11 llvm::StringLiteral Kind,
12 const std::string &FileURI,
14 std::string NewText) {
15 std::vector<lspserver::TextEdit> Edits;
18 using Changes = std::map<std::string, std::vector<lspserver::TextEdit>>;
22 .kind = std::string(Kind),
23 .edit = std::move(WE),
33 if (!((First >=
'a' && First <=
'z') || (First >=
'A' && First <=
'Z') ||
38 for (
size_t I = 1; I < S.size(); ++I) {
40 if (!((C >=
'a' && C <=
'z') || (C >=
'A' && C <=
'Z') ||
41 (C >=
'0' && C <=
'9') || C ==
'_' || C ==
'-' || C ==
'\''))
46 static const std::set<std::string> Keywords = {
47 "if",
"then",
"else",
"assert",
"with",
"let",
"in",
48 "rec",
"inherit",
"or",
"true",
"false",
"null"};
49 return Keywords.find(S) == Keywords.end();
54 Result.reserve(S.size() + S.size() / 4 + 2);
55 for (
size_t I = 0; I < S.size(); ++I) {
75 if (I + 1 < S.size() && S[I + 1] ==
'{') {
Shared utilities for code actions.
bool isValidNixIdentifier(const std::string &S)
Check if a string is a valid Nix identifier that can be unquoted.
lspserver::CodeAction createSingleEditAction(const std::string &Title, llvm::StringLiteral Kind, const std::string &FileURI, const lspserver::Range &EditRange, std::string NewText)
Create a CodeAction with a single text edit.
std::string escapeNixString(llvm::StringRef S)
Escape special characters for Nix double-quoted string literals.
std::string quoteNixAttrKey(const std::string &Key)
Quote and escape a Nix attribute key if necessary.