nixd
Loading...
Searching...
No Matches
nixd Namespace Reference

Namespaces

namespace  rpcMethod
namespace  rpc
namespace  util
namespace  idioms

Classes

struct  Configuration
class  Controller
class  EvalClient
class  OwnedEvalClient
class  NixTU
 Holds analyzed information about a document. More...
class  AttrSetClient
class  AttrSetClientProc
class  AttrSetProvider
 Main RPC class for attrset provider. More...
class  EvalProvider
struct  PackageDescription
struct  ValueMeta
 General metadata of all nix::Values. More...
struct  ValueDescription
 Using nix's ":doc" method to retrieve value's additional information. More...
struct  AttrPathInfoResponse
struct  AttrPathCompleteParams
struct  OptionType
struct  OptionDescription
struct  OptionField
class  LLVMErrorException
class  JSONParseException
class  JSONSchemaException
struct  StreamProc
struct  CannotFindVarException

Typedefs

using EvalExprParams = std::string
using EvalExprResponse = std::optional<std::string>
using Selector = std::vector<std::string>
 A list of strings that "select"s into a attribute set.
using PackageInfoParams = Selector
using OptionInfoParams = Selector
using AttrPathInfoParams = Selector
using AttrPathCompleteResponse = std::vector<std::string>
using OptionInfoResponse = OptionDescription
using OptionCompleteResponse = std::vector<OptionField>

Enumerations

enum class  FindAttrPathResult { OK , Inherit , NotAttrPath , WithDynamic }

Functions

nixd::Configuration parseCLIConfig ()
 Parse the CLI flag and initialize the config nixd::DefaultConfig.
bool fromJSON (const llvm::json::Value &Params, Configuration::Diagnostic &R, llvm::json::Path P)
bool fromJSON (const llvm::json::Value &Params, Configuration::Formatting &R, llvm::json::Path P)
bool fromJSON (const llvm::json::Value &Params, Configuration::OptionProvider &R, llvm::json::Path P)
bool fromJSON (const llvm::json::Value &Params, Configuration::NixpkgsProvider &R, llvm::json::Path P)
bool fromJSON (const llvm::json::Value &Params, Configuration &R, llvm::json::Path P)
void startAttrSetEval (const std::string &Name, std::unique_ptr< AttrSetClientProc > &Worker)
void startNixpkgs (std::unique_ptr< AttrSetClientProc > &NixpkgsEval)
void startOption (const std::string &Name, std::unique_ptr< AttrSetClientProc > &Worker)
llvm::json::Value toJSON (const PackageDescription &Params)
bool fromJSON (const llvm::json::Value &Params, PackageDescription &R, llvm::json::Path P)
llvm::json::Value toJSON (const ValueMeta &Params)
bool fromJSON (const llvm::json::Value &Params, ValueMeta &R, llvm::json::Path P)
llvm::json::Value toJSON (const ValueDescription &Params)
bool fromJSON (const llvm::json::Value &Params, ValueDescription &R, llvm::json::Path P)
llvm::json::Value toJSON (const AttrPathInfoResponse &Params)
bool fromJSON (const llvm::json::Value &Params, AttrPathInfoResponse &R, llvm::json::Path P)
llvm::json::Value toJSON (const AttrPathCompleteParams &Params)
bool fromJSON (const llvm::json::Value &Params, AttrPathCompleteParams &R, llvm::json::Path P)
llvm::json::Value toJSON (const OptionType &Params)
bool fromJSON (const llvm::json::Value &Params, OptionType &R, llvm::json::Path P)
llvm::json::Value toJSON (const OptionDescription &Params)
bool fromJSON (const llvm::json::Value &Params, OptionDescription &R, llvm::json::Path P)
llvm::json::Value toJSON (const OptionField &Params)
bool fromJSON (const llvm::json::Value &Params, OptionField &R, llvm::json::Path P)
int forkPiped (int &In, int &Out, int &Err)
 fork this process and create some pipes connected to the new process.
llvm::json::Value parse (llvm::StringRef JSON)
template<class T>
fromJSON (const llvm::json::Value &V)
const nixf::EnvNodeupEnv (const nixf::Node &Desc, const nixf::VariableLookupAnalysis &VLA, const nixf::ParentMapAnalysis &PM)
 Search up until there are some node associated with "EnvNode".
bool havePackageScope (const nixf::Node &N, const nixf::VariableLookupAnalysis &VLA, const nixf::ParentMapAnalysis &PM)
 Determine whether or not some node has enclosed "with pkgs; [ ]".
std::pair< std::vector< std::string >, std::string > getScopeAndPrefix (const nixf::Node &N, const nixf::ParentMapAnalysis &PM)
 get variable scope, and it's prefix name.
FindAttrPathResult findAttrPath (const nixf::Node &N, const nixf::ParentMapAnalysis &PM, std::vector< std::string > &Path)
 Heuristically find attrpath suitable for "attrpath" completion.
FindAttrPathResult findAttrPathForOptions (const nixf::Node &N, const nixf::ParentMapAnalysis &PM, std::vector< std::string > &Path)
 Heuristically find attrpath suitable for "attrpath" completion. Strips "config." from the start to support config sections in NixOS modules.
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.
void addAttrNameActions (const nixf::Node &N, const nixf::ParentMapAnalysis &PM, const std::string &FileURI, llvm::StringRef Src, std::vector< lspserver::CodeAction > &Actions)
 Add refactoring code actions for attribute names (quote/unquote).
void addConvertToInheritAction (const nixf::Node &N, const nixf::ParentMapAnalysis &PM, const std::string &FileURI, llvm::StringRef Src, std::vector< lspserver::CodeAction > &Actions)
 Add code action to convert binding to inherit syntax.
void addExtractToFileAction (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 extract-to-file action for selected expressions.
void addFlattenAttrsAction (const nixf::Node &N, const nixf::ParentMapAnalysis &PM, const std::string &FileURI, llvm::StringRef Src, std::vector< lspserver::CodeAction > &Actions)
 Add flatten action for nested attribute sets.
void addInheritToBindingAction (const nixf::Node &N, const nixf::ParentMapAnalysis &PM, const std::string &FileURI, llvm::StringRef Src, std::vector< lspserver::CodeAction > &Actions)
 Add code action to convert inherit to explicit binding.
void addJsonToNixAction (llvm::StringRef Src, const lspserver::Range &Range, const std::string &FileURI, std::vector< lspserver::CodeAction > &Actions)
 Add JSON to Nix conversion action for selected JSON text.
void addNoogleDocAction (const nixf::Node &N, const nixf::ParentMapAnalysis &PM, std::vector< lspserver::CodeAction > &Actions)
 Add a code action to open noogle.dev documentation for lib.* functions.
void addPackAttrsAction (const nixf::Node &N, const nixf::ParentMapAnalysis &PM, const std::string &FileURI, llvm::StringRef Src, std::vector< lspserver::CodeAction > &Actions)
 Add pack action for dotted attribute paths.
void addRewriteStringAction (const nixf::Node &N, const nixf::ParentMapAnalysis &PM, const std::string &FileURI, llvm::StringRef Src, std::vector< lspserver::CodeAction > &Actions)
 Add rewrite action for string literal syntax conversion.
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.
bool isValidNixIdentifier (const std::string &S)
 Check if a string is a valid Nix identifier that can be unquoted.
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.
void addWithToLetAction (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 convert with expression to let/inherit.
lspserver::Position toLSPPosition (llvm::StringRef Code, const nixf::LexerCursor &P)
nixf::Position toNixfPosition (const lspserver::Position &P)
nixf::PositionRange toNixfRange (const lspserver::Range &P)
lspserver::Range toLSPRange (llvm::StringRef Code, const nixf::LexerCursorRange &R)
int getLSPSeverity (nixf::Diagnostic::DiagnosticKind Kind)
llvm::SmallVector< lspserver::DiagnosticTag, 1 > toLSPTags (const std::vector< nixf::DiagnosticTag > &Tags)
const nixf::DefinitionfindDefinition (const nixf::Node &N, const nixf::ParentMapAnalysis &PMA, const nixf::VariableLookupAnalysis &VLA)
 Heuristically find definition on some node.
std::optional< std::string > resolveExprPath (const std::string &BasePath, const std::string &ExprPath)
 Resolve a Nix expression path to a real filesystem path.

Variables

llvm::cl::OptionCategory NixdCategory
llvm::cl::opt< bool > LitTest
 Indicating that we are in lit-test mode.
constexpr size_t MaxJsonDepth = 100
 Maximum recursion depth for JSON to Nix conversion.
constexpr size_t MaxJsonWidth = 10000
 Maximum array/object width for JSON to Nix conversion.

Typedef Documentation

◆ AttrPathCompleteResponse

using nixd::AttrPathCompleteResponse = std::vector<std::string>

Definition at line 117 of file AttrSet.h.

◆ AttrPathInfoParams

Definition at line 48 of file AttrSet.h.

◆ EvalExprParams

using nixd::EvalExprParams = std::string

Definition at line 39 of file AttrSet.h.

◆ EvalExprResponse

using nixd::EvalExprResponse = std::optional<std::string>

Definition at line 40 of file AttrSet.h.

◆ OptionCompleteResponse

Definition at line 151 of file AttrSet.h.

◆ OptionInfoParams

Definition at line 46 of file AttrSet.h.

◆ OptionInfoResponse

Definition at line 149 of file AttrSet.h.

◆ PackageInfoParams

Definition at line 45 of file AttrSet.h.

◆ Selector

using nixd::Selector = std::vector<std::string>

A list of strings that "select"s into a attribute set.

Definition at line 43 of file AttrSet.h.

Enumeration Type Documentation

◆ FindAttrPathResult

enum class nixd::FindAttrPathResult
strong
Enumerator
OK 
Inherit 
NotAttrPath 
WithDynamic 

Definition at line 119 of file AST.h.

Function Documentation

◆ addAttrNameActions()

void nixd::addAttrNameActions ( const nixf::Node & N,
const nixf::ParentMapAnalysis & PM,
const std::string & FileURI,
llvm::StringRef Src,
std::vector< lspserver::CodeAction > & Actions )

◆ addConvertToInheritAction()

void nixd::addConvertToInheritAction ( const nixf::Node & N,
const nixf::ParentMapAnalysis & PM,
const std::string & FileURI,
llvm::StringRef Src,
std::vector< lspserver::CodeAction > & Actions )

Add code action to convert binding to inherit syntax.

This action is offered when the cursor is on a binding that matches one of these patterns:

  • { attrName = attrName; } -> { inherit attrName; }
  • { attrName = source.attrName; } -> { inherit (source) attrName; }

The action is NOT offered when:

  • The binding has a multi-segment path (e.g., x.y = z)
  • The attribute name is dynamic/interpolated
  • The value doesn't match the attribute name
  • The select expression has a default value

Definition at line 15 of file ConvertToInherit.cpp.

References createSingleEditAction(), nixf::Node::lCur(), nixf::AttrPath::names(), nixf::LexerCursor::offset(), nixf::Binding::path(), nixf::ExprSelect::path(), quoteNixAttrKey(), nixf::Node::rCur(), lspserver::CodeAction::REFACTOR_REWRITE_KIND, toLSPRange(), nixf::ParentMapAnalysis::upTo(), and lspserver::Value.

◆ addExtractToFileAction()

void nixd::addExtractToFileAction ( 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 extract-to-file action for selected expressions.

This action is offered when the cursor is on any valid Nix expression. It creates a new file with the expression content and replaces the original expression with an import statement. If the expression contains free variables (variables used but not defined within the expression), they are wrapped in a lambda in the new file.

Example transformation: Original: { buildInputs = [ pkgs.foo pkgs.bar ]; } New file (buildInputs.nix): { pkgs }: [ pkgs.foo pkgs.bar ] Replaced: { buildInputs = import ./buildInputs.nix { inherit pkgs; }; }

Definition at line 322 of file ExtractToFile.cpp.

References lspserver::URIForFile::canonicalize(), lspserver::WorkspaceEdit::documentChanges, lspserver::CodeAction::edit, lspserver::TextDocumentEdit::edits, lspserver::CodeAction::kind, lspserver::CreateFile::options, nixf::Node::range(), lspserver::CodeAction::REFACTOR_KIND, nixf::Node::src(), lspserver::TextDocumentEdit::textDocument, lspserver::CodeAction::title, toLSPRange(), lspserver::CreateFile::uri, lspserver::TextDocumentIdentifier::uri, and lspserver::VersionedTextDocumentIdentifier::version.

◆ addFlattenAttrsAction()

void nixd::addFlattenAttrsAction ( const nixf::Node & N,
const nixf::ParentMapAnalysis & PM,
const std::string & FileURI,
llvm::StringRef Src,
std::vector< lspserver::CodeAction > & Actions )

Add flatten action for nested attribute sets.

This action is offered when the cursor is on a binding whose value is a non-recursive attribute set. It flattens all nested bindings into dotted paths.

Definition at line 44 of file FlattenAttrs.cpp.

References nixf::Binds::bindings(), createSingleEditAction(), nixf::Binding::path(), lspserver::CodeAction::REFACTOR_REWRITE_KIND, nixf::Node::src(), toLSPRange(), and nixf::ParentMapAnalysis::upTo().

◆ addInheritToBindingAction()

void nixd::addInheritToBindingAction ( const nixf::Node & N,
const nixf::ParentMapAnalysis & PM,
const std::string & FileURI,
llvm::StringRef Src,
std::vector< lspserver::CodeAction > & Actions )

Add code action to convert inherit to explicit binding.

This action converts inherit statements to explicit bindings:

  • Simple inherit: { inherit x; } -> { x = x; }
  • Inherit from expression: { inherit (b) a; } -> { a = b.a; }

The action is only offered when the inherit has exactly one name.

Definition at line 15 of file InheritToBinding.cpp.

References createSingleEditAction(), Inherit, nixf::Inherit::names(), lspserver::CodeAction::REFACTOR_REWRITE_KIND, toLSPRange(), and nixf::ParentMapAnalysis::upTo().

◆ addJsonToNixAction()

void nixd::addJsonToNixAction ( llvm::StringRef Src,
const lspserver::Range & Range,
const std::string & FileURI,
std::vector< lspserver::CodeAction > & Actions )

Add JSON to Nix conversion action for selected JSON text.

This is a selection-based action that works on arbitrary text, not AST nodes. It parses the selected text as JSON and converts it to Nix syntax.

Definition at line 97 of file JsonToNix.cpp.

References createSingleEditAction(), lspserver::Range::end, lspserver::positionToOffset(), lspserver::CodeAction::REFACTOR_REWRITE_KIND, and lspserver::Range::start.

◆ addNoogleDocAction()

void nixd::addNoogleDocAction ( const nixf::Node & N,
const nixf::ParentMapAnalysis & PM,
std::vector< lspserver::CodeAction > & Actions )

Add a code action to open noogle.dev documentation for lib.* functions.

This action is offered when the cursor is on an ExprSelect with:

  • Base expression is ExprVar with name "lib"
  • Path contains at least one static attribute name

Examples that trigger:

  • lib.optionalString
  • lib.strings.optionalString
  • lib.attrsets.mapAttrs

Examples that do NOT trigger:

  • lib (just the variable, no selection)
  • lib.${x} (dynamic attribute)
  • pkgs.hello (not lib.*)

Definition at line 30 of file NoogleDoc.cpp.

References lspserver::CodeAction::REFACTOR_KIND, and nixf::ParentMapAnalysis::upTo().

◆ addPackAttrsAction()

void nixd::addPackAttrsAction ( const nixf::Node & N,
const nixf::ParentMapAnalysis & PM,
const std::string & FileURI,
llvm::StringRef Src,
std::vector< lspserver::CodeAction > & Actions )

Add pack action for dotted attribute paths.

This action is offered when the cursor is on a binding with a dotted path (e.g., foo.bar = 1). It offers three variants:

  • Pack One: pack only the current binding
  • Shallow Pack All: pack all siblings sharing the same first segment
  • Recursive Pack All: fully nest all siblings

Definition at line 187 of file PackAttrs.cpp.

References createSingleEditAction(), nixf::ExprAttrs::isRecursive(), nixf::Node::kind(), nixf::AttrPath::names(), nixf::LexerCursor::offset(), nixf::Binding::path(), nixf::ParentMapAnalysis::query(), quoteNixAttrKey(), nixf::Node::range(), nixf::LexerCursorRange::rCur(), lspserver::CodeAction::REFACTOR_REWRITE_KIND, nixf::ExprAttrs::sema(), nixf::Node::src(), nixf::SemaAttrs::staticAttrs(), toLSPRange(), nixf::ParentMapAnalysis::upTo(), nixf::Attribute::value(), and nixf::Binding::value().

◆ addRewriteStringAction()

void nixd::addRewriteStringAction ( const nixf::Node & N,
const nixf::ParentMapAnalysis & PM,
const std::string & FileURI,
llvm::StringRef Src,
std::vector< lspserver::CodeAction > & Actions )

Add rewrite action for string literal syntax conversion.

This action is offered when the cursor is on a string literal. It converts between double-quoted strings ("...") and indented strings (''...''), properly handling escape sequence differences.

Definition at line 106 of file RewriteString.cpp.

References createSingleEditAction(), lspserver::CodeAction::REFACTOR_REWRITE_KIND, toLSPRange(), and nixf::ParentMapAnalysis::upTo().

◆ addToFormalsAction()

void nixd::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.

This action is offered when:

  • The cursor is on an ExprVar (variable reference)
  • The variable is undefined (not found in any scope)
  • The enclosing lambda has a formals parameter list (e.g., {x, y}: body)

The action is NOT offered when:

  • The variable is already defined in any scope
  • There is no enclosing lambda
  • The enclosing lambda uses simple argument style (x: body) instead of formals

Transformation example: {x}: y -> {x, y}: y

Definition at line 20 of file AddToFormals.cpp.

References nixf::LexerCursor::column(), nixf::Formals::dedup(), lspserver::CodeAction::edit, nixf::Formal::isEllipsis(), lspserver::CodeAction::isPreferred, lspserver::CodeAction::kind, nixf::Node::lCur(), nixf::LexerCursor::line(), nixf::Formals::members(), nixf::Node::name(), nixf::LexerCursor::offset(), nixf::VariableLookupAnalysis::query(), lspserver::CodeAction::QUICKFIX_KIND, quoteNixAttrKey(), nixf::Node::rCur(), lspserver::CodeAction::title, toLSPPosition(), nixf::VariableLookupAnalysis::Undefined, nixf::LexerCursor::unsafeCreate(), and nixf::ParentMapAnalysis::upTo().

◆ addWithToLetAction()

void nixd::addWithToLetAction ( 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 convert with expression to let/inherit.

This action is offered when the cursor is on the with keyword. It transforms with source; body into let inherit (source) vars; in body where vars are all variables used from the with scope.

The action is NOT offered when:

  • The cursor is not on the with keyword
  • No variables are used from the with scope (unused with)
  • The with body is directly another with expression (nested with chains)

Definition at line 133 of file WithToLet.cpp.

References createSingleEditAction(), nixf::Node::range(), lspserver::CodeAction::REFACTOR_REWRITE_KIND, toLSPRange(), and nixf::ParentMapAnalysis::upTo().

◆ createSingleEditAction()

lspserver::CodeAction nixd::createSingleEditAction ( const std::string & Title,
llvm::StringLiteral Kind,
const std::string & FileURI,
const lspserver::Range & EditRange,
std::string NewText )

◆ escapeNixString()

std::string nixd::escapeNixString ( llvm::StringRef S)

Escape special characters for Nix double-quoted string literals.

Escapes: " \ ${
\r \t (per Nix Reference Manual)

Definition at line 52 of file Utils.cpp.

Referenced by quoteNixAttrKey().

◆ findAttrPath()

nixd::FindAttrPathResult nixd::findAttrPath ( const nixf::Node & N,
const nixf::ParentMapAnalysis & PM,
std::vector< std::string > & Path )

Heuristically find attrpath suitable for "attrpath" completion.

Parameters
[out]Paththe attrpath.

Definition at line 283 of file AST.cpp.

References nixf::ParentMapAnalysis::upTo().

Referenced by findAttrPathForOptions().

◆ findAttrPathForOptions()

nixd::FindAttrPathResult nixd::findAttrPathForOptions ( const nixf::Node & N,
const nixf::ParentMapAnalysis & PM,
std::vector< std::string > & Path )

Heuristically find attrpath suitable for "attrpath" completion. Strips "config." from the start to support config sections in NixOS modules.

Parameters
[out]Paththe attrpath.

Definition at line 320 of file AST.cpp.

References findAttrPath(), and OK.

◆ findDefinition()

const Definition & nixd::findDefinition ( const nixf::Node & N,
const nixf::ParentMapAnalysis & PMA,
const nixf::VariableLookupAnalysis & VLA )

Heuristically find definition on some node.

Definition at line 366 of file Definition.cpp.

References nixf::Node::kind().

◆ forkPiped()

int nixd::forkPiped ( int & In,
int & Out,
int & Err )

fork this process and create some pipes connected to the new process.

stdin, stdout, stderr in the new process will be closed, and these fds could be used to communicate with it.

Returns
pid of child process, in parent.
0 in child.

Definition at line 8 of file ForkPiped.cpp.

Referenced by nixd::StreamProc::StreamProc().

◆ fromJSON() [1/14]

bool nixd::fromJSON ( const llvm::json::Value & Params,
AttrPathCompleteParams & R,
llvm::json::Path P )

◆ fromJSON() [2/14]

bool nixd::fromJSON ( const llvm::json::Value & Params,
AttrPathInfoResponse & R,
llvm::json::Path P )

◆ fromJSON() [3/14]

bool nixd::fromJSON ( const llvm::json::Value & Params,
Configuration & R,
llvm::json::Path P )

◆ fromJSON() [4/14]

bool nixd::fromJSON ( const llvm::json::Value & Params,
Configuration::Diagnostic & R,
llvm::json::Path P )

Referenced by fromJSON(), and parseCLIConfig().

◆ fromJSON() [5/14]

bool nixd::fromJSON ( const llvm::json::Value & Params,
Configuration::Formatting & R,
llvm::json::Path P )

◆ fromJSON() [6/14]

bool nixd::fromJSON ( const llvm::json::Value & Params,
Configuration::NixpkgsProvider & R,
llvm::json::Path P )

◆ fromJSON() [7/14]

bool nixd::fromJSON ( const llvm::json::Value & Params,
Configuration::OptionProvider & R,
llvm::json::Path P )

◆ fromJSON() [8/14]

bool nixd::fromJSON ( const llvm::json::Value & Params,
OptionDescription & R,
llvm::json::Path P )

◆ fromJSON() [9/14]

bool nixd::fromJSON ( const llvm::json::Value & Params,
OptionField & R,
llvm::json::Path P )

◆ fromJSON() [10/14]

bool nixd::fromJSON ( const llvm::json::Value & Params,
OptionType & R,
llvm::json::Path P )

◆ fromJSON() [11/14]

◆ fromJSON() [12/14]

bool nixd::fromJSON ( const llvm::json::Value & Params,
ValueDescription & R,
llvm::json::Path P )

◆ fromJSON() [13/14]

bool nixd::fromJSON ( const llvm::json::Value & Params,
ValueMeta & R,
llvm::json::Path P )

Definition at line 87 of file AttrSet.cpp.

References nixd::ValueMeta::Location, and nixd::ValueMeta::Type.

◆ fromJSON() [14/14]

template<class T>
T nixd::fromJSON ( const llvm::json::Value & V)

Definition at line 32 of file JSON.h.

References fromJSON().

◆ getLSPSeverity()

int nixd::getLSPSeverity ( nixf::Diagnostic::DiagnosticKind Kind)

◆ getScopeAndPrefix()

std::pair< std::vector< std::string >, std::string > nixd::getScopeAndPrefix ( const nixf::Node & N,
const nixf::ParentMapAnalysis & PM )

get variable scope, and it's prefix name.

Nixpkgs has some packages scoped in "nested" attrs. e.g. llvmPackages, pythonPackages. Try to find these name as a pre-selected scope, the last value is "prefix".

Definition at line 274 of file AST.cpp.

References nixf::Node::kind().

◆ havePackageScope()

bool nixd::havePackageScope ( const nixf::Node & N,
const nixf::VariableLookupAnalysis & VLA,
const nixf::ParentMapAnalysis & PM )
nodiscard

Determine whether or not some node has enclosed "with pkgs; [ ]".

Yes, this evaluation isn't flawless. What if the identifier isn't "pkgs"? We can't dynamically evaluate everything each time and invalidate them immediately after document updates. Therefore, this heuristic method represents a trade-off between performance considerations.

Definition at line 108 of file AST.cpp.

References nixf::ExprVar::id(), nixf::EnvNode::isWith(), nixf::Node::kind(), nixf::Identifier::name(), nixf::EnvNode::parent(), nixf::EnvNode::syntax(), upEnv(), and nixf::ExprWith::with().

◆ isValidNixIdentifier()

bool nixd::isValidNixIdentifier ( const std::string & S)

Check if a string is a valid Nix identifier that can be unquoted.

Valid identifiers: start with letter or underscore, contain letters, digits, underscores, hyphens, or single quotes. Must not be a keyword.

Definition at line 27 of file Utils.cpp.

Referenced by addAttrNameActions(), and quoteNixAttrKey().

◆ parse()

llvm::json::Value nixd::parse ( llvm::StringRef JSON)

Definition at line 5 of file JSON.cpp.

Referenced by parseCLIConfig().

◆ parseCLIConfig()

Configuration nixd::parseCLIConfig ( )

Parse the CLI flag and initialize the config nixd::DefaultConfig.

Definition at line 25 of file CommandLine/Configuration.cpp.

References fromJSON(), and parse().

◆ quoteNixAttrKey()

std::string nixd::quoteNixAttrKey ( const std::string & Key)

Quote and escape a Nix attribute key if necessary.

Returns the key as-is if it's a valid identifier, otherwise quotes and escapes special characters using escapeNixString().

Definition at line 89 of file Utils.cpp.

References escapeNixString(), and isValidNixIdentifier().

Referenced by addConvertToInheritAction(), addPackAttrsAction(), and addToFormalsAction().

◆ resolveExprPath()

std::optional< std::string > nixd::resolveExprPath ( const std::string & BasePath,
const std::string & ExprPath )
inline

Resolve a Nix expression path to a real filesystem path.

This function resolves relative paths against the base file's directory, handles directory → default.nix conversion, and validates the result.

Used by both DocumentLink (for clickable links) and Definition (for go-to-definition on path literals).

Parameters
BasePathThe path of the file containing the path literal.
ExprPathThe path literal string from the Nix expression.
Returns
The resolved absolute path, or nullopt if resolution fails.

Definition at line 28 of file PathResolve.h.

References lspserver::elog(), and lspserver::vlog().

◆ startAttrSetEval()

void nixd::startAttrSetEval ( const std::string & Name,
std::unique_ptr< AttrSetClientProc > & Worker )

Definition at line 24 of file Launch.cpp.

References nixd::AttrSetClient::getExe().

Referenced by startNixpkgs(), and startOption().

◆ startNixpkgs()

void nixd::startNixpkgs ( std::unique_ptr< AttrSetClientProc > & NixpkgsEval)

Definition at line 32 of file Launch.cpp.

References startAttrSetEval().

◆ startOption()

void nixd::startOption ( const std::string & Name,
std::unique_ptr< AttrSetClientProc > & Worker )

Definition at line 36 of file Launch.cpp.

References NULL_DEVICE, and startAttrSetEval().

◆ toJSON() [1/8]

Value nixd::toJSON ( const AttrPathCompleteParams & Params)

◆ toJSON() [2/8]

◆ toJSON() [3/8]

◆ toJSON() [4/8]

Value nixd::toJSON ( const OptionField & Params)

◆ toJSON() [5/8]

Value nixd::toJSON ( const OptionType & Params)

◆ toJSON() [6/8]

◆ toJSON() [7/8]

llvm::json::Value nixd::toJSON ( const ValueDescription & Params)

◆ toJSON() [8/8]

Value nixd::toJSON ( const ValueMeta & Params)

Definition at line 80 of file AttrSet.cpp.

References nixd::ValueMeta::Location, lspserver::Object, and nixd::ValueMeta::Type.

◆ toLSPPosition()

lspserver::Position nixd::toLSPPosition ( llvm::StringRef Code,
const nixf::LexerCursor & P )

Definition at line 27 of file Convert.cpp.

References nixf::LexerCursor::offset(), and lspserver::offsetToPosition().

Referenced by addToFormalsAction(), and toLSPRange().

◆ toLSPRange()

◆ toLSPTags()

llvm::SmallVector< lspserver::DiagnosticTag, 1 > nixd::toLSPTags ( const std::vector< nixf::DiagnosticTag > & Tags)

Definition at line 47 of file Convert.cpp.

References lspserver::Deprecated, nixf::Faded, nixf::Striked, and lspserver::Unnecessary.

◆ toNixfPosition()

nixf::Position nixd::toNixfPosition ( const lspserver::Position & P)

Definition at line 32 of file Convert.cpp.

References lspserver::Position::character, and lspserver::Position::line.

Referenced by toNixfRange().

◆ toNixfRange()

nixf::PositionRange nixd::toNixfRange ( const lspserver::Range & P)

Definition at line 36 of file Convert.cpp.

References lspserver::Range::end, lspserver::Range::start, and toNixfPosition().

◆ upEnv()

const EnvNode * nixd::upEnv ( const nixf::Node & Desc,
const nixf::VariableLookupAnalysis & VLA,
const nixf::ParentMapAnalysis & PM )
nodiscard

Search up until there are some node associated with "EnvNode".

Definition at line 98 of file AST.cpp.

References nixf::VariableLookupAnalysis::env(), nixf::ParentMapAnalysis::isRoot(), and nixf::ParentMapAnalysis::query().

Referenced by havePackageScope().

Variable Documentation

◆ LitTest

opt< bool > nixd::LitTest
extern
Initial value:
{
"lit-test", desc("Indicating that the server is running in lit-test mode."),
init(false), cat(NixdCategory)}
llvm::cl::OptionCategory NixdCategory

Indicating that we are in lit-test mode.

Definition at line 8 of file Options.cpp.

Referenced by main(), and main().

◆ MaxJsonDepth

size_t nixd::MaxJsonDepth = 100
constexpr

Maximum recursion depth for JSON to Nix conversion.

Definition at line 44 of file Utils.h.

◆ MaxJsonWidth

size_t nixd::MaxJsonWidth = 10000
constexpr

Maximum array/object width for JSON to Nix conversion.

Definition at line 47 of file Utils.h.

◆ NixdCategory

OptionCategory nixd::NixdCategory
extern