From bfdd44087273434a5f5dc52c6e79db8f307c76c2 Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Fri, 11 Aug 2023 14:34:43 +0800 Subject: [PATCH] nixd/Server: fix dead semaphore in `Controller::onCompletion` --- nixd/lib/Server/Controller.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/nixd/lib/Server/Controller.cpp b/nixd/lib/Server/Controller.cpp index b7c392d33..d8ba4512a 100644 --- a/nixd/lib/Server/Controller.cpp +++ b/nixd/lib/Server/Controller.cpp @@ -552,9 +552,15 @@ void Controller::onHover(const lspserver::TextDocumentPositionParams &Params, void Controller::onCompletion(const lspserver::CompletionParams &Params, lspserver::Callback 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; @@ -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,