mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-13 05:27:37 +00:00
Tightened excluded range checks in receiver chain resolution (fixes stupid . in comments fkin up next line bug)
This commit is contained in:
1 parent
ce8c9b3b94
commit
c0a022c5b5
3 files changed
+58
-16
No files matched your search
+32
-4
@@ -389,6 +389,17 @@ public class AutocompleteManager {
|
||||
|
||||
// Walk left across a dotted receiver chain
|
||||
while (pos >= 0) {
|
||||
// Skip excluded regions (comments/strings) to avoid reading dots from inside them
|
||||
if (document != null && document.isExcluded(pos)) {
|
||||
int jumped = jumpBeforeExcluded(pos);
|
||||
if (jumped == pos) {
|
||||
pos--;
|
||||
} else {
|
||||
pos = jumped;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
char c = text.charAt(pos);
|
||||
|
||||
if (Character.isWhitespace(c)) {
|
||||
@@ -414,10 +425,24 @@ public class AutocompleteManager {
|
||||
// Consume identifier
|
||||
while (pos >= 0 && Character.isJavaIdentifierPart(text.charAt(pos))) pos--;
|
||||
|
||||
// If preceded by a dot, keep going
|
||||
// If preceded by a dot, keep going (skip excluded ranges when looking for the dot)
|
||||
int checkPos = pos;
|
||||
while (checkPos >= 0 && Character.isWhitespace(text.charAt(checkPos))) {
|
||||
checkPos--;
|
||||
while (checkPos >= 0) {
|
||||
char ch = text.charAt(checkPos);
|
||||
if (Character.isWhitespace(ch)) {
|
||||
checkPos--;
|
||||
continue;
|
||||
}
|
||||
if (document != null && document.isExcluded(checkPos)) {
|
||||
int jumped = jumpBeforeExcluded(checkPos);
|
||||
if (jumped == checkPos) {
|
||||
checkPos--;
|
||||
} else {
|
||||
checkPos = jumped;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (checkPos >= 0 && text.charAt(checkPos) == '.') {
|
||||
pos = checkPos - 1;
|
||||
@@ -1044,13 +1069,16 @@ public class AutocompleteManager {
|
||||
|
||||
// Check if we found a dot
|
||||
if (pos >= 0 && text.charAt(pos) == '.') {
|
||||
if (document != null && document.isExcluded(pos)) return -1;
|
||||
return pos;
|
||||
} else {
|
||||
while (pos >= 0 && Character.isJavaIdentifierPart(text.charAt(pos)))
|
||||
pos--;
|
||||
|
||||
if (pos >= 0 && text.charAt(pos) == '.')
|
||||
if (pos >= 0 && text.charAt(pos) == '.') {
|
||||
if (document != null && document.isExcluded(pos)) return -1;
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -151,11 +151,11 @@ public class FieldChainMarker {
|
||||
int pos = m.end(2);
|
||||
while (pos < text.length()) {
|
||||
pos = document.skipWhitespace(pos);
|
||||
if (pos >= text.length() || text.charAt(pos) != '.') break;
|
||||
if (pos >= text.length() || document.isExcluded(pos) || text.charAt(pos) != '.') break;
|
||||
pos++; // Skip dot
|
||||
|
||||
pos = document.skipWhitespace(pos);
|
||||
if (pos >= text.length() || !Character.isJavaIdentifierStart(text.charAt(pos))) break;
|
||||
if (pos >= text.length() || document.isExcluded(pos) || !Character.isJavaIdentifierStart(text.charAt(pos))) break;
|
||||
|
||||
// Read identifier
|
||||
int identStart = pos;
|
||||
@@ -452,11 +452,11 @@ public class FieldChainMarker {
|
||||
int pos = identEnd;
|
||||
while (pos < text.length()) {
|
||||
pos = document.skipWhitespace(pos);
|
||||
if (pos >= text.length() || text.charAt(pos) != '.') break;
|
||||
if (pos >= text.length() || document.isExcluded(pos) || text.charAt(pos) != '.') break;
|
||||
pos++; // Skip dot
|
||||
|
||||
pos = document.skipWhitespace(pos);
|
||||
if (pos >= text.length() || !Character.isJavaIdentifierStart(text.charAt(pos))) break;
|
||||
if (pos >= text.length() || document.isExcluded(pos) || !Character.isJavaIdentifierStart(text.charAt(pos))) break;
|
||||
|
||||
// Read identifier
|
||||
int nStart = pos;
|
||||
|
||||
@@ -6467,7 +6467,7 @@ public class ScriptDocument {
|
||||
while (pos >= 0 && Character.isWhitespace(text.charAt(pos)))
|
||||
pos--;
|
||||
|
||||
if (pos < 0 || text.charAt(pos) != '.')
|
||||
if (pos < 0 || isExcluded(pos) || text.charAt(pos) != '.')
|
||||
return false;
|
||||
|
||||
// Skip the dot and any whitespace
|
||||
@@ -6475,7 +6475,7 @@ public class ScriptDocument {
|
||||
while (pos >= 0 && Character.isWhitespace(text.charAt(pos)))
|
||||
pos--;
|
||||
|
||||
if (pos < 0)
|
||||
if (pos < 0 || isExcluded(pos))
|
||||
return false;
|
||||
|
||||
// Check what's before the dot - could be:
|
||||
@@ -6506,7 +6506,7 @@ public class ScriptDocument {
|
||||
pos--;
|
||||
|
||||
// If preceded by a dot, this is part of a chain - treat as instance for now
|
||||
if (pos >= 0 && text.charAt(pos) == '.') {
|
||||
if (pos >= 0 && !isExcluded(pos) && text.charAt(pos) == '.') {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -7199,7 +7199,8 @@ public class ScriptDocument {
|
||||
while (scanPos >= 0 && Character.isWhitespace(text.charAt(scanPos)))
|
||||
scanPos--;
|
||||
|
||||
if (scanPos < 0 || text.charAt(scanPos) != '.') {
|
||||
// Guard: dot inside a comment/string must not be treated as a receiver chain separator
|
||||
if (scanPos < 0 || isExcluded(scanPos) || text.charAt(scanPos) != '.') {
|
||||
return null; // No receiver
|
||||
}
|
||||
|
||||
@@ -8130,11 +8131,24 @@ public class ScriptDocument {
|
||||
|
||||
if (Character.isJavaIdentifierPart(c)) {
|
||||
while (pos >= 0 && Character.isJavaIdentifierPart(text.charAt(pos))) pos--;
|
||||
// Skip whitespace to check for chained identifier (preceded by a dot)
|
||||
// Skip whitespace AND excluded ranges to check for chained identifier (preceded by a dot).
|
||||
// Without skipping excluded ranges, a dot inside a comment (e.g. "//event.\n player")
|
||||
// would be mistaken for a chain continuation dot.
|
||||
int checkPos = pos;
|
||||
while (checkPos >= 0 && Character.isWhitespace(text.charAt(checkPos))) checkPos--;
|
||||
// If it's part of a chained identifier (preceded by a dot), continue
|
||||
if (checkPos >= 0 && text.charAt(checkPos) == '.') { pos = checkPos - 1; continue; }
|
||||
while (checkPos >= 0) {
|
||||
if (isExcluded(checkPos)) {
|
||||
for (int[] range : excludedRanges) {
|
||||
if (checkPos >= range[0] && checkPos < range[1]) {
|
||||
checkPos = range[0] - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (Character.isWhitespace(text.charAt(checkPos))) { checkPos--; continue; }
|
||||
break;
|
||||
}
|
||||
if (checkPos >= 0 && !isExcluded(checkPos) && text.charAt(checkPos) == '.') { pos = checkPos - 1; continue; }
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user