forked from OSchip/llvm-project
[clangd] Return vector<TextEdit> from applyTweak. NFC
For the same reasons as r363150, which got overwritten by changes in r363680. Sending without review to unbreak our integrate. llvm-svn: 363691
This commit is contained in:
parent
ed4a602515
commit
df9ee08b64
clang-tools-extra/clangd
|
@ -491,14 +491,14 @@ void ClangdLSPServer::onCommand(const ExecuteCommandParams &Params,
|
|||
|
||||
auto Action = [this, ApplyEdit](decltype(Reply) Reply, URIForFile File,
|
||||
std::string Code,
|
||||
llvm::Expected<Tweak::Effect> R) {
|
||||
llvm::Expected<ResolvedEffect> R) {
|
||||
if (!R)
|
||||
return Reply(R.takeError());
|
||||
|
||||
if (R->ApplyEdit) {
|
||||
WorkspaceEdit WE;
|
||||
WE.changes.emplace();
|
||||
(*WE.changes)[File.uri()] = replacementsToEdits(Code, *R->ApplyEdit);
|
||||
(*WE.changes)[File.uri()] = *R->ApplyEdit;
|
||||
ApplyEdit(std::move(WE));
|
||||
}
|
||||
if (R->ShowMessage) {
|
||||
|
|
|
@ -325,7 +325,7 @@ void ClangdServer::enumerateTweaks(PathRef File, Range Sel,
|
|||
}
|
||||
|
||||
void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID,
|
||||
Callback<Tweak::Effect> CB) {
|
||||
Callback<ResolvedEffect> CB) {
|
||||
auto Action = [Sel](decltype(CB) CB, std::string File, std::string TweakID,
|
||||
Expected<InputsAndAST> InpAST) {
|
||||
if (!InpAST)
|
||||
|
@ -348,7 +348,13 @@ void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID,
|
|||
*Effect->ApplyEdit, Style))
|
||||
Effect->ApplyEdit = std::move(*Formatted);
|
||||
}
|
||||
return CB(std::move(*Effect));
|
||||
|
||||
ResolvedEffect R;
|
||||
R.ShowMessage = std::move(Effect->ShowMessage);
|
||||
if (Effect->ApplyEdit)
|
||||
R.ApplyEdit =
|
||||
replacementsToEdits(InpAST->Inputs.Contents, *Effect->ApplyEdit);
|
||||
return CB(std::move(R));
|
||||
};
|
||||
WorkScheduler.runWithAST(
|
||||
"ApplyTweak", File,
|
||||
|
|
|
@ -57,6 +57,14 @@ public:
|
|||
using ClangTidyOptionsBuilder = std::function<tidy::ClangTidyOptions(
|
||||
llvm::vfs::FileSystem &, llvm::StringRef /*File*/)>;
|
||||
|
||||
/// Like Tweak::Effect, but stores TextEdits instead of tooling::Replacements.
|
||||
/// Slightly nicer to embedders of ClangdServer.
|
||||
/// FIXME: figure out how to remove this duplication.
|
||||
struct ResolvedEffect {
|
||||
llvm::Optional<std::string> ShowMessage;
|
||||
llvm::Optional<std::vector<TextEdit>> ApplyEdit;
|
||||
};
|
||||
|
||||
/// Manages a collection of source files and derived data (ASTs, indexes),
|
||||
/// and provides language-aware features such as code completion.
|
||||
///
|
||||
|
@ -239,7 +247,7 @@ public:
|
|||
|
||||
/// Apply the code tweak with a specified \p ID.
|
||||
void applyTweak(PathRef File, Range Sel, StringRef ID,
|
||||
Callback<Tweak::Effect> CB);
|
||||
Callback<ResolvedEffect> CB);
|
||||
|
||||
/// Only for testing purposes.
|
||||
/// Waits until all requests to worker thread are finished and dumps AST for
|
||||
|
|
Loading…
Reference in New Issue