diff --git a/libnixf/include/nixf/Basic/Diagnostic.h b/libnixf/include/nixf/Basic/Diagnostic.h index 7228c48b3..1d45b8eac 100644 --- a/libnixf/include/nixf/Basic/Diagnostic.h +++ b/libnixf/include/nixf/Basic/Diagnostic.h @@ -149,11 +149,22 @@ class Diagnostic : public PartialDiagnostic { /// should be "Fatal", "Error" or "Warning" /// this will affect the eval process. /// - /// "Fatal" -- shouldn't eval the code, e.g. parsing error. - /// "Error" -- trigger an error in nix, but we can recover & eval the code. /// "Warning" -- just a warning. - /// "Note" -- some additional information about the error. - enum Severity { DS_Fatal, DS_Error, DS_Warning }; + enum Severity { + /// shouldn't eval the code, e.g. parsing error. + DS_Fatal, + /// trigger an error in nix, but we can recover & eval the code. + DS_Error, + /// A warning. + DS_Warning, + /// An information. + DS_Info, + + /// A hint. Hints are usually not rendered directly in some editor GUI + /// So this is suitable for liveness analysis results. + /// For example, "unused xxx" + DS_Hint, + }; /// Internal kind enum DiagnosticKind { diff --git a/libnixf/include/nixf/Basic/DiagnosticKinds.inc b/libnixf/include/nixf/Basic/DiagnosticKinds.inc index 9ecd4a2b4..7409b4cf7 100644 --- a/libnixf/include/nixf/Basic/DiagnosticKinds.inc +++ b/libnixf/include/nixf/Basic/DiagnosticKinds.inc @@ -54,11 +54,11 @@ DIAG("sema-dup-formal-arg", DuplicatedFormalToArg, Error, "function argument duplicated to a function formal") DIAG("sema-undefined-variable", UndefinedVariable, Error, "undefined variable `{}`") -DIAG("sema-def-not-used", DefinitionNotUsed, Warning, +DIAG("sema-def-not-used", DefinitionNotUsed, Hint, "definition `{}` is not used") -DIAG("sema-extra-rec", ExtraRecursive, Warning, +DIAG("sema-extra-rec", ExtraRecursive, Hint, "attrset is not necessary to be `rec`ursive ") -DIAG("sema-extra-with", ExtraWith, Warning, "unused `with` expression") +DIAG("sema-extra-with", ExtraWith, Hint, "unused `with` expression") // let a = 1; b = { a = 2; }; with b; a // "a" will bind to "let", not "with", that is not very intuitive. diff --git a/nixd/lib/Controller/Convert.cpp b/nixd/lib/Controller/Convert.cpp index d350219f1..8a68164d9 100644 --- a/nixd/lib/Controller/Convert.cpp +++ b/nixd/lib/Controller/Convert.cpp @@ -1,4 +1,5 @@ #include "Convert.h" +#include "nixf/Basic/Diagnostic.h" using namespace lspserver; @@ -11,6 +12,10 @@ int getLSPSeverity(nixf::Diagnostic::DiagnosticKind Kind) { return 1; case nixf::Diagnostic::DS_Warning: return 2; + case nixf::Diagnostic::DS_Info: + return 3; + case nixf::Diagnostic::DS_Hint: + return 4; } assert(false && "Invalid severity"); __builtin_unreachable(); diff --git a/nixd/tools/nixd/test/diagnostic-liveness-formal.md b/nixd/tools/nixd/test/diagnostic-liveness-formal.md index 4fc39b44b..f90dd5b71 100644 --- a/nixd/tools/nixd/test/diagnostic-liveness-formal.md +++ b/nixd/tools/nixd/test/diagnostic-liveness-formal.md @@ -51,7 +51,7 @@ CHECK-NEXT: "line": 0 CHECK-NEXT: } CHECK-NEXT: }, CHECK-NEXT: "relatedInformation": [], -CHECK-NEXT: "severity": 2, +CHECK-NEXT: "severity": 4, CHECK-NEXT: "source": "nixf", CHECK-NEXT: "tags": [ CHECK-NEXT: 1