22 const std::string &FileURI, llvm::StringRef Src,
23 std::vector<lspserver::CodeAction> &Actions) {
28 const auto &Var =
static_cast<const nixf::ExprVar &
>(*VarNode);
31 auto Result = VLA.
query(Var);
36 const nixf::Node *LambdaNode = PM.
upTo(N, nixf::Node::NK_ExprLambda);
43 if (!Lambda.arg() || !Lambda.arg()->formals())
47 const std::string &VarName = Var.id().
name();
50 if (Formals.
dedup().contains(VarName))
64 const auto &Members = Formals.
members();
66 if (Members.empty()) {
70 size_t InsertOffset = BraceOffset + 1;
79 bool HasEllipsis = LastMember && LastMember->
isEllipsis();
82 if (Members.size() == 1) {
93 for (
auto It = Members.rbegin(); It != Members.rend(); ++It) {
94 if ((*It) && !(*It)->isEllipsis()) {
95 LastNonEllipsis = (*It).get();
100 if (!LastNonEllipsis)
117 std::string Title =
"add `" + VarName +
"` to formals";
119 std::vector<lspserver::TextEdit> Edits;
123 using Changes = std::map<std::string, std::vector<lspserver::TextEdit>>;
127 Action.
title = std::move(Title);
130 Action.
edit = std::move(WE);
132 Actions.emplace_back(std::move(Action));
Convert between LSP and nixf types.
Shared utilities for code actions.
Lookup variable names, from it's parent scope.
int64_t column() const
Column number, starting from 0.
std::size_t offset() const
Offset in the source file, starting from 0.
static LexerCursor unsafeCreate(int64_t Line, int64_t Column, std::size_t Offset)
Create a cursor at the given position. (Line, Column, Offset).
int64_t line() const
Line number, starting from 0.
static const char * name(NodeKind Kind)
const Node * upTo(const Node &N, Node::NodeKind Kind) const
Search up until some kind of node is found.
LookupResult query(const ExprVar &Var) const
Query the which name/with binds to specific varaible.
lspserver::Position toLSPPosition(llvm::StringRef Code, const nixf::LexerCursor &P)
void addToFormalsAction(const nixf::Node &N, const nixf::ParentMapAnalysis &PM, const nixf::VariableLookupAnalysis &VLA, const std::string &FileURI, llvm::StringRef Src, std::vector< lspserver::CodeAction > &Actions)
Add code action to add undefined variable to lambda formals.
std::string quoteNixAttrKey(const std::string &Key)
Quote and escape a Nix attribute key if necessary.
std::string title
A short, human-readable, title for this code action.
std::optional< std::string > kind
std::optional< WorkspaceEdit > edit
The workspace edit this code action performs.
static const llvm::StringLiteral QUICKFIX_KIND