clang-tools 24.0.0git
FeatureModuleExample.cpp
Go to the documentation of this file.
1//===--- FeatureModuleExample.cpp - Example dynamic FeatureModule ---------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "FeatureModule.h"
10#include "refactor/Tweak.h"
11
12namespace clang::clangd {
13namespace {
14
15/// An example tweak contributed by the dynamic feature module.
16class ExampleModuleTweak final : public Tweak {
17public:
18 const char *id() const override { return "ExampleModuleTweak"; }
19 bool prepare(const Selection &) override { return true; }
20 Expected<Effect> apply(const Selection &) override {
21 return Effect::showMessage("Example module tweak executed");
22 }
23 std::string title() const override { return "Execute example module action"; }
24 llvm::StringLiteral kind() const override {
25 return llvm::StringLiteral("quickfix");
26 }
27};
28
29/// An example FeatureModule loaded dynamically into clangd.
30class ExampleFeatureModule final : public FeatureModule {
31public:
32 void contributeTweaks(std::vector<std::unique_ptr<Tweak>> &Out) override {
33 Out.emplace_back(new ExampleModuleTweak);
34 }
35};
36
37static FeatureModuleRegistry::Add<ExampleFeatureModule>
38 X("example-feature-module", "Example clangd feature module");
39
40} // namespace
41} // namespace clang::clangd
A FeatureModule contributes a vertical feature to clangd.
An interface base for small context-sensitive refactoring actions.
Definition Tweak.h:46
FIXME: Skip testing on windows temporarily due to the different escaping code mode.
Definition AST.cpp:44
static URISchemeRegistry::Add< TestScheme > X(TestScheme::Scheme, "Test schema")