11#include <boost/asio/post.hpp>
15using namespace llvm::json;
16using namespace lspserver;
19 Callback<std::vector<CodeAction>> Reply) {
20 using CheckTy = std::vector<CodeAction>;
22 Range Range = Params.
range;
23 auto Action = [Reply = std::move(Reply),
File, Range,
this]()
mutable {
24 return Reply([&]() -> llvm::Expected<CheckTy> {
27 const auto &Diagnostics = TU->diagnostics();
28 auto Actions = std::vector<CodeAction>();
29 Actions.reserve(Diagnostics.size());
30 for (
const nixf::Diagnostic &D : Diagnostics) {
31 auto DRange =
toLSPRange(TU->src(), D.range());
36 for (
const nixf::Fix &F : D.fixes()) {
37 std::vector<TextEdit> Edits;
38 Edits.reserve(F.edits().size());
39 for (
const nixf::TextEdit &TE : F.edits()) {
40 Edits.emplace_back(TextEdit{
42 .newText = std::string(TE.newText()),
45 using Changes = std::map<std::string, std::vector<TextEdit>>;
47 WorkspaceEdit WE{.changes = Changes{
48 {std::move(FileURI), std::move(Edits)},
50 Actions.emplace_back(CodeAction{
53 .edit = std::move(WE),
60 boost::asio::post(Pool, std::move(Action));
#define CheckDefault(x)
Variant of CheckReturn, but returns default constructed CheckTy
Convert between LSP and nixf types.
llvm::unique_function< void(llvm::Expected< T >)> Callback
lspserver::Range toLSPRange(llvm::StringRef Code, const nixf::LexerCursorRange &R)
Range range
The range for which the command was invoked.
TextDocumentIdentifier textDocument
The document in which the command was invoked.
static const llvm::StringLiteral QUICKFIX_KIND
bool overlap(const Range &RHS) const
URIForFile uri
The text document's URI.
static URIForFile canonicalize(llvm::StringRef AbsPath, llvm::StringRef TUPath)
llvm::StringRef file() const
Retrieves absolute path to the file.