diff --git a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/ErrorUnderlineRenderer.java b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/ErrorUnderlineRenderer.java index 3f475452a..2f8edf488 100644 --- a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/ErrorUnderlineRenderer.java +++ b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/ErrorUnderlineRenderer.java @@ -111,7 +111,7 @@ public class ErrorUnderlineRenderer { } // Check all method declarations for errors - for (MethodInfo method : doc.getMethods()) { + for (MethodInfo method : doc.getAllMethods()) { if (!method.isDeclaration() || !method.hasError()) continue; @@ -124,21 +124,14 @@ public class ErrorUnderlineRenderer { } // Handle missing return error (underline the method name) - if (method.hasMissingReturnError()) { + else if (method.hasMissingReturnError()) { int methodNameStart = method.getNameOffset(); int methodNameEnd = methodNameStart + method.getName().length(); drawUnderlineForSpan(methodNameStart, methodNameEnd, lineStartX, baselineY, lineText, lineStart, lineEnd, ERROR_COLOR); } - - // Handle duplicate method error (underline from full declaration start to closing paren) - if (method.getErrorType() == MethodInfo.ErrorType.DUPLICATE_METHOD) { - drawUnderlineForSpan(method.getFullDeclarationOffset(), method.getDeclarationEnd(), - lineStartX, baselineY, lineText, lineStart, lineEnd, ERROR_COLOR); - } - // Handle parameter errors - if (method.hasParameterErrors()) { + else if (method.hasParameterErrors()) { for (MethodInfo.ParameterError paramError : method.getParameterErrors()) { FieldInfo param = paramError.getParameter(); if (param == null || param.getDeclarationOffset() < 0) @@ -150,6 +143,13 @@ public class ErrorUnderlineRenderer { lineText, lineStart, lineEnd, ERROR_COLOR); } } + + // Handle all other errors + else if (method.hasError()) { + drawUnderlineForSpan(method.getFullDeclarationOffset(), method.getDeclarationEnd(), lineStartX, + baselineY, lineText, lineStart, lineEnd, ERROR_COLOR); + } + } } 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 d84e1d401..d2e6d51d1 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 @@ -4482,6 +4482,13 @@ public class ScriptDocument { return Collections.unmodifiableList(methods); } + public List getAllMethods() { + List allMethods = new ArrayList<>(methods); + for (ScriptTypeInfo scriptType : scriptTypes.values()) + allMethods.addAll(scriptType.getAllMethodsFlat()); + + return allMethods; + } public List getMethodCalls() { return Collections.unmodifiableList(methodCalls); } diff --git a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/hover/TokenHoverInfo.java b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/hover/TokenHoverInfo.java index 9404b9313..02e65fe1a 100644 --- a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/hover/TokenHoverInfo.java +++ b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/hover/TokenHoverInfo.java @@ -232,18 +232,8 @@ public class TokenHoverInfo { } } - // If hovering over duplicate method declaration, show the error - if (methodDecl.getErrorType() == MethodInfo.ErrorType.DUPLICATE_METHOD) { - int declStart = methodDecl.getFullDeclarationOffset(); - int declEnd = methodDecl.getDeclarationEnd(); - - if (tokenStart >= declStart && tokenEnd <= declEnd) { - errors.add(methodDecl.getErrorMessage()); - } - } - // If hovering over a parameter with an error, show that error - if (methodDecl.hasParameterErrors()) { + else if (methodDecl.hasParameterErrors()) { for (MethodInfo.ParameterError paramError : methodDecl.getParameterErrors()) { FieldInfo param = paramError.getParameter(); if (param != null && param.getDeclarationOffset() >= 0) { @@ -258,7 +248,7 @@ public class TokenHoverInfo { } // If hovering over a return statement with a type error, show that error - if (methodDecl.hasReturnStatementErrors()) { + else if (methodDecl.hasReturnStatementErrors()) { for (MethodInfo.ReturnStatementError returnError : methodDecl.getReturnStatementErrors()) { int returnStart = returnError.getStartOffset(); int returnEnd = returnError.getEndOffset(); @@ -268,6 +258,17 @@ public class TokenHoverInfo { } } } + + + // All other errors + else if (methodDecl.hasError()) { + int declStart = methodDecl.getFullDeclarationOffset(); + int declEnd = methodDecl.getDeclarationEnd(); + + if (tokenStart >= declStart && tokenEnd <= declEnd) { + errors.add(methodDecl.getErrorMessage()); + } + } } if(token.getType() == TokenType.UNDEFINED_VAR) @@ -337,7 +338,7 @@ public class TokenHoverInfo { ScriptDocument doc = line.getParent(); int tokenStart = token.getGlobalStart(); - for (MethodInfo method : doc.getMethods()) { + for (MethodInfo method : doc.getAllMethods()) { if (!method.isDeclaration()) continue; diff --git a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/method/MethodInfo.java b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/method/MethodInfo.java index 80ba41796..1d4092d7b 100644 --- a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/method/MethodInfo.java +++ b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/method/MethodInfo.java @@ -34,6 +34,7 @@ public final class MethodInfo { public enum ErrorType { NONE, MISSING_RETURN, // Non-void method missing return statement + MISSING_BODY, // Non-void method missing return statement RETURN_TYPE_MISMATCH, // Return statement type doesn't match method return type VOID_METHOD_RETURNS_VALUE, // Void method returns a value DUPLICATE_METHOD, // Method with same signature already defined in scope @@ -433,6 +434,11 @@ public final class MethodInfo { //No need to check for return types/statements if(bodyless) return; + + if (bodyStart == bodyEnd && !isAbstract() && !isNative()) { + setError(ErrorType.MISSING_BODY, "Method must have a body or be declared abstract/native."); + return; + } // Validate return statement types FIRST if we have a type resolver // This ensures type errors are shown even if there's also a missing return