mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 20:07:32 +00:00
Bunch of JS fixes
This commit is contained in:
1 parent
c56a8ee7d9
commit
50bcbb5872
4 files changed
+41
-9
No files matched your search
+6
-2
@@ -1,12 +1,10 @@
|
||||
package noppes.npcs.client.gui.util.script.autocomplete;
|
||||
|
||||
import noppes.npcs.client.gui.util.script.JavaTextContainer.LineData;
|
||||
import noppes.npcs.client.gui.util.script.interpreter.ScriptDocument;
|
||||
import noppes.npcs.client.gui.util.script.interpreter.ScriptTextContainer;
|
||||
import noppes.npcs.client.gui.util.script.interpreter.type.TypeInfo;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -391,6 +389,12 @@ public class AutocompleteManager {
|
||||
|
||||
// Get suggestions from appropriate provider
|
||||
AutocompleteProvider provider = document.isJavaScript() ? jsProvider : javaProvider;
|
||||
|
||||
// For JavaScript, update variable types from analyzer
|
||||
if (document.isJavaScript() && document.getJSAnalyzer() != null) {
|
||||
jsProvider.updateVariableTypes(document.getJSAnalyzer().getVariableTypes());
|
||||
}
|
||||
|
||||
List<AutocompleteItem> suggestions = provider.getSuggestions(context);
|
||||
|
||||
// Limit suggestions to prevent overwhelming the UI and improve performance
|
||||
|
||||
@@ -161,7 +161,7 @@ public class ScriptDocument {
|
||||
* Check if this is a JavaScript/ECMAScript document.
|
||||
*/
|
||||
public boolean isJavaScript() {
|
||||
return false;//"ECMAScript".equalsIgnoreCase(language);
|
||||
return "ECMAScript".equalsIgnoreCase(language);
|
||||
}
|
||||
|
||||
// ==================== TEXT MANAGEMENT ====================
|
||||
@@ -271,14 +271,24 @@ public class ScriptDocument {
|
||||
// Phase 7: Compute indent guides
|
||||
computeIndentGuides(marks);
|
||||
}
|
||||
|
||||
// Store the last JS analyzer for autocomplete
|
||||
private JSScriptAnalyzer currentJSAnalyzer;
|
||||
|
||||
/**
|
||||
* Format JavaScript/ECMAScript code using the JS type inference system.
|
||||
*/
|
||||
private List<ScriptLine.Mark> formatJavaScript() {
|
||||
// Use JSScriptAnalyzer for JS-specific analysis
|
||||
JSScriptAnalyzer analyzer = new JSScriptAnalyzer(text);
|
||||
return analyzer.analyze();
|
||||
currentJSAnalyzer = new JSScriptAnalyzer(this);
|
||||
return currentJSAnalyzer.analyze();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last JS analyzer (for autocomplete to access variable types).
|
||||
*/
|
||||
public JSScriptAnalyzer getJSAnalyzer() {
|
||||
return currentJSAnalyzer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+13
-2
@@ -1,7 +1,9 @@
|
||||
package noppes.npcs.client.gui.util.script.interpreter.js_parser;
|
||||
|
||||
import noppes.npcs.client.gui.util.script.interpreter.ScriptDocument;
|
||||
import noppes.npcs.client.gui.util.script.interpreter.ScriptLine;
|
||||
import noppes.npcs.client.gui.util.script.interpreter.token.TokenType;
|
||||
import scala.annotation.meta.field;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.*;
|
||||
@@ -12,6 +14,7 @@ import java.util.regex.*;
|
||||
*/
|
||||
public class JSScriptAnalyzer {
|
||||
|
||||
private final ScriptDocument document;
|
||||
private final String text;
|
||||
private final JSTypeRegistry registry;
|
||||
|
||||
@@ -41,8 +44,9 @@ public class JSScriptAnalyzer {
|
||||
|
||||
private static final Pattern NUMBER_PATTERN = Pattern.compile("\\b\\d+\\.?\\d*\\b");
|
||||
|
||||
public JSScriptAnalyzer(String text) {
|
||||
this.text = text;
|
||||
public JSScriptAnalyzer(ScriptDocument document) {
|
||||
this.document = document;
|
||||
this.text = document.getText();
|
||||
this.registry = JSTypeRegistry.getInstance();
|
||||
// Ensure registry is initialized
|
||||
if (!registry.isInitialized()) {
|
||||
@@ -385,4 +389,11 @@ public class JSScriptAnalyzer {
|
||||
public String getVariableType(String varName) {
|
||||
return variableTypes.get(varName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all inferred variable types.
|
||||
*/
|
||||
public Map<String, String> getVariableTypes() {
|
||||
return new HashMap<>(variableTypes);
|
||||
}
|
||||
}
|
||||
+9
-2
@@ -254,12 +254,15 @@ public class JSTypeRegistry {
|
||||
|
||||
// Detect circular alias references
|
||||
if (visited.contains(baseName)) {
|
||||
System.err.println("[JSTypeRegistry] Circular type alias detected: " + baseName);
|
||||
// Circular alias detected - try direct type lookup as fallback
|
||||
if (types.containsKey(baseName)) {
|
||||
return types.get(baseName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
visited.add(baseName);
|
||||
|
||||
// Direct lookup
|
||||
// Direct lookup in types first (higher priority than aliases)
|
||||
if (types.containsKey(baseName)) {
|
||||
return types.get(baseName);
|
||||
}
|
||||
@@ -267,6 +270,10 @@ public class JSTypeRegistry {
|
||||
// Check type aliases
|
||||
if (typeAliases.containsKey(baseName)) {
|
||||
String resolved = typeAliases.get(baseName);
|
||||
// Don't follow alias if it resolves to itself
|
||||
if (resolved.equals(baseName)) {
|
||||
return null;
|
||||
}
|
||||
return getType(resolved, visited);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user