Skip to content

Commit

Permalink
nixd: publish variable lookup diagnostics (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc authored Apr 8, 2024
1 parent 1746296 commit 8eab44b
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
8 changes: 7 additions & 1 deletion nixd/tools/nixd/src/Support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "nixf/Basic/Diagnostic.h"
#include "nixf/Bytecode/Write.h"
#include "nixf/Parse/Parser.h"
#include "nixf/Sema/VariableLookup.h"

#include <boost/asio/post.hpp>

Expand Down Expand Up @@ -38,14 +39,19 @@ void Controller::actOnDocumentAdd(PathRef File,
std::vector<nixf::Diagnostic> Diagnostics;
std::shared_ptr<nixf::Node> AST =
nixf::parse(*Draft->Contents, Diagnostics);
publishDiagnostics(File, Version, Diagnostics);

if (!AST) {
std::lock_guard G(TUsLock);
publishDiagnostics(File, Version, Diagnostics);
TUs[File] = NixTU(std::move(Diagnostics), std::move(AST), std::nullopt);
return;
}

nixf::VariableLookupAnalysis VLA(Diagnostics);
VLA.runOnAST(*AST);

publishDiagnostics(File, Version, Diagnostics);

// Serialize the AST into shared memory. Prepare for evaluation.
std::stringstream OS;
nixf::writeBytecode(OS, AST.get());
Expand Down
63 changes: 63 additions & 0 deletions nixd/tools/nixd/test/diagnostic-liveness.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# RUN: nixd --lit-test < %s | FileCheck %s

<-- initialize(0)

```json
{
"jsonrpc":"2.0",
"id":0,
"method":"initialize",
"params":{
"processId":123,
"rootPath":"",
"capabilities":{
},
"trace":"off"
}
}
```


<-- textDocument/didOpen

```json
{
"jsonrpc":"2.0",
"method":"textDocument/didOpen",
"params":{
"textDocument":{
"uri":"file:///basic.nix",
"languageId":"nix",
"version":1,
"text":"x: y: x + 1"
}
}
}
```

```
CHECK: "diagnostics": [
CHECK-NEXT: {
CHECK-NEXT: "code": "sema-def-not-used",
CHECK-NEXT: "message": "definition `y` is not used",
CHECK-NEXT: "range": {
CHECK-NEXT: "end": {
CHECK-NEXT: "character": 4,
CHECK-NEXT: "line": 0
CHECK-NEXT: },
CHECK-NEXT: "start": {
CHECK-NEXT: "character": 3,
CHECK-NEXT: "line": 0
CHECK-NEXT: }
CHECK-NEXT: },
CHECK-NEXT: "relatedInformation": [],
CHECK-NEXT: "severity": 2,
CHECK-NEXT: "source": "nixf",
CHECK-NEXT: "tags": [
CHECK-NEXT: 1
CHECK-NEXT: ]
CHECK-NEXT: }
CHECK-NEXT: ],
CHECK-NEXT: "uri": "file:///basic.nix",
CHECK-NEXT: "version": 1
```

0 comments on commit 8eab44b

Please sign in to comment.