Got error validation working for ScriptTypeInfo

This commit is contained in:
bigguy345 committed 2025-12-31 20:42:40 +02:00
1 parent 0caebb08ca
commit 35af0bbd2d
3 files changed
+58 -3

No files matched your search

@@ -5,6 +5,7 @@ import noppes.npcs.client.gui.util.script.interpreter.field.AssignmentInfo;
import noppes.npcs.client.gui.util.script.interpreter.field.FieldInfo;
import noppes.npcs.client.gui.util.script.interpreter.method.MethodCallInfo;
import noppes.npcs.client.gui.util.script.interpreter.method.MethodInfo;
import noppes.npcs.client.gui.util.script.interpreter.type.ScriptTypeInfo;
import org.lwjgl.opengl.GL11;
/**
@@ -151,6 +152,17 @@ public class ErrorUnderlineRenderer {
}
}
for(ScriptTypeInfo types : doc.getScriptTypes()){
if(!types.hasError())
continue;
int typeStart = types.getDeclarationOffset();
int typeEnd = types.getBodyStart();
drawUnderlineForSpan(typeStart, typeEnd, lineStartX, baselineY,
lineText, lineStart, lineEnd, ERROR_COLOR);
}
}
/**
@@ -22,6 +22,7 @@ import noppes.npcs.client.gui.util.script.interpreter.type.TypeResolver;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* The main document container that manages script text, lines, and tokens.
@@ -4944,6 +4945,10 @@ public class ScriptDocument {
return Collections.unmodifiableList(methods);
}
public List<ScriptTypeInfo> getScriptTypes() {
return scriptTypes.values().stream().collect(Collectors.toList());
}
public List<MethodInfo> getAllMethods() {
List<MethodInfo> allMethods = new ArrayList<>(methods);
for (ScriptTypeInfo scriptType : scriptTypes.values())
@@ -135,7 +135,6 @@ public class TokenHoverInfo {
case UNDEFINED_VAR:
info.extractUndefinedInfo(token);
break;
case LITERAL:
case KEYWORD:
case MODIFIER:
@@ -152,7 +151,9 @@ public class TokenHoverInfo {
info.extractMethodDeclInfo(token);
} else if (token.getFieldInfo() != null) {
info.extractFieldInfoGeneric(token);
} else {
} else if (info.hasErrors())
return info;
else {
return null; // Nothing to show
}
break;
@@ -271,6 +272,22 @@ public class TokenHoverInfo {
}
}
ScriptTypeInfo scriptType = findScriptTypeContainingPosition(token);
if (scriptType != null && scriptType.hasError()) {
// Missing interface method errors
for (ScriptTypeInfo.MissingMethodError err : scriptType.getMissingMethodErrors()) {
errors.add(err.getMessage());
}
// Constructor mismatch errors
for (ScriptTypeInfo.ConstructorMismatchError err : scriptType.getConstructorMismatchErrors()) {
errors.add(err.getMessage());
}
// General error message
if (scriptType.getErrorMessage() != null) {
errors.add(scriptType.getErrorMessage());
}
}
if(token.getType() == TokenType.UNDEFINED_VAR)
errors.add("Cannot resolve symbol '" + token.getText() + "'");
@@ -354,6 +371,27 @@ public class TokenHoverInfo {
}
return null;
}
private ScriptTypeInfo findScriptTypeContainingPosition(Token token) {
ScriptLine line = token.getParentLine();
if (line == null || line.getParent() == null) {
return null;
}
ScriptDocument doc = line.getParent();
int tokenStart = token.getGlobalStart();
for (ScriptTypeInfo scriptType : doc.getScriptTypes()) {
int typeStart = scriptType.getDeclarationOffset();
int typeEnd = scriptType.getBodyStart();
// Token is within the type declaration
if (tokenStart >= typeStart && tokenStart <= typeEnd) {
return scriptType;
}
}
return null;
}
/**
* Find the argument that contains the given position.
@@ -539,7 +577,7 @@ public class TokenHoverInfo {
}
// Add ScriptTypeInfo errors
if (scriptType.hasError()) {
if (false) { //|| scriptType.hasError()
// Missing interface method errors
for (ScriptTypeInfo.MissingMethodError err : scriptType.getMissingMethodErrors()) {
errors.add(err.getMessage());