Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixd/Server: fix dead semaphore in Controller::onCompletion #241

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions nixd/lib/Server/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,15 @@ void Controller::onHover(const lspserver::TextDocumentPositionParams &Params,
void Controller::onCompletion(const lspserver::CompletionParams &Params,
lspserver::Callback<llvm::json::Value> Reply) {
// Statically construct the completion list.
std::binary_semaphore Smp(0);
auto Path = Params.textDocument.uri.file();
auto Action = [&Smp, &Params, &Reply,

auto OpDraft = DraftMgr.getDraft(Path);
if (!OpDraft) {
Reply(lspserver::error("requested completion list on unknown draft path"));
return;
}

auto Action = [Params, Reply = std::move(Reply),
this](const ParseAST &AST,
ASTManager::VersionTy Version) mutable {
using PL = ParseAST::LocationContext;
Expand Down Expand Up @@ -624,16 +630,10 @@ void Controller::onCompletion(const lspserver::CompletionParams &Params,
L.isIncomplete = true;
RR.Response = std::move(L);
}
Smp.release();
};

if (auto Draft = DraftMgr.getDraft(Path)) {
auto Version = EvalDraftStore::decodeVersion(Draft->Version).value_or(0);
ASTMgr.withAST(Path.str(), Version, std::move(Action));
Smp.acquire();
} else {
Reply(lspserver::error("requested completion list on unknown draft path"));
}
auto Version = EvalDraftStore::decodeVersion(OpDraft->Version).value_or(0);
ASTMgr.withAST(Path.str(), Version, std::move(Action));
}

void Controller::onRename(const lspserver::RenameParams &Params,
Expand Down