Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private void collectChildren(ITypeRoot unit, IJavaElement[] elements, ArrayList<
if (type != IJavaElement.TYPE && type != IJavaElement.FIELD && type != IJavaElement.METHOD) {
continue;
}
if (element instanceof SourceMethod method && JDTUtils.isGenerated(method)) {
if (element instanceof SourceMethod method && JDTUtils.isGenerated(method) && !preferenceManager.getPreferences().isShowGeneratedCodeSymbols()) {
continue;
}
Location location = JDTUtils.toLocation(element);
Expand Down Expand Up @@ -229,7 +229,7 @@ private DocumentSymbol toDocumentSymbol(IJavaElement unit, ITypeRoot root, IProg
if (type != TYPE && type != FIELD && type != METHOD && type != PACKAGE_DECLARATION && type != COMPILATION_UNIT && type != PACKAGE_FRAGMENT) {
return null;
}
if (unit instanceof SourceMethod method && JDTUtils.isGenerated(method)) {
if (unit instanceof SourceMethod method && JDTUtils.isGenerated(method) && !preferenceManager.getPreferences().isShowGeneratedCodeSymbols()) {
return null;
}
if (monitor.isCanceled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ public class Preferences {
*/
public static final String JAVA_SYMBOLS_INCLUDE_SOURCE_METHOD_DECLARATIONS = "java.symbols.includeSourceMethodDeclarations";

/**
* Include generated code (e.g. Lombok getters, setters, constructors) in document symbols.
*/
public static final String JAVA_SYMBOLS_INCLUDE_GENERATED_CODE = "java.symbols.includeGeneratedCode";

/**
* Insert spaces when pressing Tab
*/
Expand Down Expand Up @@ -676,6 +681,7 @@ public class Preferences {
private boolean smartSemicolonDetection;
private boolean includeDecompiledSources;
private boolean includeSourceMethodDeclarations;
private boolean showGeneratedCodeSymbols;

private String mavenUserSettings;
private String mavenGlobalSettings;
Expand Down Expand Up @@ -973,6 +979,7 @@ public Preferences() {
smartSemicolonDetection = false;
includeDecompiledSources = true;
includeSourceMethodDeclarations = false;
showGeneratedCodeSymbols = false;
insertSpaces = true;
tabSize = DEFAULT_TAB_SIZE;
mavenNotCoveredPluginExecutionSeverity = IGNORE;
Expand Down Expand Up @@ -1141,6 +1148,7 @@ public Preferences clone() {
prefs.smartSemicolonDetection = this.smartSemicolonDetection;
prefs.includeDecompiledSources = this.includeDecompiledSources;
prefs.includeSourceMethodDeclarations = this.includeSourceMethodDeclarations;
prefs.showGeneratedCodeSymbols = this.showGeneratedCodeSymbols;
prefs.inlayHintsParameterMode = this.inlayHintsParameterMode;
prefs.inlayHintsSuppressedWhenSameNameNumberedParameter = this.inlayHintsSuppressedWhenSameNameNumberedParameter;
prefs.inlayHintsVariableTypesEnabled = this.inlayHintsVariableTypesEnabled;
Expand Down Expand Up @@ -1730,6 +1738,11 @@ public static Preferences updateFrom(Preferences existing, Map<String, Object> c
prefs.setIncludeSourceMethodDeclarations(includeSourceMethodDeclarations);
}

if (containsKey(configuration, JAVA_SYMBOLS_INCLUDE_GENERATED_CODE)) {
boolean showGeneratedCodeSymbols = getBoolean(configuration, JAVA_SYMBOLS_INCLUDE_GENERATED_CODE, existing.showGeneratedCodeSymbols);
prefs.setShowGeneratedCodeSymbols(showGeneratedCodeSymbols);
}

if (containsKey(configuration, JAVA_INLAYHINTS_PARAMETERNAMES_ENABLED)) {
String inlayHintsParameterMode = getString(configuration, JAVA_INLAYHINTS_PARAMETERNAMES_ENABLED, null);
prefs.setInlayHintsParameterMode(InlayHintsParameterMode.fromString(inlayHintsParameterMode, existing.inlayHintsParameterMode));
Expand Down Expand Up @@ -2809,6 +2822,14 @@ public void setIncludeSourceMethodDeclarations(boolean includeSourceMethodDeclar
this.includeSourceMethodDeclarations = includeSourceMethodDeclarations;
}

public boolean isShowGeneratedCodeSymbols() {
return this.showGeneratedCodeSymbols;
}

public void setShowGeneratedCodeSymbols(boolean showGeneratedCodeSymbols) {
this.showGeneratedCodeSymbols = showGeneratedCodeSymbols;
}

public Preferences setInsertSpaces(boolean insertSpaces) {
this.insertSpaces = insertSpaces;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,27 @@ public void testLombok() throws Exception {
assertFalse(method.isPresent());
}

@Test
public void testLombok_showGeneratedCodeSymbols() throws Exception {
boolean lombokDisabled = "true".equals(System.getProperty("jdt.ls.lombok.disabled"));
if (lombokDisabled) {
return;
}
preferences.setShowGeneratedCodeSymbols(true);
try {
importProjects("maven/mavenlombok");
project = ResourcesPlugin.getWorkspace().getRoot().getProject("mavenlombok");
String className = "org.sample.Test";
List<? extends SymbolInformation> symbols = getSymbols(className);
assertFalse(symbols.isEmpty(), "No symbols found for " + className);
assertHasSymbol("Test", "Test.java", SymbolKind.Class, symbols);
Optional<? extends SymbolInformation> method = symbols.stream().filter(s -> (s.getKind() == SymbolKind.Method)).findAny();
assertTrue(method.isPresent(), "Generated methods should appear when java.symbols.includeGeneratedCode is true");
} finally {
preferences.setShowGeneratedCodeSymbols(false);
}
}

@Test
public void testDecompiledSource() throws Exception {
importProjects("eclipse/reference");
Expand Down