nixd
Loading...
Searching...
No Matches
Support.cpp
Go to the documentation of this file.
2
4#include <nixf/Parse/Parser.h>
6
7#include <boost/asio/post.hpp>
8
9#include <mutex>
10
11using namespace lspserver;
12using namespace nixd;
13
14void Controller::removeDocument(lspserver::PathRef File) {
15 Store.removeDraft(File);
16 {
17 std::lock_guard _(TUsLock);
18 TUs.erase(File);
19 }
20}
21
22void Controller::actOnDocumentAdd(PathRef File,
23 std::optional<int64_t> Version) {
24 auto Action = [this, File = std::string(File), Version]() {
25 auto Draft = Store.getDraft(File);
26 std::shared_ptr<const std::string> Src = Draft->Contents;
27 assert(Draft && "Added document is not in the store?");
28
29 std::vector<nixf::Diagnostic> Diagnostics;
30 std::shared_ptr<nixf::Node> AST =
31 nixf::parse(*Draft->Contents, Diagnostics);
32
33 if (!AST) {
34 std::lock_guard G(TUsLock);
35 publishDiagnostics(File, Version, *Src, Diagnostics);
36 TUs.insert_or_assign(File,
37 std::make_shared<NixTU>(std::move(Diagnostics),
38 std::move(AST), std::nullopt,
39 /*VLA=*/nullptr, Src));
40 return;
41 }
42
43 auto VLA = std::make_unique<nixf::VariableLookupAnalysis>(Diagnostics);
44 VLA->runOnAST(*AST);
45
46 publishDiagnostics(File, Version, *Src, Diagnostics);
47
48 {
49 std::lock_guard G(TUsLock);
50 TUs.insert_or_assign(
51 File, std::make_shared<NixTU>(std::move(Diagnostics), std::move(AST),
52 std::nullopt, std::move(VLA), Src));
53 return;
54 }
55 };
56 Action();
57}
58
59void Controller::createWorkDoneProgress(
61 if (ClientCaps.WorkDoneProgress)
62 CreateWorkDoneProgress(Params, [](llvm::Expected<std::nullptr_t> Reply) {
63 if (!Reply)
64 elog("create workdone progress error: {0}", Reply.takeError());
65 });
66}
67
68Controller::Controller(std::unique_ptr<lspserver::InboundPort> In,
69 std::unique_ptr<lspserver::OutboundPort> Out)
70 : LSPServer(std::move(In), std::move(Out)) {
71
72 // Life Cycle
73 Registry.addMethod("initialize", this, &Controller::onInitialize);
74 Registry.addNotification("initialized", this, &Controller::onInitialized);
75
76 Registry.addMethod("shutdown", this, &Controller::onShutdown);
77
78 // Text Document Synchronization
79 Registry.addNotification("textDocument/didOpen", this,
80 &Controller::onDocumentDidOpen);
81 Registry.addNotification("textDocument/didChange", this,
82 &Controller::onDocumentDidChange);
83
84 Registry.addNotification("textDocument/didClose", this,
85 &Controller::onDocumentDidClose);
86
87 // Language Features
88 Registry.addMethod("textDocument/definition", this,
89 &Controller::onDefinition);
90 Registry.addMethod("textDocument/documentSymbol", this,
91 &Controller::onDocumentSymbol);
92 Registry.addMethod("textDocument/semanticTokens/full", this,
93 &Controller::onSemanticTokens);
94 Registry.addMethod("textDocument/inlayHint", this, &Controller::onInlayHint);
95 Registry.addMethod("textDocument/completion", this,
96 &Controller::onCompletion);
97 Registry.addMethod("completionItem/resolve", this,
98 &Controller::onCompletionItemResolve);
99 Registry.addMethod("textDocument/references", this,
100 &Controller::onReferences);
101 Registry.addMethod("textDocument/documentHighlight", this,
102 &Controller::onDocumentHighlight);
103 Registry.addMethod("textDocument/documentLink", this,
104 &Controller::onDocumentLink);
105 Registry.addMethod("textDocument/codeAction", this,
106 &Controller::onCodeAction);
107 Registry.addMethod("textDocument/hover", this, &Controller::onHover);
108 Registry.addMethod("textDocument/formatting", this, &Controller::onFormat);
109 Registry.addMethod("textDocument/rename", this, &Controller::onRename);
110 Registry.addMethod("textDocument/prepareRename", this,
111 &Controller::onPrepareRename);
112
113 // Workspace features
114 Registry.addNotification("workspace/didChangeConfiguration", this,
115 &Controller::onDidChangeConfiguration);
116
118 "workspace/configuration");
119
121 "textDocument/publishDiagnostics");
122 CreateWorkDoneProgress =
124 "window/workDoneProgress/create");
125 BeginWorkDoneProgress =
127 ReportWorkDoneProgress =
129 EndWorkDoneProgress =
131}
Lookup variable names, from it's parent scope.
std::optional< Draft > getDraft(PathRef File) const
void removeDraft(PathRef File)
Remove the draft from the store.
HandlerRegistry Registry
Definition LSPServer.h:55
Controller(std::unique_ptr< lspserver::InboundPort > In, std::unique_ptr< lspserver::OutboundPort > Out)
Definition Support.cpp:68
Parser interface.
Whether current platform treats paths case insensitively.
Definition Connection.h:11
void elog(const char *Fmt, Ts &&...Vals)
Definition Logger.h:52
llvm::StringRef PathRef
Definition Path.h:27
bool fromJSON(const llvm::json::Value &Params, Configuration::Diagnostic &R, llvm::json::Path P)
std::shared_ptr< Node > parse(std::string_view Src, std::vector< Diagnostic > &Diags)
Parse a string.
void addMethod(llvm::StringRef Method, ThisT *This, void(ThisT::*Handler)(const Param &, Callback< Result >))
Definition LSPBinder.h:57
void addNotification(llvm::StringLiteral Method, ThisT *This, void(ThisT::*Handler)(const Param &))
Definition LSPBinder.h:73