diff --git a/nixd/lib/Controller/DocumentHighlight.cpp b/nixd/lib/Controller/DocumentHighlight.cpp index e143efb2a..1dd5658e3 100644 --- a/nixd/lib/Controller/DocumentHighlight.cpp +++ b/nixd/lib/Controller/DocumentHighlight.cpp @@ -9,6 +9,7 @@ #include "nixd/Controller/Controller.h" #include +#include #include #include #include @@ -58,7 +59,14 @@ void Controller::onDocumentHighlight( std::vector 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{}); + lspserver::elog("textDocument/documentHighlight failed: {0}", Err); return; } Reply(std::move(Highlights)); diff --git a/nixd/tools/nixd/test/document-highlight-fail.md b/nixd/tools/nixd/test/document-highlight-fail.md new file mode 100644 index 000000000..f8d243777 --- /dev/null +++ b/nixd/tools/nixd/test/document-highlight-fail.md @@ -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"} +```