12#include <boost/asio/post.hpp>
26std::vector<DocumentHighlight> highlight(
const nixf::Node &Desc,
30 llvm::StringRef Src) {
34 std::vector<DocumentHighlight> Highlights;
36 for (
const auto *Use : Def.uses()) {
40 .kind = DocumentHighlightKind::Read,
44 const Node &Syntax = *Def.syntax();
47 .kind = DocumentHighlightKind::Write,
56void Controller::onDocumentHighlight(
58 Callback<std::vector<DocumentHighlight>> Reply) {
59 using CheckTy = std::vector<DocumentHighlight>;
63 return Reply([&]() -> llvm::Expected<CheckTy> {
67 const auto &Desc = *
CheckDefault(AST->descend({Pos, Pos}));
69 const auto &PM = *TU->parentMap();
70 const auto &VLA = *TU->variableLookup();
71 return highlight(Desc, PM, VLA,
URI, TU->src());
72 }
catch (std::exception &E) {
73 elog(
"textDocument/documentHighlight failed: {0}", E.what());
78 boost::asio::post(Pool, std::move(Action));
#define CheckDefault(x)
Variant of CheckReturn, but returns default constructed CheckTy
Convert between LSP and nixf types.
Lookup variable names, from it's parent scope.
LexerCursorRange range() const
Whether current platform treats paths case insensitively.
llvm::unique_function< void(llvm::Expected< T >)> Callback
void elog(const char *Fmt, Ts &&...Vals)
nixf::Position toNixfPosition(const lspserver::Position &P)
const nixf::Definition & findDefinition(const nixf::Node &N, const nixf::ParentMapAnalysis &PMA, const nixf::VariableLookupAnalysis &VLA)
Heuristically find definition on some node.
lspserver::Range toLSPRange(llvm::StringRef Code, const nixf::LexerCursorRange &R)
URIForFile uri
The text document's URI.
Position position
The position inside the text document.
TextDocumentIdentifier textDocument
The text document.