diff options
| author | Sam McCall <sam.mccall@gmail.com> | 2019-02-01 05:41:50 +0000 |
|---|---|---|
| committer | Sam McCall <sam.mccall@gmail.com> | 2019-02-01 05:41:50 +0000 |
| commit | 8a32f3b7a0f67bedbeb8df9e1bfdbb2aa846adaf (patch) | |
| tree | 8401d5227f694f257339560a2af67ea0c7133032 /clang-tools-extra/clangd/refactor/Tweak.h | |
| parent | c6931ddc3d62cd32bd8e25573a51758586642ea1 (diff) | |
| download | bcm5719-llvm-8a32f3b7a0f67bedbeb8df9e1bfdbb2aa846adaf.tar.gz bcm5719-llvm-8a32f3b7a0f67bedbeb8df9e1bfdbb2aa846adaf.zip | |
[clangd] Fix crash in applyTweak, remove TweakID alias.
Strings are complicated, giving them opaque names makes us forget
they're complicated.
llvm-svn: 352837
Diffstat (limited to 'clang-tools-extra/clangd/refactor/Tweak.h')
| -rw-r--r-- | clang-tools-extra/clangd/refactor/Tweak.h | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/clang-tools-extra/clangd/refactor/Tweak.h b/clang-tools-extra/clangd/refactor/Tweak.h index df00bf7fede..abd4995e4dd 100644 --- a/clang-tools-extra/clangd/refactor/Tweak.h +++ b/clang-tools-extra/clangd/refactor/Tweak.h @@ -27,14 +27,11 @@ namespace clang { namespace clangd { -using TweakID = llvm::StringRef; - /// 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 { /// public: -/// TweakID id() const override final; // definition provided by -/// // REGISTER_TWEAK. +/// const char* id() const override final; // defined by REGISTER_TWEAK. /// // implement other methods here. /// }; /// REGISTER_TWEAK(MyTweak); @@ -57,7 +54,7 @@ public: /// A unique id of the action, it is always equal to the name of the class /// defining the Tweak. Definition is provided automatically by /// REGISTER_TWEAK. - virtual TweakID id() const = 0; + virtual const char *id() const = 0; /// Run the first stage of the action. The non-None result indicates that the /// action is available and should be shown to the user. Returns None if the /// action is not available. @@ -78,9 +75,7 @@ public: #define REGISTER_TWEAK(Subclass) \ ::llvm::Registry<::clang::clangd::Tweak>::Add<Subclass> \ TweakRegistrationFor##Subclass(#Subclass, /*Description=*/""); \ - ::clang::clangd::TweakID Subclass::id() const { \ - return llvm::StringLiteral(#Subclass); \ - } + const char *Subclass::id() const { return #Subclass; } /// Calls prepare() on all tweaks, returning those that can run on the /// selection. @@ -89,7 +84,7 @@ std::vector<std::unique_ptr<Tweak>> prepareTweaks(const Tweak::Selection &S); // Calls prepare() on the tweak with a given ID. // If prepare() returns false, returns an error. // If prepare() returns true, returns the corresponding tweak. -llvm::Expected<std::unique_ptr<Tweak>> prepareTweak(TweakID ID, +llvm::Expected<std::unique_ptr<Tweak>> prepareTweak(StringRef TweakID, const Tweak::Selection &S); } // namespace clangd |

