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 publishDiagnostics(File, std::nullopt, "", {});
21}
22
23void Controller::actOnDocumentAdd(PathRef File,
24 std::optional<int64_t> Version) {
25 auto Action = [this, File = std::string(File), Version]() {
26 auto Draft = Store.getDraft(File);
27 std::shared_ptr<const std::string> Src = Draft->Contents;
28 assert(Draft && "Added document is not in the store?");
29
30 std::vector<nixf::Diagnostic> Diagnostics;
31 std::shared_ptr<nixf::Node> AST =
32 nixf::parse(*Draft->Contents, Diagnostics);
33
34 if (!AST) {
35 std::lock_guard G(TUsLock);
36 publishDiagnostics(File, Version, *Src, Diagnostics);
37 TUs.insert_or_assign(File,
38 std::make_shared<NixTU>(std::move(Diagnostics),
39 std::move(AST), std::nullopt,
40 /*VLA=*/nullptr, Src));
41 return;
42 }
43
44 auto VLA = std::make_unique<nixf::VariableLookupAnalysis>(Diagnostics);
45 VLA->runOnAST(*AST);
46
47 publishDiagnostics(File, Version, *Src, Diagnostics);
48
49 {
50 std::lock_guard G(TUsLock);
51 TUs.insert_or_assign(
52 File, std::make_shared<NixTU>(std::move(Diagnostics), std::move(AST),
53 std::nullopt, std::move(VLA), Src));
54 return;
55 }
56 };
57 Action();
58}
59
60void Controller::createWorkDoneProgress(
62 if (ClientCaps.WorkDoneProgress)
63 CreateWorkDoneProgress(Params, [](llvm::Expected<std::nullptr_t> Reply) {
64 if (!Reply)
65 elog("create workdone progress error: {0}", Reply.takeError());
66 });
67}
68
69Controller::Controller(std::unique_ptr<lspserver::InboundPort> In,
70 std::unique_ptr<lspserver::OutboundPort> Out)
71 : LSPServer(std::move(In), std::move(Out)) {
72
73 // Life Cycle
74 Registry.addMethod("initialize", this, &Controller::onInitialize);
75 Registry.addNotification("initialized", this, &Controller::onInitialized);
76
77 Registry.addMethod("shutdown", this, &Controller::onShutdown);
78
79 // Text Document Synchronization
80 Registry.addNotification("textDocument/didOpen", this,
81 &Controller::onDocumentDidOpen);
82 Registry.addNotification("textDocument/didChange", this,
83 &Controller::onDocumentDidChange);
84
85 Registry.addNotification("textDocument/didClose", this,
86 &Controller::onDocumentDidClose);
87
88 // Language Features
89 Registry.addMethod("textDocument/definition", this,
90 &Controller::onDefinition);
91 Registry.addMethod("textDocument/documentSymbol", this,
92 &Controller::onDocumentSymbol);
93 Registry.addMethod("textDocument/semanticTokens/full", this,
94 &Controller::onSemanticTokens);
95 Registry.addMethod("textDocument/inlayHint", this, &Controller::onInlayHint);
96 Registry.addMethod("textDocument/completion", this,
97 &Controller::onCompletion);
98 Registry.addMethod("completionItem/resolve", this,
99 &Controller::onCompletionItemResolve);
100 Registry.addMethod("textDocument/references", this,
101 &Controller::onReferences);
102 Registry.addMethod("textDocument/documentHighlight", this,
103 &Controller::onDocumentHighlight);
104 Registry.addMethod("textDocument/documentLink", this,
105 &Controller::onDocumentLink);
106 Registry.addMethod("textDocument/codeAction", this,
107 &Controller::onCodeAction);
108 Registry.addMethod("textDocument/hover", this, &Controller::onHover);
109 Registry.addMethod("textDocument/formatting", this, &Controller::onFormat);
110 Registry.addMethod("textDocument/rename", this, &Controller::onRename);
111 Registry.addMethod("textDocument/prepareRename", this,
112 &Controller::onPrepareRename);
113
114 // Workspace features
115 Registry.addNotification("workspace/didChangeConfiguration", this,
116 &Controller::onDidChangeConfiguration);
117
119 "workspace/configuration");
120
122 "textDocument/publishDiagnostics");
123 CreateWorkDoneProgress =
125 "window/workDoneProgress/create");
126 BeginWorkDoneProgress =
128 ReportWorkDoneProgress =
130 EndWorkDoneProgress =
132}
Lookup variable names, from it's parent scope.
llvm::unique_function< void(const ParamTy &, Callback< ResponseTy >)> mkOutMethod(llvm::StringRef Method, OutboundPort *O=nullptr)
Definition LSPServer.h:69
HandlerRegistry Registry
Definition LSPServer.h:55
LSPServer(std::unique_ptr< InboundPort > In, std::unique_ptr< OutboundPort > Out)
Definition LSPServer.h:87
llvm::unique_function< void(const T &)> mkOutNotifiction(llvm::StringRef Method, OutboundPort *O=nullptr)
Definition LSPServer.h:58
Controller(std::unique_ptr< lspserver::InboundPort > In, std::unique_ptr< lspserver::OutboundPort > Out)
Definition Support.cpp:69
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
std::shared_ptr< Node > parse(std::string_view Src, std::vector< Diagnostic > &Diags)
Parse a string.