Skip to content

Commit b50aa64

Browse files
committed
[fixes #2950] Patch language server semantic highlighting
1 parent ba2b47b commit b50aa64

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java

+6-9
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ public String mapResourceName(int classFileFormatVersion, String resourceName) {
8787
patchHideGeneratedNodes(sm);
8888
patchPostCompileHookEclipse(sm);
8989
patchFixSourceTypeConverter(sm);
90-
patchDisableLombokForCodeCleanup(sm);
9190
patchListRewriteHandleGeneratedMethods(sm);
9291
patchSyntaxAndOccurrencesHighlighting(sm);
9392
patchSortMembersOperation(sm);
@@ -206,14 +205,6 @@ private static void patchSyntaxAndOccurrencesHighlighting(ScriptManager sm) {
206205
.build());
207206
}
208207

209-
private static void patchDisableLombokForCodeCleanup(ScriptManager sm) {
210-
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.exitEarly()
211-
.target(new MethodTarget("org.eclipse.jdt.core.dom.ASTNode", "accept", "void", "org.eclipse.jdt.core.dom.ASTVisitor"))
212-
.decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isRefactoringVisitorAndGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode", "org.eclipse.jdt.core.dom.ASTVisitor"))
213-
.request(StackRequest.THIS, StackRequest.PARAM1)
214-
.build());
215-
}
216-
217208
private static void patchListRewriteHandleGeneratedMethods(ScriptManager sm) {
218209
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.replaceMethodCall()
219210
.target(new MethodTarget("org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer$ListRewriter", "rewriteList"))
@@ -308,6 +299,12 @@ private static void patchHideGeneratedNodes(ScriptManager sm) {
308299
"org.eclipse.jdt.core.dom.SimpleName[]"))
309300
.request(StackRequest.RETURN_VALUE).build());
310301

302+
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.exitEarly()
303+
.target(new MethodTarget("org.eclipse.jdt.core.dom.ASTNode", "accept", "void", "org.eclipse.jdt.core.dom.ASTVisitor"))
304+
.decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isBlockedVisitorAndGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode", "org.eclipse.jdt.core.dom.ASTVisitor"))
305+
.request(StackRequest.THIS, StackRequest.PARAM1)
306+
.build());
307+
311308
patchRefactorScripts(sm);
312309
patchFormatters(sm);
313310
}

src/eclipseAgent/lombok/launch/PatchFixesHider.java

+3-12
Original file line numberDiff line numberDiff line change
@@ -414,23 +414,14 @@ public static boolean isGenerated(org.eclipse.jdt.internal.compiler.ast.ASTNode
414414
return result;
415415
}
416416

417-
public static boolean isRefactoringVisitorAndGenerated(org.eclipse.jdt.core.dom.ASTNode node, org.eclipse.jdt.core.dom.ASTVisitor visitor) {
417+
public static boolean isBlockedVisitorAndGenerated(org.eclipse.jdt.core.dom.ASTNode node, org.eclipse.jdt.core.dom.ASTVisitor visitor) {
418418
if (visitor == null) return false;
419419

420420
String className = visitor.getClass().getName();
421-
if (!(className.startsWith("org.eclipse.jdt.internal.corext.fix") || className.startsWith("org.eclipse.jdt.internal.ui.fix"))) return false;
421+
if (!(className.startsWith("org.eclipse.jdt.internal.corext.fix") || className.startsWith("org.eclipse.jdt.internal.ui.fix") || className.startsWith("org.eclipse.jdt.ls.core.internal.semantictokens.SemanticTokensVisitor"))) return false;
422422
if (className.equals("org.eclipse.jdt.internal.corext.fix.VariableDeclarationFixCore$WrittenNamesFinder")) return false;
423423

424-
boolean result = false;
425-
try {
426-
result = ((Boolean)node.getClass().getField("$isGenerated").get(node)).booleanValue();
427-
if (!result && node.getParent() != null && node.getParent() instanceof org.eclipse.jdt.core.dom.QualifiedName) {
428-
result = isGenerated(node.getParent());
429-
}
430-
} catch (Exception e) {
431-
// better to assume it isn't generated
432-
}
433-
return result;
424+
return isGenerated(node);
434425
}
435426

436427
public static boolean isListRewriteOnGeneratedNode(org.eclipse.jdt.core.dom.rewrite.ListRewrite rewrite) {

0 commit comments

Comments
 (0)