nixd
Toggle main menu visibility
Loading...
Searching...
No Matches
nixd
lib
Controller
CodeActions
Utils.h
Go to the documentation of this file.
1
/// \file
2
/// \brief Shared utilities for code actions.
3
///
4
/// This header provides common functions used across multiple code action
5
/// implementations, including text manipulation, Nix identifier validation,
6
/// and CodeAction construction helpers.
7
8
#pragma once
9
10
#include <
lspserver/Protocol.h
>
11
12
#include <llvm/ADT/StringRef.h>
13
14
#include <string>
15
#include <vector>
16
17
namespace
nixd
{
18
19
/// \brief Create a CodeAction with a single text edit.
20
lspserver::CodeAction
createSingleEditAction
(
const
std::string &Title,
21
llvm::StringLiteral Kind,
22
const
std::string &FileURI,
23
const
lspserver::Range
&EditRange,
24
std::string NewText);
25
26
/// \brief Create a CodeAction with multiple text edits applied as one.
27
///
28
/// Per LSP, all edits in a single WorkspaceEdit are applied against the
29
/// pre-edit document state, so callers must ensure ranges do not overlap.
30
lspserver::CodeAction
31
createMultiEditAction
(
const
std::string &Title, llvm::StringLiteral Kind,
32
const
std::string &FileURI,
33
std::vector<lspserver::TextEdit> Edits);
34
35
/// \brief Check if a string is a valid Nix identifier that can be unquoted.
36
///
37
/// Valid identifiers: start with letter or underscore, contain letters,
38
/// digits, underscores, hyphens, or single quotes. Must not be a keyword.
39
bool
isValidNixIdentifier
(
const
std::string &S);
40
41
/// \brief Escape special characters for Nix double-quoted string literals.
42
///
43
/// Escapes: " \ ${ \n \r \t (per Nix Reference Manual)
44
std::string
escapeNixString
(llvm::StringRef S);
45
46
/// \brief Quote and escape a Nix attribute key if necessary.
47
///
48
/// Returns the key as-is if it's a valid identifier, otherwise quotes and
49
/// escapes special characters using escapeNixString().
50
std::string
quoteNixAttrKey
(
const
std::string &
Key
);
51
52
/// \brief Maximum recursion depth for JSON to Nix conversion.
53
constexpr
size_t
MaxJsonDepth
= 100;
54
55
/// \brief Maximum array/object width for JSON to Nix conversion.
56
constexpr
size_t
MaxJsonWidth
= 10000;
57
58
}
// namespace nixd
lspserver::Key
Definition
SourceCode.h:24
Protocol.h
nixd
Definition
CommandLine/Configuration.h:9
nixd::MaxJsonDepth
constexpr size_t MaxJsonDepth
Maximum recursion depth for JSON to Nix conversion.
Definition
Utils.h:53
nixd::MaxJsonWidth
constexpr size_t MaxJsonWidth
Maximum array/object width for JSON to Nix conversion.
Definition
Utils.h:56
nixd::isValidNixIdentifier
bool isValidNixIdentifier(const std::string &S)
Check if a string is a valid Nix identifier that can be unquoted.
Definition
Utils.cpp:40
nixd::createSingleEditAction
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.
Definition
Utils.cpp:10
nixd::createMultiEditAction
lspserver::CodeAction createMultiEditAction(const std::string &Title, llvm::StringLiteral Kind, const std::string &FileURI, std::vector< lspserver::TextEdit > Edits)
Create a CodeAction with multiple text edits applied as one.
Definition
Utils.cpp:28
nixd::escapeNixString
std::string escapeNixString(llvm::StringRef S)
Escape special characters for Nix double-quoted string literals.
Definition
Utils.cpp:65
nixd::quoteNixAttrKey
std::string quoteNixAttrKey(const std::string &Key)
Quote and escape a Nix attribute key if necessary.
Definition
Utils.cpp:102
lspserver::CodeAction
Definition
lspserver/include/lspserver/Protocol.h:1122
lspserver::Range
Definition
lspserver/include/lspserver/Protocol.h:158
Generated by
1.17.0