Skip to content

Commit e733a49

Browse files
authored
Improve hover info & other fixes (#1151)
* fix #263
1 parent 00f0dcf commit e733a49

11 files changed

Lines changed: 518 additions & 57 deletions

File tree

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/GetDefinition.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import de.peeeq.wurstio.languageserver.WFile;
77
import de.peeeq.wurstscript.WLogger;
88
import de.peeeq.wurstscript.ast.*;
9+
import de.peeeq.wurstscript.attributes.CofigOverridePackages;
10+
import de.peeeq.wurstscript.attributes.names.NameLink;
911
import de.peeeq.wurstscript.parser.WPos;
1012
import de.peeeq.wurstscript.utils.Utils;
1113
import org.eclipse.lsp4j.Location;
@@ -45,6 +47,13 @@ private List<? extends Location> execute2(ModelManager modelManager) {
4547
}
4648
Element e = Utils.getAstElementAtPos(cu, line, column, false).get();
4749
WLogger.info("get definition at: " + e.getClass().getSimpleName());
50+
NameDef configuredDecl = getConfiguredDeclarationAtPos(e);
51+
if (configuredDecl != null) {
52+
NameDef originalDecl = getOriginalConfigDeclaration(configuredDecl);
53+
if (originalDecl != null) {
54+
return linkTo(originalDecl);
55+
}
56+
}
4857
if (e instanceof FuncRef) {
4958
FuncRef funcRef = (FuncRef) e;
5059
FunctionDefinition decl = funcRef.attrFuncDef();
@@ -85,6 +94,40 @@ private List<? extends Location> execute2(ModelManager modelManager) {
8594
return Collections.emptyList();
8695
}
8796

97+
private NameDef getConfiguredDeclarationAtPos(Element e) {
98+
if (e instanceof NameDef) {
99+
return (NameDef) e;
100+
}
101+
Element current = e;
102+
while (current != null) {
103+
if (current instanceof NameDef) {
104+
return (NameDef) current;
105+
}
106+
current = current.getParent();
107+
}
108+
return null;
109+
}
110+
111+
private NameDef getOriginalConfigDeclaration(NameDef nameDef) {
112+
if (!(nameDef instanceof GlobalVarDef) || !nameDef.hasAnnotation("@config")) {
113+
return null;
114+
}
115+
PackageOrGlobal nearestPackage = nameDef.attrNearestPackage();
116+
if (!(nearestPackage instanceof WPackage)) {
117+
return null;
118+
}
119+
WPackage configPackage = (WPackage) nearestPackage;
120+
if (!configPackage.getName().endsWith(CofigOverridePackages.CONFIG_POSTFIX)) {
121+
return null;
122+
}
123+
WPackage originalPackage = CofigOverridePackages.getOriginalPackage(configPackage);
124+
if (originalPackage == null) {
125+
return null;
126+
}
127+
NameLink originalVar = originalPackage.getElements().lookupVarNoConfig(nameDef.getName(), false);
128+
return originalVar == null ? null : originalVar.getDef();
129+
}
130+
88131
private List<? extends Location> linkTo(AstElementWithSource decl) {
89132
if (decl == null) {
90133
return Collections.emptyList();

0 commit comments

Comments
 (0)