Skip to content

Commit b0a407d

Browse files
angelozerrdatho7561
authored andcommitted
Show Converter, defaultValue, types as inlay hint
Fixes #529 Signed-off-by: azerr <[email protected]>
1 parent b128c65 commit b0a407d

File tree

69 files changed

+3023
-533
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+3023
-533
lines changed

microprofile.jdt/org.eclipse.lsp4mp.jdt.core/plugin.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ propertiesProviders.name=MicroProfile properties providers extension
1717
javaFeatureParticipants.name=Java features participants for MicroProfile
1818
projectLabelProviders.name=Project label providers extension
1919
javaASTValidators.name=Java AST validators
20+
javaASTInlayHints.name=Java AST inlay hints
2021
staticPropertyProviders.name=MicroProfile static properties providers extension

microprofile.jdt/org.eclipse.lsp4mp.jdt.core/plugin.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
<extension-point id="javaASTValidators"
1818
name="%javaASTValidators.name"
1919
schema="schema/javaASTValidators.exsd"/>
20+
<extension-point id="javaASTInlayHints"
21+
name="%javaASTInlayHints.name"
22+
schema="schema/javaASTInlayHints.exsd"/>
2023
<extension-point id="staticPropertyProviders"
2124
name="%staticPropertyProviders.name"
2225
schema="schema/staticPropertyProviders.exsd"/>
@@ -37,6 +40,7 @@
3740
<command id="microprofile/java/codeAction"/>
3841
<command id="microprofile/java/codeActionResolve"/>
3942
<command id="microprofile/java/codeLens"/>
43+
<command id="microprofile/java/inlayHint"/>
4044
<command id="microprofile/java/completion"/>
4145
<command id="microprofile/java/definition"/>
4246
<command id="microprofile/java/diagnostics"/>
@@ -67,6 +71,8 @@
6771
<extension point="org.eclipse.lsp4mp.jdt.core.javaFeatureParticipants" >
6872
<!-- Diagnostics managed with Java AST vistor -->
6973
<diagnostics class="org.eclipse.lsp4mp.jdt.internal.core.java.validators.JavaASTDiagnosticsParticipant" />
74+
<!-- Inlay hints managed with Java AST vistor -->
75+
<inlayHint class="org.eclipse.lsp4mp.jdt.internal.core.java.inlayhint.JavaASTInlayHintsParticipant" />
7076
</extension>
7177

7278
<!-- Java Util Logging Config support -->
@@ -108,6 +114,11 @@
108114
<validator class="org.eclipse.lsp4mp.jdt.internal.config.java.MicroProfileConfigASTValidator" />
109115
</extension>
110116

117+
<extension point="org.eclipse.lsp4mp.jdt.core.javaASTInlayHints">
118+
<!-- Show converters, default values as inlay hint for @ConfigProperty annotation -->
119+
<inlayHint class="org.eclipse.lsp4mp.jdt.internal.config.java.MicroProfileConfigASTInlayHint" />
120+
</extension>
121+
111122
<!-- Microprofile Config Static Property support -->
112123

113124
<extension point="org.eclipse.lsp4mp.jdt.core.staticPropertyProviders">
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<!-- Schema file written by PDE -->
3+
<schema targetNamespace="org.eclipse.lsp4mp.jdt.core" xmlns="http://www.w3.org/2001/XMLSchema">
4+
<annotation>
5+
<appinfo>
6+
<meta.schema plugin="org.eclipse.lsp4mp.jdt.core" id="javaASTInlayHints" name="Java AST InlayHints"/>
7+
</appinfo>
8+
<documentation>
9+
This extension point allows adding a inlayHint to report LSP inlay hint which will be processed when AST is visited.
10+
</documentation>
11+
</annotation>
12+
13+
<element name="extension">
14+
<annotation>
15+
<appinfo>
16+
<meta.element />
17+
</appinfo>
18+
</annotation>
19+
<complexType>
20+
<sequence minOccurs="1" maxOccurs="unbounded">
21+
<element ref="inlayHint" minOccurs="0" maxOccurs="unbounded"/>
22+
</sequence>
23+
<attribute name="point" type="string" use="required">
24+
<annotation>
25+
<documentation>
26+
27+
</documentation>
28+
</annotation>
29+
</attribute>
30+
<attribute name="id" type="string">
31+
<annotation>
32+
<documentation>
33+
34+
</documentation>
35+
</annotation>
36+
</attribute>
37+
<attribute name="name" type="string">
38+
<annotation>
39+
<documentation>
40+
41+
</documentation>
42+
<appinfo>
43+
<meta.attribute translatable="true"/>
44+
</appinfo>
45+
</annotation>
46+
</attribute>
47+
</complexType>
48+
</element>
49+
50+
<element name="inlayHint">
51+
<annotation>
52+
<documentation>
53+
The Java AST inlayHint managed by a custom class.
54+
</documentation>
55+
</annotation>
56+
<complexType>
57+
<attribute name="class" type="string" use="required">
58+
<annotation>
59+
<documentation>
60+
The Java class for AST InlayHint.
61+
</documentation>
62+
<appinfo>
63+
<meta.attribute kind="java" basedOn="org.eclipse.lsp4mp.jdt.core.java.inlayHints.JavaASTInlayHint:"/>
64+
</appinfo>
65+
</annotation>
66+
</attribute>
67+
</complexType>
68+
</element>
69+
70+
<annotation>
71+
<appinfo>
72+
<meta.section type="since"/>
73+
</appinfo>
74+
<documentation>
75+
0.4.0
76+
</documentation>
77+
</annotation>
78+
79+
<annotation>
80+
<appinfo>
81+
<meta.section type="examples"/>
82+
</appinfo>
83+
<documentation>
84+
The following is an example of inlayHint with a custom class:
85+
86+
&lt;pre&gt;
87+
&lt;extension point=&quot;org.eclipse.lsp4mp.jdt.core.javaASTInlayHints&quot;&gt;
88+
&lt;!-- Show converters, default values as inlay hint for @ConfigProperty annotation --&gt;
89+
&lt;inlayHint class=&quot;org.eclipse.lsp4mp.jdt.internal.config.java.MicroProfileConfigASTInlayHint&quot; /&gt;
90+
&lt;/extension&gt;
91+
&lt;/pre&gt;
92+
</documentation>
93+
</annotation>
94+
95+
96+
97+
98+
</schema>

microprofile.jdt/org.eclipse.lsp4mp.jdt.core/schema/javaFeatureParticipants.exsd

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,27 @@
119119
</attribute>
120120
</complexType>
121121
</element>
122-
122+
123+
<element name="inlayHint">
124+
<annotation>
125+
<documentation>
126+
Java inlay hint participant.
127+
</documentation>
128+
</annotation>
129+
<complexType>
130+
<attribute name="class" type="string" use="required">
131+
<annotation>
132+
<documentation>
133+
Name of a class that implements IJavaInlayHintParticipant.
134+
</documentation>
135+
<appinfo>
136+
<meta.attribute kind="java" basedOn=":org.eclipse.lsp4mp.jdt.core.java.inlayHint.IJavaInlayHintParticipant"/>
137+
</appinfo>
138+
</annotation>
139+
</attribute>
140+
</complexType>
141+
</element>
142+
123143
<element name="completion">
124144
<annotation>
125145
<documentation>
@@ -280,4 +300,7 @@
280300
</documentation>
281301
</annotation>
282302

303+
304+
305+
283306
</schema>
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Red Hat Inc. and others.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
8+
*
9+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10+
*
11+
* Contributors:
12+
* Red Hat Inc. - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.lsp4mp.commons;
15+
16+
import java.util.Objects;
17+
18+
/**
19+
* MicroProfile inlay hints settings.
20+
*
21+
* @author Angelo ZERR
22+
*
23+
*/
24+
public class MicroProfileInlayHintSettings {
25+
26+
private static final MicroProfileInlayHintTypeSettings DEFAULT_CONVERTERS;
27+
private static final MicroProfileInlayHintTypeSettings DEFAULT_DEFAULT_VALUES;
28+
private static final MicroProfileInlayHintTypeSettings DEFAULT_RESOLVE_EXPRESSIONS;
29+
private static final MicroProfileInlayHintTypeSettings DEFAULT_TYPES;
30+
31+
static {
32+
DEFAULT_CONVERTERS = new MicroProfileInlayHintTypeSettings();
33+
DEFAULT_CONVERTERS.setEnabled(false);
34+
DEFAULT_DEFAULT_VALUES = new MicroProfileInlayHintTypeSettings();
35+
DEFAULT_DEFAULT_VALUES.setEnabled(true);
36+
DEFAULT_RESOLVE_EXPRESSIONS = new MicroProfileInlayHintTypeSettings();
37+
DEFAULT_RESOLVE_EXPRESSIONS.setEnabled(true);
38+
DEFAULT_TYPES = new MicroProfileInlayHintTypeSettings();
39+
DEFAULT_TYPES.setEnabled(false);
40+
}
41+
42+
private boolean enabled;
43+
private MicroProfileInlayHintTypeSettings converters;
44+
private MicroProfileInlayHintTypeSettings defaultValues;
45+
private MicroProfileInlayHintTypeSettings resolveExpressions;
46+
private MicroProfileInlayHintTypeSettings types;
47+
private transient boolean updated;
48+
49+
public MicroProfileInlayHintSettings() {
50+
setEnabled(true);
51+
}
52+
53+
public boolean isEnabled() {
54+
return enabled;
55+
}
56+
57+
public void setEnabled(boolean enabled) {
58+
this.enabled = enabled;
59+
}
60+
61+
public MicroProfileInlayHintTypeSettings getConverters() {
62+
updateDefault();
63+
return converters;
64+
}
65+
66+
public void setConverters(MicroProfileInlayHintTypeSettings converters) {
67+
this.converters = converters;
68+
this.updated = false;
69+
}
70+
71+
public MicroProfileInlayHintTypeSettings getDefaultValues() {
72+
updateDefault();
73+
return defaultValues;
74+
}
75+
76+
public void setDefaultValues(MicroProfileInlayHintTypeSettings defaultValues) {
77+
this.defaultValues = defaultValues;
78+
this.updated = false;
79+
}
80+
81+
public MicroProfileInlayHintTypeSettings getResolveExpressions() {
82+
updateDefault();
83+
return resolveExpressions;
84+
}
85+
86+
public void setResolveExpressions(MicroProfileInlayHintTypeSettings resolveExpressions) {
87+
this.resolveExpressions = resolveExpressions;
88+
this.updated = false;
89+
}
90+
91+
public MicroProfileInlayHintTypeSettings getTypes() {
92+
updateDefault();
93+
return types;
94+
}
95+
96+
public void setTypes(MicroProfileInlayHintTypeSettings types) {
97+
this.types = types;
98+
this.updated = false;
99+
}
100+
101+
/**
102+
* Update each kind of validation settings with default value if not defined.
103+
*/
104+
private void updateDefault() {
105+
if (updated) {
106+
return;
107+
}
108+
setConverters(converters != null ? converters : DEFAULT_CONVERTERS);
109+
setDefaultValues(defaultValues != null ? defaultValues : DEFAULT_DEFAULT_VALUES);
110+
setResolveExpressions(resolveExpressions != null ? resolveExpressions : DEFAULT_RESOLVE_EXPRESSIONS);
111+
setTypes(types != null ? types : DEFAULT_TYPES);
112+
updated = true;
113+
}
114+
115+
/**
116+
* Update the the inlay hint settings with the given new inlay hint settings.
117+
*
118+
* @param newInlayHint the new inlay hint settings.
119+
*/
120+
public boolean update(MicroProfileInlayHintSettings newInlayHint) {
121+
if (newInlayHint == null || Objects.equals(this, newInlayHint)) {
122+
return false;
123+
}
124+
this.setEnabled(newInlayHint.isEnabled());
125+
this.setConverters(newInlayHint.getConverters());
126+
this.setDefaultValues(newInlayHint.getDefaultValues());
127+
this.setResolveExpressions(newInlayHint.getResolveExpressions());
128+
this.setTypes(newInlayHint.getTypes());
129+
return true;
130+
}
131+
132+
@Override
133+
public int hashCode() {
134+
return java.util.Objects.hash(converters, defaultValues, enabled, resolveExpressions, types);
135+
}
136+
137+
@Override
138+
public boolean equals(Object obj) {
139+
if (this == obj)
140+
return true;
141+
if (obj == null)
142+
return false;
143+
if (getClass() != obj.getClass())
144+
return false;
145+
MicroProfileInlayHintSettings other = (MicroProfileInlayHintSettings) obj;
146+
return java.util.Objects.equals(converters, other.converters)
147+
&& java.util.Objects.equals(defaultValues, other.defaultValues) && enabled == other.enabled
148+
&& java.util.Objects.equals(resolveExpressions, other.resolveExpressions)
149+
&& java.util.Objects.equals(types, other.types);
150+
}
151+
152+
}

0 commit comments

Comments
 (0)