Skip to content

Commit

Permalink
nixd: redirect doc highlight error from UI into log
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc committed Apr 9, 2024
1 parent 3b6e46f commit 36d1bbf
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
10 changes: 9 additions & 1 deletion nixd/lib/Controller/DocumentHighlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "nixd/Controller/Controller.h"

#include <boost/asio/post.hpp>
#include <cstddef>
#include <lspserver/Protocol.h>
#include <nixf/Sema/ParentMap.h>
#include <nixf/Sema/VariableLookup.h>
Expand Down Expand Up @@ -58,7 +59,14 @@ void Controller::onDocumentHighlight(
std::vector<DocumentHighlight> Highlights;
if (auto Err = highlight(*Desc, *TU->parentMap(), *TU->variableLookup(),
URI, Highlights)) {
Reply(std::move(Err));
// FIXME: Empty response if there are no def-use chain found.
// For document highlights, the specification explicitly specified LSP
// should do "fuzzy" things.

// Empty response on error, don't reply all errors because this method
// is very frequently called.
Reply(std::vector<DocumentHighlight>{});
lspserver::elog("textDocument/documentHighlight failed: {0}", Err);
return;
}
Reply(std::move(Highlights));
Expand Down
66 changes: 66 additions & 0 deletions nixd/tools/nixd/test/document-highlight-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# 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":"let x = 1; y = 2; in x + y"
}
}
}
```

<-- textDocument/documentHighlight(2)


```json
{
"jsonrpc":"2.0",
"id":2,
"method":"textDocument/documentHighlight",
"params":{
"textDocument":{
"uri":"file:///basic.nix"
},
"position":{
"line": 0,
"character":1
}
}
}
```

```
CHECK: "id": 2,
CHECK-NEXT: "jsonrpc": "2.0",
CHECK-NEXT: "result": []
```

```json
{"jsonrpc":"2.0","method":"exit"}
```

0 comments on commit 36d1bbf

Please sign in to comment.