diff --git a/clang-tools-extra/clangd/Protocol.h b/clang-tools-extra/clangd/Protocol.h --- a/clang-tools-extra/clangd/Protocol.h +++ b/clang-tools-extra/clangd/Protocol.h @@ -1007,6 +1007,12 @@ llvm::Optional kind; const static llvm::StringLiteral QUICKFIX_KIND; const static llvm::StringLiteral REFACTOR_KIND; + const static llvm::StringLiteral REFACTOR_EXTRACT_KIND; + const static llvm::StringLiteral REFACTOR_INLINE_KIND; + const static llvm::StringLiteral REFACTOR_MOVE_KIND; + const static llvm::StringLiteral REFACTOR_REWRITE_KIND; + const static llvm::StringLiteral SOURCE_KIND; + const static llvm::StringLiteral SOURCE_ORGANIZE_IMPORTS_KIND; const static llvm::StringLiteral INFO_KIND; /// The diagnostics that this code action resolves. diff --git a/clang-tools-extra/clangd/Protocol.cpp b/clang-tools-extra/clangd/Protocol.cpp --- a/clang-tools-extra/clangd/Protocol.cpp +++ b/clang-tools-extra/clangd/Protocol.cpp @@ -799,6 +799,12 @@ const llvm::StringLiteral CodeAction::QUICKFIX_KIND = "quickfix"; const llvm::StringLiteral CodeAction::REFACTOR_KIND = "refactor"; +const llvm::StringLiteral CodeAction::REFACTOR_EXTRACT_KIND = "refactor.extract"; +const llvm::StringLiteral CodeAction::REFACTOR_INLINE_KIND = "refactor.inline"; +const llvm::StringLiteral CodeAction::REFACTOR_MOVE_KIND = "refactor.move"; +const llvm::StringLiteral CodeAction::REFACTOR_REWRITE_KIND = "refactor.rewrite"; +const llvm::StringLiteral CodeAction::SOURCE_KIND = "source"; +const llvm::StringLiteral CodeAction::SOURCE_ORGANIZE_IMPORTS_KIND = "source.organizeImports"; const llvm::StringLiteral CodeAction::INFO_KIND = "info"; llvm::json::Value toJSON(const CodeAction &CA) { diff --git a/clang-tools-extra/clangd/refactor/InsertionPoint.h b/clang-tools-extra/clangd/refactor/InsertionPoint.h --- a/clang-tools-extra/clangd/refactor/InsertionPoint.h +++ b/clang-tools-extra/clangd/refactor/InsertionPoint.h @@ -6,6 +6,9 @@ // //===----------------------------------------------------------------------===// +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_REFACTOR_INSERTIONPOINT_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_REFACTOR_INSERTIONPOINT_H + #include "clang/AST/DeclCXX.h" #include "clang/Basic/Specifiers.h" #include "clang/Tooling/Core/Replacement.h" @@ -51,3 +54,5 @@ } // namespace clangd } // namespace clang + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_REFACTOR_INSERTIONPOINT_H diff --git a/clang-tools-extra/clangd/refactor/Tweak.h b/clang-tools-extra/clangd/refactor/Tweak.h --- a/clang-tools-extra/clangd/refactor/Tweak.h +++ b/clang-tools-extra/clangd/refactor/Tweak.h @@ -37,7 +37,7 @@ /// An interface base for small context-sensitive refactoring actions. /// To implement a new tweak use the following pattern in a .cpp file: -/// class MyTweak : public Tweak { +/// class MyTweak final : public Tweak { /// public: /// const char* id() const override final; // defined by REGISTER_TWEAK. /// // implement other methods here. diff --git a/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp b/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp @@ -30,7 +30,7 @@ // Currently this only removes qualifier from under the cursor. In the future, // we should improve this to remove qualifier from all occurrences of this // symbol. -class AddUsing : public Tweak { +class AddUsing final : public Tweak { public: const char *id() const override; @@ -38,7 +38,7 @@ Expected apply(const Selection &Inputs) override; std::string title() const override; llvm::StringLiteral kind() const override { - return CodeAction::REFACTOR_KIND; + return CodeAction::REFACTOR_REWRITE_KIND; } private: diff --git a/clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp b/clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp @@ -21,7 +21,7 @@ /// ^^^^^^^^^^^^^^^^^^^^^ /// After: /// void /* entity.name.function.cpp */ f() { int /* variable.cpp */ abc; } -class AnnotateHighlightings : public Tweak { +class AnnotateHighlightings final : public Tweak { public: const char *id() const final; @@ -29,9 +29,7 @@ Expected apply(const Selection &Inputs) override; std::string title() const override { return "Annotate highlighting tokens"; } - llvm::StringLiteral kind() const override { - return CodeAction::REFACTOR_KIND; - } + llvm::StringLiteral kind() const override { return CodeAction::INFO_KIND; } bool hidden() const override { return true; } }; REGISTER_TWEAK(AnnotateHighlightings) diff --git a/clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp b/clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp @@ -383,12 +383,12 @@ /// /// a.cc: /// -class DefineInline : public Tweak { +class DefineInline final : public Tweak { public: const char *id() const final; llvm::StringLiteral kind() const override { - return CodeAction::REFACTOR_KIND; + return CodeAction::REFACTOR_MOVE_KIND; } std::string title() const override { return "Move function body to declaration"; diff --git a/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp b/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp @@ -360,13 +360,13 @@ /// a.cc /// #include "a.h" /// void foo() { return; } -class DefineOutline : public Tweak { +class DefineOutline final : public Tweak { public: const char *id() const override; bool hidden() const override { return false; } llvm::StringLiteral kind() const override { - return CodeAction::REFACTOR_KIND; + return CodeAction::REFACTOR_MOVE_KIND; } std::string title() const override { return "Move function body to out-of-line"; diff --git a/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp b/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp @@ -29,7 +29,7 @@ /// CallExpr /// |-DeclRefExpr fcall /// `-StringLiteral "foo" -class DumpAST : public Tweak { +class DumpAST final : public Tweak { public: const char *id() const final; @@ -82,7 +82,7 @@ /// .DeclRefExpr fcall /// BinaryOperator 2 + 2 /// *IntegerLiteral 2 -class ShowSelectionTree : public Tweak { +class ShowSelectionTree final : public Tweak { public: const char *id() const final; @@ -103,7 +103,7 @@ /// Message: /// foo - /// {"containerName":null,"id":"CA2EBE44A1D76D2A","name":"foo","usr":"c:@F@foo#"} -class DumpSymbol : public Tweak { +class DumpSymbol final : public Tweak { const char *id() const final; bool prepare(const Selection &Inputs) override { return true; } Expected apply(const Selection &Inputs) override { @@ -131,7 +131,7 @@ /// 0 | int foo /// | [sizeof=4, dsize=4, align=4, /// | nvsize=4, nvalign=4] -class DumpRecordLayout : public Tweak { +class DumpRecordLayout final : public Tweak { public: const char *id() const final; diff --git a/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp b/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp @@ -31,11 +31,11 @@ /// MyClass x = Something(); /// ^^^^^^^ /// FIXME: Handle decltype as well -class ExpandAutoType : public Tweak { +class ExpandAutoType final : public Tweak { public: const char *id() const final; llvm::StringLiteral kind() const override { - return CodeAction::REFACTOR_KIND; + return CodeAction::REFACTOR_REWRITE_KIND; } bool prepare(const Selection &Inputs) override; Expected apply(const Selection &Inputs) override; diff --git a/clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp b/clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp @@ -28,11 +28,11 @@ /// After: /// #define FOO(X) X+X /// 10*a+10*a -class ExpandMacro : public Tweak { +class ExpandMacro final : public Tweak { public: const char *id() const final; llvm::StringLiteral kind() const override { - return CodeAction::REFACTOR_KIND; + return CodeAction::REFACTOR_REWRITE_KIND; } bool prepare(const Selection &Inputs) override; diff --git a/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp b/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp @@ -803,14 +803,14 @@ return ExtractedFunc; } -class ExtractFunction : public Tweak { +class ExtractFunction final : public Tweak { public: const char *id() const final; bool prepare(const Selection &Inputs) override; Expected apply(const Selection &Inputs) override; std::string title() const override { return "Extract to function"; } llvm::StringLiteral kind() const override { - return CodeAction::REFACTOR_KIND; + return CodeAction::REFACTOR_EXTRACT_KIND; } private: diff --git a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp @@ -483,7 +483,7 @@ /// After: /// auto placeholder = 5 + 4; /// int x = placeholder * 3; -class ExtractVariable : public Tweak { +class ExtractVariable final : public Tweak { public: const char *id() const final; bool prepare(const Selection &Inputs) override; @@ -492,7 +492,7 @@ return "Extract subexpression to variable"; } llvm::StringLiteral kind() const override { - return CodeAction::REFACTOR_KIND; + return CodeAction::REFACTOR_EXTRACT_KIND; } private: diff --git a/clang-tools-extra/clangd/refactor/tweaks/MemberwiseConstructor.cpp b/clang-tools-extra/clangd/refactor/tweaks/MemberwiseConstructor.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/MemberwiseConstructor.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/MemberwiseConstructor.cpp @@ -30,11 +30,11 @@ // S(int x, unique_ptr y) : x(x), y(std::move(y)) {} // // We place the constructor inline, other tweaks are available to outline it. -class MemberwiseConstructor : public Tweak { +class MemberwiseConstructor final : public Tweak { public: const char *id() const final; llvm::StringLiteral kind() const override { - return CodeAction::REFACTOR_KIND; + return CodeAction::REFACTOR_REWRITE_KIND; } std::string title() const override { return llvm::formatv("Define constructor"); diff --git a/clang-tools-extra/clangd/refactor/tweaks/ObjCLocalizeStringLiteral.cpp b/clang-tools-extra/clangd/refactor/tweaks/ObjCLocalizeStringLiteral.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/ObjCLocalizeStringLiteral.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/ObjCLocalizeStringLiteral.cpp @@ -28,11 +28,11 @@ /// ^^^ /// After: /// NSLocalizedString(@"description", @"") -class ObjCLocalizeStringLiteral : public Tweak { +class ObjCLocalizeStringLiteral final : public Tweak { public: const char *id() const final; llvm::StringLiteral kind() const override { - return CodeAction::REFACTOR_KIND; + return CodeAction::REFACTOR_REWRITE_KIND; } bool prepare(const Selection &Inputs) override; diff --git a/clang-tools-extra/clangd/refactor/tweaks/ObjCMemberwiseInitializer.cpp b/clang-tools-extra/clangd/refactor/tweaks/ObjCMemberwiseInitializer.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/ObjCMemberwiseInitializer.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/ObjCMemberwiseInitializer.cpp @@ -170,11 +170,11 @@ /// Generate an initializer for an Objective-C class based on selected /// properties and instance variables. -class ObjCMemberwiseInitializer : public Tweak { +class ObjCMemberwiseInitializer final : public Tweak { public: const char *id() const final; llvm::StringLiteral kind() const override { - return CodeAction::REFACTOR_KIND; + return CodeAction::REFACTOR_REWRITE_KIND; } bool prepare(const Selection &Inputs) override; diff --git a/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp b/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp @@ -47,7 +47,7 @@ namespace clang { namespace clangd { namespace { -class PopulateSwitch : public Tweak { +class PopulateSwitch final : public Tweak { const char *id() const override; bool prepare(const Selection &Sel) override; Expected apply(const Selection &Sel) override; diff --git a/clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp b/clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp @@ -26,7 +26,7 @@ /// After: /// printf(R"("a" /// b)"); -class RawStringLiteral : public Tweak { +class RawStringLiteral final : public Tweak { public: const char *id() const final; @@ -34,7 +34,7 @@ Expected apply(const Selection &Inputs) override; std::string title() const override { return "Convert to raw string"; } llvm::StringLiteral kind() const override { - return CodeAction::REFACTOR_KIND; + return CodeAction::REFACTOR_REWRITE_KIND; } private: diff --git a/clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp b/clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp @@ -29,7 +29,7 @@ /// Currently limited to using namespace directives inside global namespace to /// simplify implementation. Also the namespace must not contain using /// directives. -class RemoveUsingNamespace : public Tweak { +class RemoveUsingNamespace final : public Tweak { public: const char *id() const override; @@ -39,7 +39,7 @@ return "Remove using namespace, re-qualify names instead"; } llvm::StringLiteral kind() const override { - return CodeAction::REFACTOR_KIND; + return CodeAction::REFACTOR_REWRITE_KIND; } private: diff --git a/clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp b/clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp @@ -84,11 +84,11 @@ // - to understand the implicit behavior // - to avoid relying on the implicit behavior // - as a baseline for explicit modification -class DeclareCopyMove : public Tweak { +class DeclareCopyMove final : public Tweak { public: const char *id() const final; llvm::StringLiteral kind() const override { - return CodeAction::REFACTOR_KIND; + return CodeAction::REFACTOR_REWRITE_KIND; } std::string title() const override { return llvm::formatv("Declare implicit {0} members", diff --git a/clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp b/clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp @@ -29,7 +29,7 @@ /// ^^^^^^^ ^^^^ /// After: /// if (foo) { continue; } else { return 10; } -class SwapIfBranches : public Tweak { +class SwapIfBranches final : public Tweak { public: const char *id() const final; @@ -37,7 +37,7 @@ Expected apply(const Selection &Inputs) override; std::string title() const override { return "Swap if branches"; } llvm::StringLiteral kind() const override { - return CodeAction::REFACTOR_KIND; + return CodeAction::REFACTOR_REWRITE_KIND; } bool hidden() const override { return true; }