From 5a48cf86f1ee97eec6a238e36c3a2f40b5d26fea Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 14 Mar 2018 18:31:48 +0000 Subject: [PATCH] [clangd] Use Contents from inputs in codeComplete and signatureHelp Summary: ClangdServer::{codeComplete,signatureHelp} both use the Contents from the draft manager. Since we want to move the draft manager from ClangdServer to ClangdLSPServer, this patch changes those methods to find the file contents from InputsAndPreamble, which contains the source passed in previously. Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D44484 llvm-svn: 327550 --- clang-tools-extra/clangd/ClangdServer.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 789382d..4e0e955 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -154,9 +154,9 @@ void ClangdServer::codeComplete(PathRef File, Position Pos, // Copy PCHs to avoid accessing this->PCHs concurrently std::shared_ptr PCHs = this->PCHs; auto FS = FSProvider.getFileSystem(); - auto Task = [PCHs, Pos, FS, CodeCompleteOpts]( - std::string Contents, Path File, Callback CB, - llvm::Expected IP) { + auto Task = [PCHs, Pos, FS, + CodeCompleteOpts](Path File, Callback CB, + llvm::Expected IP) { assert(IP && "error when trying to read preamble for codeComplete"); auto PreambleData = IP->Preamble; @@ -164,13 +164,12 @@ void ClangdServer::codeComplete(PathRef File, Position Pos, // both the old and the new version in case only one of them matches. CompletionList Result = clangd::codeComplete( File, IP->Command, PreambleData ? &PreambleData->Preamble : nullptr, - Contents, Pos, FS, PCHs, CodeCompleteOpts); + IP->Contents, Pos, FS, PCHs, CodeCompleteOpts); CB(std::move(Result)); }; - WorkScheduler.runWithPreamble( - "CodeComplete", File, - Bind(Task, std::move(*Latest.Draft), File.str(), std::move(CB))); + WorkScheduler.runWithPreamble("CodeComplete", File, + Bind(Task, File.str(), std::move(CB))); } void ClangdServer::signatureHelp(PathRef File, Position Pos, @@ -183,8 +182,7 @@ void ClangdServer::signatureHelp(PathRef File, Position Pos, auto PCHs = this->PCHs; auto FS = FSProvider.getFileSystem(); - auto Action = [Pos, FS, PCHs](std::string Contents, Path File, - Callback CB, + auto Action = [Pos, FS, PCHs](Path File, Callback CB, llvm::Expected IP) { if (!IP) return CB(IP.takeError()); @@ -192,12 +190,11 @@ void ClangdServer::signatureHelp(PathRef File, Position Pos, auto PreambleData = IP->Preamble; CB(clangd::signatureHelp(File, IP->Command, PreambleData ? &PreambleData->Preamble : nullptr, - Contents, Pos, FS, PCHs)); + IP->Contents, Pos, FS, PCHs)); }; - WorkScheduler.runWithPreamble( - "SignatureHelp", File, - Bind(Action, std::move(*Latest.Draft), File.str(), std::move(CB))); + WorkScheduler.runWithPreamble("SignatureHelp", File, + Bind(Action, File.str(), std::move(CB))); } llvm::Expected -- 2.7.4