diff --git a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/ScriptDocument.java b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/ScriptDocument.java index 7b6543266..7f1264468 100644 --- a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/ScriptDocument.java +++ b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/ScriptDocument.java @@ -1692,7 +1692,9 @@ public class ScriptDocument { * For JavaScript: Parses "var/let/const varName = expr;" with type inference */ private void parseLocalVariables() { - for (MethodInfo method : getAllMethods()) { + List allMethodsAndConstructors = getAllMethods(); + allMethodsAndConstructors.addAll(getAllConstructors()); + for (MethodInfo method : allMethodsAndConstructors) { Map> locals = new HashMap<>(); methodLocals.put(method.getDeclarationOffset(), locals); @@ -3240,6 +3242,14 @@ public class ScriptDocument { break; } } + if (!insideMethod) { + for (MethodInfo constructor : getAllConstructors()) { + if (constructor.containsPosition(position)) { + insideMethod = true; + break; + } + } + } if (insideMethod) continue; boolean insideInner = false; @@ -3323,6 +3333,11 @@ public class ScriptDocument { for (MethodInfo method : getAllMethods()) { if (method.containsPosition(cAbsNamePos)) { cInsideMethod = true; break; } } + if (!cInsideMethod) { + for (MethodInfo constructor : getAllConstructors()) { + if (constructor.containsPosition(cAbsNamePos)) { cInsideMethod = true; break; } + } + } if (cInsideMethod) return; boolean cInsideInner = false; for (InnerCallableScope sc : innerScopes) { @@ -3394,6 +3409,11 @@ public class ScriptDocument { for (MethodInfo method : getAllMethods()) { if (method.containsPosition(firstVarAbsPos)) { greedyInsideMethod = true; break; } } + if (!greedyInsideMethod) { + for (MethodInfo constructor : getAllConstructors()) { + if (constructor.containsPosition(firstVarAbsPos)) { greedyInsideMethod = true; break; } + } + } } if (greedyInsideMethod) continue; @@ -3430,6 +3450,11 @@ public class ScriptDocument { for (MethodInfo method : getAllMethods()) { if (method.containsPosition(cAbsNamePos)) { cInsideMethod = true; break; } } + if (!cInsideMethod) { + for (MethodInfo constructor : getAllConstructors()) { + if (constructor.containsPosition(cAbsNamePos)) { cInsideMethod = true; break; } + } + } } if (cInsideMethod) return; @@ -3473,6 +3498,14 @@ public class ScriptDocument { break; } } + if (!insideMethod) { + for (MethodInfo constructor : getAllConstructors()) { + if (constructor.containsPosition(position)) { + insideMethod = true; + break; + } + } + } } if (insideMethod) @@ -3538,6 +3571,11 @@ public class ScriptDocument { for (MethodInfo method : getAllMethods()) { if (method.containsPosition(cAbsNamePos)) { cInsideMethod = true; break; } } + if (!cInsideMethod) { + for (MethodInfo constructor : getAllConstructors()) { + if (constructor.containsPosition(cAbsNamePos)) { cInsideMethod = true; break; } + } + } } if (cInsideMethod) return; @@ -8948,12 +8986,22 @@ for (ScriptTypeInfo type:scriptTypes.values()) { while (searchPos < text.length() && Character.isWhitespace(text.charAt(searchPos))) searchPos++; - if (searchPos < text.length() && text.charAt(searchPos) == '(') { + // Skip generic args or diamond operator (e.g., or <>) + if (searchPos < text.length() && text.charAt(searchPos) == '<') { + int closeAngle = text.indexOf('>', searchPos); + if (closeAngle >= 0) { + searchPos = closeAngle + 1; + while (searchPos < text.length() && Character.isWhitespace(text.charAt(searchPos))) + searchPos++; + } + } + + if (searchPos < text.length() && text.charAt(searchPos) == '(') { int openParen = searchPos; - int closeParen = findMatchingParen(openParen); + int closeParen = findMatchingParen(openParen); if (closeParen >= 0) { - // For constructor declarations, verify it's followed by opening brace + // For constructor declarations, verify it's followed by opening brace if (isConstructorDecl && !isNewCreation) { int braceSearch = closeParen + 1; while (braceSearch < text.length() && Character.isWhitespace(text.charAt(braceSearch))) @@ -9301,6 +9349,11 @@ for (ScriptTypeInfo type:scriptTypes.values()) { return method; } } + for (MethodInfo constructor : getAllConstructors()) { + if (constructor.containsPosition(position)) { + return constructor; + } + } return null; }