mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 22:16:11 +00:00
Merge pull request #2978 from Rawi01/language-server
Add syntax highlighting and javadoc to language server (VSCode)
This commit is contained in:
4 files changed
+44
-24
No files matched your search
@@ -95,6 +95,7 @@ import org.eclipse.jdt.internal.compiler.ast.TypeParameter;
|
||||
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
|
||||
import org.eclipse.jdt.internal.compiler.ast.Wildcard;
|
||||
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
|
||||
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
|
||||
import org.eclipse.jdt.internal.compiler.lookup.Binding;
|
||||
import org.eclipse.jdt.internal.compiler.lookup.CaptureBinding;
|
||||
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding;
|
||||
@@ -337,6 +338,8 @@ public class EclipseHandlerUtil {
|
||||
public static final Class<?> INTERSECTION_BINDING1, INTERSECTION_BINDING2;
|
||||
public static final Field INTERSECTION_BINDING_TYPES1, INTERSECTION_BINDING_TYPES2;
|
||||
public static final Field TYPE_DECLARATION_RECORD_COMPONENTS;
|
||||
public static final Class<?> COMPILATION_UNIT;
|
||||
public static final Method COMPILATION_UNIT_ORIGINAL_FROM_CLONE;
|
||||
static {
|
||||
STRING_LITERAL__LINE_NUMBER = getField(StringLiteral.class, "lineNumber");
|
||||
ANNOTATION__MEMBER_VALUE_PAIR_NAME = getField(Annotation.class, "memberValuePairName");
|
||||
@@ -346,6 +349,8 @@ public class EclipseHandlerUtil {
|
||||
INTERSECTION_BINDING_TYPES1 = INTERSECTION_BINDING1 == null ? null : getField(INTERSECTION_BINDING1, "intersectingTypes");
|
||||
INTERSECTION_BINDING_TYPES2 = INTERSECTION_BINDING2 == null ? null : getField(INTERSECTION_BINDING2, "intersectingTypes");
|
||||
TYPE_DECLARATION_RECORD_COMPONENTS = getField(TypeDeclaration.class, "recordComponents");
|
||||
COMPILATION_UNIT = getClass("org.eclipse.jdt.internal.core.CompilationUnit");
|
||||
COMPILATION_UNIT_ORIGINAL_FROM_CLONE = COMPILATION_UNIT == null ? null : Permit.permissiveGetMethod(COMPILATION_UNIT, "originalFromClone");
|
||||
}
|
||||
|
||||
public static int reflectInt(Field f, Object o) {
|
||||
@@ -2731,7 +2736,14 @@ public class EclipseHandlerUtil {
|
||||
public static void setDocComment(CompilationUnitDeclaration cud, TypeDeclaration type, ASTNode node, String doc) {
|
||||
if (doc == null) return;
|
||||
|
||||
Map<String, String> docs = EcjAugments.CompilationUnit_javadoc.setIfAbsent(cud.compilationResult.compilationUnit, new HashMap<String, String>());
|
||||
ICompilationUnit compilationUnit = cud.compilationResult.compilationUnit;
|
||||
if (compilationUnit.getClass().equals(COMPILATION_UNIT)) {
|
||||
try {
|
||||
compilationUnit = (ICompilationUnit) Permit.invoke(COMPILATION_UNIT_ORIGINAL_FROM_CLONE, compilationUnit);
|
||||
} catch (Throwable t) { }
|
||||
}
|
||||
|
||||
Map<String, String> docs = EcjAugments.CompilationUnit_javadoc.setIfAbsent(compilationUnit, new HashMap<String, String>());
|
||||
if (node instanceof AbstractMethodDeclaration) {
|
||||
AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) node;
|
||||
String signature = getSignature(type, methodDeclaration);
|
||||
|
||||
@@ -87,7 +87,6 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
|
||||
patchHideGeneratedNodes(sm);
|
||||
patchPostCompileHookEclipse(sm);
|
||||
patchFixSourceTypeConverter(sm);
|
||||
patchDisableLombokForCodeCleanup(sm);
|
||||
patchListRewriteHandleGeneratedMethods(sm);
|
||||
patchSyntaxAndOccurrencesHighlighting(sm);
|
||||
patchSortMembersOperation(sm);
|
||||
@@ -206,14 +205,6 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
|
||||
.build());
|
||||
}
|
||||
|
||||
private static void patchDisableLombokForCodeCleanup(ScriptManager sm) {
|
||||
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.exitEarly()
|
||||
.target(new MethodTarget("org.eclipse.jdt.core.dom.ASTNode", "accept", "void", "org.eclipse.jdt.core.dom.ASTVisitor"))
|
||||
.decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isRefactoringVisitorAndGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode", "org.eclipse.jdt.core.dom.ASTVisitor"))
|
||||
.request(StackRequest.THIS, StackRequest.PARAM1)
|
||||
.build());
|
||||
}
|
||||
|
||||
private static void patchListRewriteHandleGeneratedMethods(ScriptManager sm) {
|
||||
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.replaceMethodCall()
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer$ListRewriter", "rewriteList"))
|
||||
@@ -308,6 +299,12 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
|
||||
"org.eclipse.jdt.core.dom.SimpleName[]"))
|
||||
.request(StackRequest.RETURN_VALUE).build());
|
||||
|
||||
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.exitEarly()
|
||||
.target(new MethodTarget("org.eclipse.jdt.core.dom.ASTNode", "accept", "void", "org.eclipse.jdt.core.dom.ASTVisitor"))
|
||||
.decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isBlockedVisitorAndGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode", "org.eclipse.jdt.core.dom.ASTVisitor"))
|
||||
.request(StackRequest.THIS, StackRequest.PARAM1)
|
||||
.build());
|
||||
|
||||
patchRefactorScripts(sm);
|
||||
patchFormatters(sm);
|
||||
}
|
||||
@@ -895,6 +892,14 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
|
||||
.requestExtra(StackRequest.PARAM1)
|
||||
.build());
|
||||
|
||||
/* This is a copy for the language server implementation that also supports markdown */
|
||||
sm.addScript(ScriptBuilder.wrapMethodCall()
|
||||
.target(new MethodTarget("org.eclipse.jdt.ls.core.internal.javadoc.JavadocContentAccess2", "getHTMLContent", "java.lang.String", "org.eclipse.jdt.core.IJavaElement", "boolean"))
|
||||
.methodToWrap(new Hook("org.eclipse.jdt.ls.core.internal.javadoc.JavadocContentAccess2", "getHTMLContentFromSource", "java.lang.String", "org.eclipse.jdt.core.IJavaElement"))
|
||||
.wrapMethod(new Hook("lombok.launch.PatchFixesHider$Javadoc", "getHTMLContentFromSource", "java.lang.String", "java.lang.String", "org.eclipse.jdt.core.IJavaElement"))
|
||||
.requestExtra(StackRequest.PARAM1)
|
||||
.build());
|
||||
|
||||
/* This is an older version that uses IMember instead of IJavaElement */
|
||||
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.wrapMethodCall()
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.ui.text.javadoc.JavadocContentAccess2", "getHTMLContent", "java.lang.String", "org.eclipse.jdt.core.IMember", "boolean"))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Project Lombok Authors.
|
||||
* Copyright (C) 2020-2021 The Project Lombok Authors.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -103,8 +103,9 @@ public class PatchJavadoc {
|
||||
private static class Reflection {
|
||||
private static final Method javadoc2HTML;
|
||||
private static final Method oldJavadoc2HTML;
|
||||
private static final Method lsJavadoc2HTML;
|
||||
static {
|
||||
Method a = null, b = null;
|
||||
Method a = null, b = null, c = null;
|
||||
|
||||
try {
|
||||
a = Permit.getMethod(JavadocContentAccess2.class, "javadoc2HTML", IMember.class, IJavaElement.class, String.class);
|
||||
@@ -112,9 +113,13 @@ public class PatchJavadoc {
|
||||
try {
|
||||
b = Permit.getMethod(JavadocContentAccess2.class, "javadoc2HTML", IMember.class, String.class);
|
||||
} catch (Throwable t) {}
|
||||
try {
|
||||
c = Permit.getMethod(Class.forName("org.eclipse.jdt.ls.core.internal.javadoc.JavadocContentAccess2"), "javadoc2HTML", IMember.class, IJavaElement.class, String.class);
|
||||
} catch (Throwable t) {}
|
||||
|
||||
javadoc2HTML = a;
|
||||
oldJavadoc2HTML = b;
|
||||
lsJavadoc2HTML = c;
|
||||
}
|
||||
|
||||
private static String javadoc2HTML(IMember member, IJavaElement element, String rawJavadoc) {
|
||||
@@ -125,6 +130,13 @@ public class PatchJavadoc {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (lsJavadoc2HTML != null) {
|
||||
try {
|
||||
return (String) lsJavadoc2HTML.invoke(null, member, element, rawJavadoc);
|
||||
} catch (Throwable t) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (oldJavadoc2HTML != null) {
|
||||
try {
|
||||
return (String) oldJavadoc2HTML.invoke(null, member, rawJavadoc);
|
||||
|
||||
@@ -414,23 +414,14 @@ final class PatchFixesHider {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isRefactoringVisitorAndGenerated(org.eclipse.jdt.core.dom.ASTNode node, org.eclipse.jdt.core.dom.ASTVisitor visitor) {
|
||||
public static boolean isBlockedVisitorAndGenerated(org.eclipse.jdt.core.dom.ASTNode node, org.eclipse.jdt.core.dom.ASTVisitor visitor) {
|
||||
if (visitor == null) return false;
|
||||
|
||||
String className = visitor.getClass().getName();
|
||||
if (!(className.startsWith("org.eclipse.jdt.internal.corext.fix") || className.startsWith("org.eclipse.jdt.internal.ui.fix"))) return false;
|
||||
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;
|
||||
if (className.equals("org.eclipse.jdt.internal.corext.fix.VariableDeclarationFixCore$WrittenNamesFinder")) return false;
|
||||
|
||||
boolean result = false;
|
||||
try {
|
||||
result = ((Boolean)node.getClass().getField("$isGenerated").get(node)).booleanValue();
|
||||
if (!result && node.getParent() != null && node.getParent() instanceof org.eclipse.jdt.core.dom.QualifiedName) {
|
||||
result = isGenerated(node.getParent());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// better to assume it isn't generated
|
||||
}
|
||||
return result;
|
||||
return isGenerated(node);
|
||||
}
|
||||
|
||||
public static boolean isListRewriteOnGeneratedNode(org.eclipse.jdt.core.dom.rewrite.ListRewrite rewrite) {
|
||||
|
||||
Reference in new issue
Block a user