11package noppes .npcs .client .gui .util .script .interpreter ;
22
3- import net .minecraft .client .Minecraft ;
43import noppes .npcs .client .ClientProxy ;
54
65import java .util .*;
@@ -74,6 +73,9 @@ public class ScriptDocument {
7473 // Local variables per method (methodStartOffset -> {varName -> FieldInfo})
7574 private final Map <Integer , Map <String , FieldInfo >> methodLocals = new HashMap <>();
7675
76+ // Method calls - stores all parsed method call information
77+ private final List <MethodCallInfo > methodCalls = new ArrayList <>();
78+
7779 // Excluded regions (strings/comments) - positions where other patterns shouldn't match
7880 private final List <int []> excludedRanges = new ArrayList <>();
7981
@@ -180,6 +182,7 @@ public void formatCodeText() {
180182 excludedRanges .clear ();
181183 methodLocals .clear ();
182184 scriptTypes .clear ();
185+ methodCalls .clear ();
183186
184187 // Phase 1: Find excluded regions (strings/comments)
185188 findExcludedRanges ();
@@ -858,13 +861,14 @@ private List<ScriptLine.Mark> buildMarks() {
858861 // Numbers
859862 addPatternMarks (marks , NUMBER_PATTERN , TokenType .NUMBER );
860863
864+ // Method calls (parse before variables so we can attach context)
865+ markMethodCalls (marks );
866+
861867 // Variables and fields
862868 markVariables (marks );
863869
864870 // Chained field accesses (e.g., mc.player.world, this.field)
865871 markChainedFieldAccesses (marks );
866-
867- markMethodCalls (marks );
868872
869873 // Imported class usages
870874 markImportedClassUsages (marks );
@@ -1321,6 +1325,9 @@ private void markMethodCalls(List<ScriptLine.Mark> marks) {
13211325 arguments , receiverType , resolvedMethod , isStaticAccess
13221326 );
13231327 callInfo .validate ();
1328+
1329+ // Store in collection for later lookup
1330+ methodCalls .add (callInfo );
13241331
13251332 // Always mark method call as green (METHOD_CALL), with error info attached for underline
13261333 // The MethodCallInfo is attached so rendering can draw curly underline if there's an error
@@ -1349,6 +1356,9 @@ private void markMethodCalls(List<ScriptLine.Mark> marks) {
13491356 arguments , null , resolvedMethod
13501357 );
13511358 callInfo .validate ();
1359+
1360+ // Store in collection for later lookup
1361+ methodCalls .add (callInfo );
13521362
13531363 // Always mark method call as green (METHOD_CALL), with error info attached for underline
13541364 marks .add (new ScriptLine .Mark (nameStart , nameEnd , TokenType .METHOD_CALL , callInfo ));
@@ -1422,6 +1432,25 @@ private boolean isStaticAccessCall(int methodNameStart) {
14221432 return !ident .isEmpty () && Character .isUpperCase (ident .charAt (0 ));
14231433 }
14241434
1435+ /**
1436+ * Find the MethodCallInfo that contains the given position as an argument.
1437+ * Returns null if the position is not inside any method call's argument list.
1438+ */
1439+ private MethodCallInfo findMethodCallContainingPosition (int position ) {
1440+ for (MethodCallInfo call : methodCalls ) {
1441+ // Check if position is within the argument list (between open and close parens)
1442+ if (position >= call .getOpenParenOffset () && position <= call .getCloseParenOffset ()) {
1443+ // Check if it's within any of the arguments
1444+ for (MethodCallInfo .Argument arg : call .getArguments ()) {
1445+ if (position >= arg .getStartOffset () && position <= arg .getEndOffset ()) {
1446+ return call ;
1447+ }
1448+ }
1449+ }
1450+ }
1451+ return null ;
1452+ }
1453+
14251454 /**
14261455 * Find the matching closing parenthesis for an opening parenthesis.
14271456 * Handles nested parentheses, strings, and comments.
@@ -1951,6 +1980,8 @@ private void markVariables(List<ScriptLine.Mark> marks) {
19511980
19521981 // Find containing method
19531982 MethodInfo containingMethod = findMethodAtPosition (position );
1983+ // Check if this variable is an argument to a method call
1984+ MethodCallInfo callInfo = findMethodCallContainingPosition (position );
19541985
19551986 // For uppercase identifiers, only process if it's a known field
19561987 // Otherwise, let type handling (markImportedClassUsages) handle it
@@ -1970,39 +2001,26 @@ private void markVariables(List<ScriptLine.Mark> marks) {
19702001 FieldInfo localInfo = locals .get (name );
19712002 // Only highlight if the position is after the declaration
19722003 if (localInfo .isVisibleAt (position )) {
1973- marks .add (new ScriptLine .Mark (m .start (1 ), m .end (1 ), TokenType .LOCAL_FIELD , localInfo ));
2004+ Object metadata = callInfo != null ? new FieldInfo .ArgInfo (localInfo , callInfo ) : localInfo ;
2005+ marks .add (new ScriptLine .Mark (m .start (1 ), m .end (1 ), TokenType .LOCAL_FIELD , metadata ));
19742006 continue ;
19752007 }
19762008 }
1977-
1978- // Check global fields
1979- if (globalFields .containsKey (name )) {
1980- FieldInfo fieldInfo = globalFields .get (name );
1981- marks .add (new ScriptLine .Mark (m .start (1 ), m .end (1 ), TokenType .GLOBAL_FIELD , fieldInfo ));
1982- continue ;
1983- }
1984-
1985- // Skip uppercase if not a known field - type handling will deal with it
1986- if (isUppercase )
1987- continue ;
1988-
1989- // Unknown variable inside method - mark as undefined
1990- marks .add (new ScriptLine .Mark (m .start (1 ), m .end (1 ), TokenType .UNDEFINED_VAR ));
19912009 } else {
1992- // Outside any method
19932010 // Check global fields
19942011 if (globalFields .containsKey (name )) {
19952012 FieldInfo fieldInfo = globalFields .get (name );
1996- marks .add (new ScriptLine .Mark (m .start (1 ), m .end (1 ), TokenType .GLOBAL_FIELD , fieldInfo ));
2013+ Object metadata = callInfo != null ? new FieldInfo .ArgInfo (fieldInfo , callInfo ) : fieldInfo ;
2014+ marks .add (new ScriptLine .Mark (m .start (1 ), m .end (1 ), TokenType .GLOBAL_FIELD , metadata ));
19972015 continue ;
19982016 }
19992017
20002018 // Skip uppercase if not a known field - type handling will deal with it
20012019 if (isUppercase )
20022020 continue ;
20032021
2004- // Unknown variable outside method - mark as undefined
2005- marks .add (new ScriptLine .Mark (m .start (1 ), m .end (1 ), TokenType .UNDEFINED_VAR ));
2022+ // Unknown variable inside method - mark as undefined
2023+ marks .add (new ScriptLine .Mark (m .start (1 ), m .end (1 ), TokenType .UNDEFINED_VAR , callInfo ));
20062024 }
20072025 }
20082026 }
0 commit comments