### Complete nixd Configuration Example Source: https://github.com/nix-community/nixd/blob/main/nixd/docs/configuration.md This is a comprehensive example of a nixd configuration file, demonstrating settings for nixpkgs, formatting, options (NixOS, Home Manager), and diagnostics. ```jsonc { "nixpkgs": { // For flake. // "expr": "import (builtins.getFlake \"/home/lyc/workspace/CS/OS/NixOS/flakes\").inputs.nixpkgs { } " // This expression will be interpreted as "nixpkgs" toplevel // Nixd provides package, lib completion/information from it. /// // Resource Usage: Entries are lazily evaluated, entire nixpkgs takes 200~300MB for just "names". /// Package documentation, versions, are evaluated by-need. "expr": "import { }" }, "formatting": { // Which command you would like to do formatting "command": [ "nixfmt" ] }, // Tell the language server your desired option set, for completion // This is lazily evaluated. "options": { // Map of eval information // By default, this entriy will be read from `import { }` // You can write arbitary nix expression here, to produce valid "options" declaration result. // // *NOTE*: Replace "" below with your actual configuration name. // If you're unsure what to use, you can verify with `nix repl` by evaluating // the expression directly. // "nixos": { "expr": "(builtins.getFlake (builtins.toString ./.)).nixosConfigurations..options" }, // Before configuring Home Manager options, consider your setup: // Which command do you use for home-manager switching? // // A. home-manager switch --flake .#... // B. nixos-rebuild switch --flake .#... // // Configuration examples for both approaches are shown below. "home-manager": { // A: "expr": "(builtins.getFlake (builtins.toString ./.)).homeConfigurations..options" // B: "expr": "(builtins.getFlake (builtins.toString ./.)).nixosConfigurations..options.home-manager.users.type.getSubOptions []" } }, // Control the diagnostic system "diagnostic": { "suppress": [ "sema-extra-with" ] } } ``` -------------------------------- ### Option Information Output for binfmtMiscRegistrations Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd-attrset-eval/test/option-info.md This is an example output from `nixd-attrset-eval` when querying `boot.binfmtMiscRegistrations`. It shows that the option has no default or example defined, and provides its description and type information. ```text CHECK: "Default": null, CHECK-NEXT: "Definitions": [], CHECK-NEXT: "Description": "Alias of {option}`boot.binfmt.registrations`.", CHECK-NEXT: "Example": null, CHECK-NEXT: "Type": { CHECK-NEXT: "Description": "attribute set of (submodule)", CHECK-NEXT: "Name": "attrsOf" CHECK-NEXT: } ``` -------------------------------- ### Install Project with Ninja Source: https://github.com/nix-community/nixd/blob/main/nixd/docs/dev.md Install the compiled nixd project using Ninja. This is required before launching an editor for testing. ```bash ninja -C build install ``` -------------------------------- ### Start Neovim Test Environment Source: https://github.com/nix-community/nixd/blob/main/nixd/docs/editors/editors.md Use this command to launch a Neovim instance with LSP support for testing. ```console nix develop github:nix-community/nixd#nvim nvim-lsp . ``` -------------------------------- ### Install nixd using nix-env (NixOS) Source: https://github.com/nix-community/nixd/blob/main/nixd/docs/editor-setup.md Installs the nixd package using legacy nix-env commands on NixOS. ```console nix-env -iA nixos.nixd ``` -------------------------------- ### Basic nixf-tidy Usage Example Source: https://github.com/nix-community/nixd/blob/main/libnixf/README.md Shows a simple command to pipe Nix code into `nixf-tidy` for variable lookup analysis. ```bash cat foo.nix | nixf-tidy --variable-lookup ``` -------------------------------- ### Start VSCodium Test Environment Source: https://github.com/nix-community/nixd/blob/main/nixd/docs/editors/editors.md Use this command to launch a VSCodium instance with the vscode-nix-ide plugin for testing. ```console nix develop github:nix-community/nixd#vscodium codium-test . ``` -------------------------------- ### Query Option Information for kernelModules Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd-attrset-eval/test/option-info.md This JSON RPC request uses the `attrset/optionInfo` method to get details for the `boot.kernelModules` option. This is useful for understanding how to configure kernel modules, including their default and example values. ```json { "jsonrpc":"2.0", "id":2, "method":"attrset/optionInfo", "params": [ "boot", "kernelModules" ] } ``` -------------------------------- ### Initialize Nixd Language Server Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/extract-to-file/extract-with-free-vars.md Initializes the nixd language server with workspace capabilities. This is a standard setup for LSP clients. ```json { "jsonrpc":"2.0", "id":0, "method":"initialize", "params":{ "processId":123, "rootPath":"", "capabilities":{ "workspace": { "workspaceEdit": { "documentChanges": true, "resourceOperations": ["create", "rename", "delete"] } } }, "trace":"off" } } ``` -------------------------------- ### Option Information Output for kernelModules Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd-attrset-eval/test/option-info.md This output shows the information for `boot.kernelModules`. Notably, it displays a string representation of the example value, which is preferred over a raw list default to prevent deep recursion issues. ```text CHECK: "Default": null, CHECK-NEXT: "Definitions": [], CHECK-NEXT: "Description": "The set of kernel modules to be loaded in the second stage of the boot process.", CHECK-NEXT: "Example": "[ \"kvm-intel\" \"snd_hda_intel\" ]", CHECK-NEXT: "Type": { ``` -------------------------------- ### Install nixd using nix-env (Non-NixOS) Source: https://github.com/nix-community/nixd/blob/main/nixd/docs/editor-setup.md Installs the nixd package using legacy nix-env commands on non-NixOS systems. ```console nix-env -iA nixpkgs.nixd ``` -------------------------------- ### Install nixd using nix profile Source: https://github.com/nix-community/nixd/blob/main/nixd/docs/editor-setup.md Adds the nixd package to your user profile using the nix profile command. ```console nix profile add github:nixos/nixpkgs#nixd ``` -------------------------------- ### Request Option Info for 'boot.tmp.cleanOnBoot' Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd-attrset-eval/test/option-info.md Send a JSON-RPC request to get information about the 'boot.tmp.cleanOnBoot' option. This is used to test how the tool handles options with scalar defaults and no examples. ```json { "jsonrpc":"2.0", "id":4, "method":"attrset/optionInfo", "params": [ "boot", "tmp", "cleanOnBoot" ] } ``` -------------------------------- ### Nixd Completion Response for Option with Example and Default Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/completion/options-default.md The expected completion response from nixd when an option has both 'example' and 'defaultText'. It shows two distinct items, sorted by 'sortText'. ```json { "id": 1, "jsonrpc": "2.0", "result": { "isIncomplete": false, "items": [ { "data": "", "detail": "nixos | bool (boolean)", "documentation": null, "filterText": "bar", "insertText": "bar = ${1:true};", "insertTextFormat": 2, "kind": 4, "label": "bar (example)", "score": 0, "sortText": "0bar", "textEdit": { "newText": "bar = ${1:true};", "range": { "end": { "character": 17, "line": 0 }, "start": { "character": 15, "line": 0 } } } }, { "data": "", "detail": "nixos | bool (boolean)", "documentation": null, "filterText": "bar", "insertText": "bar = ${1:pkgs.stdenv.hostPlatform.isLinux}; "insertTextFormat": 2, "kind": 4, "label": "bar (default)", "score": 0, "sortText": "1bar", "textEdit": { "newText": "bar = ${1:pkgs.stdenv.hostPlatform.isLinux};", "range": { "end": { "character": 17, "line": 0 } "start": { "character": 15, "line": 0 } } } } ] } } ``` -------------------------------- ### Configure Project with Meson Source: https://github.com/nix-community/nixd/blob/main/nixd/docs/dev.md Configure the nixd project using Meson. Use `--buildtype=debug` for development, `--prefix=` for non-privileged installation, `--default-library=static` to avoid RPATH issues, and `-Dwerror=true` to match CI settings. ```bash meson setup build --buildtype=debug --default-library=static --prefix=$PWD/local/install -Dwarning_level=3 -Dwerror=true ``` -------------------------------- ### Neovim nixd LSP Configuration Source: https://github.com/nix-community/nixd/blob/main/nixd/docs/configuration.md Configure the nixd LSP client in Neovim using vim.lsp.config. This example sets up the command, filetypes, root markers, and specific settings for nixpkgs, formatting, and options. ```lua local nvim_lsp = vim.lsp vim_lsp.config("nixd", { cmd = { "nixd" }, filetypes = { "nix" }, root_markers = { "flake.nix", ".git" }, settings = { nixd = { nixpkgs = { expr = "import { }", }, formatting = { command = { "nixfmt" }, }, options = { nixos = { expr = '(builtins.getFlake (toString ./.)).nixosConfigurations..options', }, home_manager = { expr = '(builtins.getFlake (toString ./.)).homeConfigurations."@".options', }, }, }, }, }) vim_lsp.enable("nixd") ``` -------------------------------- ### Request Code Action for Noogle Documentation Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/noogle-doc/noogle-lib-simple.md Requests a code action for a specific range within a Nix file. This example specifically triggers the 'Open Noogle documentation' action. ```json { "jsonrpc":"2.0", "id":2, "method":"textDocument/codeAction", "params":{ "textDocument":{ "uri":"file:///noogle-lib-simple.nix" }, "range":{ "start":{ "line": 0, "character":0 }, "end":{ "line":0, "character":18 } }, "context":{ "diagnostics":[], "triggerKind":2 } } } ``` -------------------------------- ### Evaluate Nix Expression with Documentation Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd-attrset-eval/test/attrs-info-doc.md Send a JSON-RPC request to evaluate a Nix expression. This example includes an attribute with embedded markdown documentation. ```json { "jsonrpc":"2.0", "id":0, "method":"attrset/evalExpr", "params": "{ hello = /** some markdown docs */x: y: x; }" } ``` -------------------------------- ### Request References for 'foo' Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/references/with.md Requests references for the identifier 'foo' within the 'basic.nix' file. The position is set to the start of 'foo'. ```json { "jsonrpc":"2.0", "id":2, "method":"textDocument/references", "params":{ "textDocument":{ "uri":"file:///basic.nix" }, "position":{ "line": 0, "character":3 } } } ``` -------------------------------- ### Configuring Home Manager Options (Standalone) in nixd Source: https://github.com/nix-community/nixd/blob/main/nixd/docs/configuration.md For users with a standalone Home Manager setup not integrated with NixOS, use this configuration to provide Home Manager options to nixd. Ensure the paths to your Home Manager configuration and nixpkgs are correct. ```jsonc { "options": { "home-manager": { "expr": "(import { configuration = ~/.config/home-manager/home.nix; pkgs = import {}; }).options" } } } ``` -------------------------------- ### Open Nix file with nested with statements Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/with-to-let/with-to-let-indirect-lambda.md Opens a Nix file containing nested 'with' statements, one of which is within a lambda. This setup is used to test code action behavior. ```nix with outer; x: with inner; baz ``` -------------------------------- ### Query Option Information for binfmtMiscRegistrations Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd-attrset-eval/test/option-info.md This JSON RPC request targets the `attrset/optionInfo` method to retrieve detailed information about the `boot.binfmtMiscRegistrations` option. It's used to inspect an option's description, type, default value, and examples. ```json { "jsonrpc":"2.0", "id":1, "method":"attrset/optionInfo", "params": [ "boot", "binfmtMiscRegistrations" ] } ``` -------------------------------- ### Retrieve Home-Manager Options in NixOS Module Source: https://github.com/nix-community/nixd/blob/main/nixd/docs/configuration.md Use this expression to get home-manager options when your home-manager is installed as part of a NixOS module. Replace `` with your actual configuration name. ```nix (builtins.getFlake (builtins.toString ./.)).nixosConfigurations..options.home-manager.users.type.getSubOptions [] ``` -------------------------------- ### Open Nix File for Hover Test Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/hover/value-docs.md Simulates opening a Nix file named 'basic.nix' containing a reference to 'pkgs.myFunc'. This prepares the environment for the hover request. ```nix pkgs.myFunc ``` -------------------------------- ### Initialize Nixd Language Server Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/pack-attrs/pack-attrs-shallow-bulk.md Initializes the nixd language server with basic parameters. ```json { "jsonrpc":"2.0", "id":0, "method":"initialize", "params":{ "processId":123, "rootPath":"", "capabilities":{}, "trace":"off" } } ``` -------------------------------- ### Option Information Output for kernelPackages Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd-attrset-eval/test/option-info.md This output for `boot.kernelPackages` illustrates that when both `default` and `defaultText` are present, `defaultText` is prioritized. This ensures that a user-friendly representation is shown instead of a placeholder. ```text CHECK: "Default": "pkgs.linuxPackages", CHECK-NEXT: "Definitions": [], CHECK-NEXT: "Description": "The kernel packages set.", CHECK-NEXT: "Example": null, ``` -------------------------------- ### Open Nix File with Package Selection Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/definition/select-package.md This section demonstrates opening a Nix file containing a package selection expression (`pkgs.x`) for definition lookup. ```nix pkgs.x ``` -------------------------------- ### Install nixd on NixOS Source: https://github.com/nix-community/nixd/blob/main/nixd/docs/editor-setup.md Add the nixd package to your system's environment for use on NixOS. ```nix { pkgs, ... }: { environment.systemPackages = with pkgs; [ nixd ]; } ``` -------------------------------- ### Nix Indented String Example Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/rewrite-string/to-dquote-newline.md A Nix code snippet demonstrating an indented string with a newline character. ```nix { x = ''hello world''; } ``` -------------------------------- ### nixf-tidy CLI Options Source: https://github.com/nix-community/nixd/blob/main/libnixf/README.md Lists the available command-line options for the `nixf-tidy` tool, used for linting Nix projects. ```text nixf-tidy --pretty-print Pretty print the JSON data --variable-lookup Peform Variable Lookup Analysis on the source code, including detecting dead code, and unused variables. ``` -------------------------------- ### Configure Coc.nvim for nixd Source: https://github.com/nix-community/nixd/blob/main/nixd/docs/editor-setup.md Set up coc-settings.json to use nixd as the language server for Nix files. ```jsonc { "languageserver": { "nix": { "command": "nixd", "filetypes": ["nix"] } } } ``` -------------------------------- ### TextDocument DidOpen Notification Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/hover/empty-payload.md Sent to the language server when a text document is opened by the client. This example opens a Nix file. ```nix pkgs.undocumented ``` -------------------------------- ### Request Inlay Hints Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/inlay-hint.md Requests inlay hints for a specific range in a Nix file. The response will contain hints like package versions. ```json { "jsonrpc": "2.0", "id": 1, "method": "textDocument/inlayHint", "params": { "textDocument":{ "uri":"file:///basic.nix" }, "range": { "start":{ "line": 0, "character":0 }, "end":{ "line":0, "character":20 } } } } ``` -------------------------------- ### Request Document Highlights Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/document-highlight/fail.md Requests document highlights for a specific position in a Nix file. This example demonstrates a scenario where no highlights are expected. ```json { "jsonrpc":"2.0", "id":2, "method":"textDocument/documentHighlight", "params":{ "textDocument":{ "uri":"file:///basic.nix" }, "position":{ "line": 0, "character":1 } } } ``` -------------------------------- ### Open Nix File Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/definition/let-in.md Simulates opening a Nix file with a simple let-in expression. This is a prerequisite for requesting definitions. ```nix let x = 1; in x ``` -------------------------------- ### Configure Kakoune-lsp for nixd Source: https://github.com/nix-community/nixd/blob/main/nixd/docs/editor-setup.md Set up Kakoune-lsp hooks to enable nixd for Nix filetypes, specifying root globs. ```kakscript remove-hooks global lsp-filetype-nix hook -group lsp-filetype-nix global BufSetOption filetype=nix %{ set-option buffer lsp_servers %{ [nixd] root_globs = ["flake.nix", "shell.nix", ".git", ".hg"] } } ``` -------------------------------- ### DidOpen Notification for Nix File Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/rename/issue-255-1.md Notifies the language server that a Nix file has been opened. This allows the server to start analyzing the file. ```nix {a ? 1}: { x = a; } ``` -------------------------------- ### Open Nix File for Code Action Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/rewrite-string/to-indented.md Opens a Nix file with a simple string assignment to trigger code actions. The file content is `{ x = "hello"; }`. ```nix { x = "hello"; } ``` -------------------------------- ### DidOpen TextDocument Notification Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/completion/select.md A notification sent to the language server when a text document is opened. This example shows a Nix file with partial input. ```nix pkgs.hel ``` -------------------------------- ### Query Option Information for kernelPackages Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd-attrset-eval/test/option-info.md This JSON RPC request queries the `attrset/optionInfo` method for the `boot.kernelPackages` option. It demonstrates how the tool handles options that have both a raw default and a `defaultText` field. ```json { "jsonrpc":"2.0", "id":3, "method":"attrset/optionInfo", "params": [ "boot", "kernelPackages" ] } ``` -------------------------------- ### Verify Definition Response Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/definition/inherit.md Uses FileCheck to verify that the definition response from nixd correctly identifies the start and end range of the 'x' symbol. ```shell CHECK: "id": 2, CHECK-NEXT: "jsonrpc": "2.0", CHECK-NEXT: "result": { CHECK-NEXT: "range": { CHECK-NEXT: "end": { CHECK-NEXT: "character": 5, CHECK-NEXT: "line": 0 CHECK-NEXT: }, CHECK-NEXT: "start": { CHECK-NEXT: "character": 4, CHECK-NEXT: "line": 0 CHECK-NEXT: } CHECK-NEXT: }, ``` -------------------------------- ### Open Nix File for Hover Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/hover/package-select.md Opens a Nix file containing a package reference. This action makes the file content available to the language server for analysis. ```nix pkgs.foo ``` -------------------------------- ### Request Hover Information for Nix Function Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/hover/value-docs.md Requests hover information for the 'myFunc' symbol in 'basic.nix'. The position is set to the start of the symbol to ensure accurate retrieval. ```json { "jsonrpc":"2.0", "id":2, "method":"textDocument/hover", "params":{ "textDocument":{ "uri":"file:///basic.nix" }, "position":{ "line":0, "character":5 } } } ``` -------------------------------- ### Open Nix File for Code Action Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/attr-name/quote-let.md Opens a Nix file with a simple let-in expression. This prepares the file for subsequent code action requests. ```nix let foo = 1; in foo ``` -------------------------------- ### Open Nix File for Code Action Test Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/add-to-formals/already-defined-negative.md Opens a Nix file named 'already-defined.nix' with the content '{x}: x'. This sets up the context for testing code actions. ```nix {x}: x ``` -------------------------------- ### Complete Attribute Set Keys Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd-attrset-eval/test/attrs-completion.md Send a JSON-RPC request to get completion suggestions for attribute set keys. Provide a scope and a prefix to filter the suggestions. ```json { "jsonrpc":"2.0", "id":1, "method":"attrset/attrpathComplete", "params": { "Scope": [ ], "Prefix": "py" } } ``` -------------------------------- ### TextDocument Completion Request Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/completion/select.md A request to the language server for completion suggestions at a specific position in a text document. This example targets the partial input 'hel' in a Nix file. ```json { "jsonrpc": "2.0", "id": 1, "method": "textDocument/completion", "params": { "textDocument": { "uri": "file:///completion.nix" }, "position": { "line": 0, "character": 7 }, "context": { "triggerKind": 1 } } } ``` -------------------------------- ### Configure KDE Kate LSP Client for nixd Source: https://github.com/nix-community/nixd/blob/main/nixd/docs/editor-setup.md Configure the LSP Client plugin in KDE Kate to use nixd for Nix files. ```jsonc { "servers": { "nix": { "command": ["nixd"], "url": "https://github.com/nix-community/nixd", "highlightingModeRegex": "^Nix$" } } } ``` -------------------------------- ### Nixd Code Action Response (Quick Fix) Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/quick-fix/quick-fix.md The expected response from nixd when a code action, specifically a quick fix, is requested. This example shows the 'insert */' quick fix. ```json { "id": 2, "jsonrpc": "2.0", "result": [ { "edit": { "changes": { "file:///basic.nix": [ { "newText": "*/", "range": { "end": { "character": 2, "line": 0 }, "start": { "character": 2, "line": 0 } } } ] } }, "kind": "quickfix", "title": "insert */" } ] } ``` -------------------------------- ### Initialize Request Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/initialize.md Sends an 'initialize' request to the nixd server. This is the first step in establishing a connection and should include process ID, root path, client capabilities, and trace level. ```json { "jsonrpc":"2.0", "id":0, "method":"initialize", "params":{ "processId":123, "rootPath":"", "capabilities":{ }, "trace":"off" } } ``` -------------------------------- ### Diagnose Nix Expression Issues in Nix REPL Source: https://github.com/nix-community/nixd/blob/main/nixd/docs/configuration.md Test your Nix expressions in `nix repl` to diagnose evaluation issues. This example shows how to inspect NixOS configuration options. ```nix nix-repl> (builtins.getFlake (builtins.toString ./.)).nixosConfigurations..options error: syntax error, unexpected SPATH, expecting ID or OR_KW or DOLLAR_CURLY or '"' at «string»:1:65: 1| (builtins.getFlake (builtins.toString ./.)).nixosConfigurations..options | ^ ``` ```nix nix-repl> (builtins.getFlake (builtins.toString ./.)).nixosConfigurations.adrastea.options { _module = { ... }; appstream = { ... }; assertions = { ... }; boot = { ... }; # ... more options ..., this is expected. } ``` -------------------------------- ### Nix Syntax Error Example (Missing Semicolon) Source: https://github.com/nix-community/nixd/blob/main/libnixf/README.md Illustrates a common Nix syntax error where a missing semicolon after a value can lead to unexpected parsing behavior in the official parser. ```nix { a = 1 b = 2 } ``` -------------------------------- ### Initialize Nixd Language Server Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/add-to-formals/already-defined-negative.md Sends an initialize request to the nixd language server. This is a standard first step in LSP communication. ```json { "jsonrpc":"2.0", "id":0, "method":"initialize", "params":{ "processId":123, "rootPath":"", "capabilities":{ }, "trace":"off" } } ``` -------------------------------- ### Open Nix File with Quoted Underscore Attribute Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/attr-name/unquote-underscore.md Opens a Nix file containing an attribute name enclosed in quotes that starts with an underscore. This sets up the scenario for the code action. ```nix { "_private" = 1; } ``` -------------------------------- ### Initialize Nixd Language Server Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/convert-to-inherit/convert-to-inherit-with-default.md Sends an initialize request to the Nixd language server. This is a standard first step in LSP communication. ```json { "jsonrpc":"2.0", "id":0, "method":"initialize", "params":{ "processId":123, "rootPath":"", "capabilities":{ }, "trace":"off" } } ``` -------------------------------- ### Open Nix File for Code Actions Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/pack-attrs/pack-attrs-multiple-prefixes-foo.md Opens a Nix file containing multiple attribute sets ('foo' and 'bar') for analysis. This sets up the context for testing code actions. ```nix { foo.a = 1; foo.b = 2; bar.c = 3; bar.d = 4; } ``` -------------------------------- ### Compile Project with Meson Source: https://github.com/nix-community/nixd/blob/main/nixd/docs/dev.md Compile the nixd project after configuration using Meson. ```bash meson compile -C build ``` -------------------------------- ### Open Nix File with Sibling Inherit Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/pack-attrs/pack-attrs-sibling-inherit.md Opens a Nix file containing an attribute set with a dotted path and an `inherit` binding for a sibling. This setup is used to test the 'pack-attrs' code action. ```nix { foo.bar = 1; inherit baz; } ``` -------------------------------- ### Open Nix File with Inherit Conflict Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/pack-attrs/pack-attrs-inherit-conflict.md Opens a Nix file that contains a conflicting 'inherit' statement and a dotted path assignment. This setup is used to test the 'Pack' code action behavior. ```nix { inherit foo; foo.bar = 1; } ``` -------------------------------- ### Open Nix File for Definition Test Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/definition/builtin.md Opens a Nix file named 'basic.nix' containing the keyword 'builtins' to prepare for a definition request. ```nix builtins ``` -------------------------------- ### Request Code Action for Dotted Path Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/pack-attrs/pack-attrs.md Requests code actions for a specific range within a Nix file. This example targets the dotted path 'foo.bar' to trigger the 'Pack dotted path' action. ```json { "jsonrpc":"2.0", "id":2, "method":"textDocument/codeAction", "params":{ "textDocument":{ "uri":"file:///pack-attrs.nix" }, "range":{ "start":{ "line": 0, "character":2 }, "end":{ "line":0, "character":9 } }, "context":{ "diagnostics":[], "triggerKind":2 } } } ``` -------------------------------- ### Open Nix File for Diagnostics Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/diagnostic/liveness.md Opens a Nix file with the URI 'file:///basic.nix' to trigger diagnostics. The expected output checks for an empty diagnostics list and the file's URI and version. ```nix x: y: x + 1 ``` ```text CHECK: "diagnostics": [], CHECK-NEXT: "uri": "file:///basic.nix", CHECK-NEXT: "version": 1 ``` -------------------------------- ### Open Nix File for Definition Test Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/definition/path.md Opens a Nix file in the language server to prepare for definition requests. The file URI includes a placeholder for the test directory. ```nix file://TEST_DIR/main.nix ./target.nix ``` -------------------------------- ### Open Nix File with Invalid Let Binding Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/attr-name/unquote-let-invalid.md Opens a Nix file containing a let binding with an invalid identifier (quoted string starting with a digit). This is used to test code action behavior. ```nix let "123" = 1; in x ``` -------------------------------- ### Open Nix File with Conflicting Bindings Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/pack-attrs/pack-attrs-conflict.md Opens a Nix file containing a conflict: a simple binding 'foo' and a dotted path 'foo.bar'. This setup is used to test the 'Pack' code action behavior. ```nix { foo = 1; foo.bar = 2; } ``` -------------------------------- ### Open Nix File for Analysis Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/with-to-let/with-to-let-indirect-attrset.md Opens a Nix file for the language server to analyze. This file contains nested `with` statements. ```nix with outer; { y = with inner; bar; } ``` -------------------------------- ### Open Nix File for Testing Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/noogle-doc/noogle-not-lib.md Opens a Nix file named 'noogle-not-lib.nix' for the language server. This prepares the environment for subsequent code action requests. ```nix pkgs.hello ``` -------------------------------- ### JSON RPC Request for Option Completion Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd-attrset-eval/test/option-complete.md A JSON RPC request to get completion suggestions for options within a specified scope. The 'Scope' parameter filters the search, and 'Prefix' can be used for partial matching. ```json { "jsonrpc":"2.0", "id":1, "method":"attrset/optionComplete", "params": { "Scope": [ "boot" ], "Prefix": "" } } ``` -------------------------------- ### Open Nix File Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/hover/1.md Opens a basic Nix file named 'basic.nix' with content '{ a = 1; }' in the language server. This prepares the server to process requests related to this file. ```nix { a = 1; } ``` -------------------------------- ### Send JSON-RPC Request for Attribute Path Info Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd-attrset-eval/test/attrs-info.md Send a JSON-RPC request to the `attrset/attrpathInfo` method to get information about a specific attribute path within an attribute set. The attribute path is provided as a string. ```json { "jsonrpc":"2.0", "id":1, "method":"attrset/attrpathInfo", "params": [ "hello" ] } ``` -------------------------------- ### Open Nix File for Testing Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/convert-to-inherit/convert-to-inherit-selector-mismatch.md Opens a Nix file in the language server to enable code analysis. The content is a simple attribute set. ```nix { foo = lib.bar; } ``` -------------------------------- ### Open Nix File for Hover Test Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/hover/options.md This code block represents opening a Nix file named 'basic.nix' with content `{ foo.bar = 1 }`. This is a prerequisite for testing hover functionality. ```nix { foo.bar = 1 } ``` -------------------------------- ### Nix Code for Pack Attributes Test Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/pack-attrs/pack-attrs-bulk-quoted.md This Nix code defines attributes where one key, "1foo", starts with a digit and thus requires quoting. This serves as input for testing the pack attributes code actions. ```nix { "1foo".a = 1; "1foo".b = 2; } ``` -------------------------------- ### Initialize LSP Client Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/completion/options-in-config.md Sends an initialize request to the Language Server Protocol client. ```json { "jsonrpc":"2.0", "id":0, "method":"initialize", "params":{ "processId":123, "rootPath":"", "capabilities":{ }, "trace":"off" } } ``` -------------------------------- ### Open Nix File for Folding Range Analysis Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/folding-range/basic.md Opens a Nix file with sample attribute sets and lists for testing folding range functionality. This snippet defines the content that will be analyzed. ```nix { # Multi-line attribute set attrs = { x = 1; y = 2; }; # Multi-line list list = [ 1 2 ]; } ``` -------------------------------- ### Attribute name coloring for nested attributes Source: https://github.com/nix-community/nixd/blob/main/nixd/docs/features.md This example demonstrates how semantic tokens can differentiate between attribute paths that create nested attribute sets (like `foo.bar`) and those that create new entries within an existing set (like `foo.x`). The goal is to visually distinguish these structures. ```nix { foo.bar = 1; # ~~~ ~~~ <----- these two tokens should be colored as same foo.x = 2; # ~~~ <----- this token, however will not be colored as same as "foo.bar" } ``` ```nix { foo = { # ^~~ <-------- new ! bar = 1; # <------- new ! }; } ``` ```nix { foo = { bar = 1; x = 2; # <---- new ! }; } ``` -------------------------------- ### Open Nix File for Code Actions Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/pack-attrs/pack-attrs-bulk-multiline.md Opens a Nix file containing attribute sets to enable code actions. The content defines multiple bindings within the 'foo' attribute. ```nix { foo.bar = 1; foo.baz = 2; foo.qux = 3; } ``` -------------------------------- ### Inlay hints for package versions Source: https://github.com/nix-community/nixd/blob/main/nixd/docs/features.md Inlay hints display package versions directly in your system configuration, making it easier to track versions. The version strings are evaluated using the `name.version` attrpath and should align with your configured `nixpkgs`. ```nix with pkgs; [ nix: 2.19.0 # ~~~~~~~~~~~~~~ <-- the version, floating. ] ``` -------------------------------- ### Open Nix File for Code Action Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/unused-def/multiple-bindings.md Opens a Nix file with multiple bindings to demonstrate the unused binding removal code action. Ensure the file content is correctly provided. ```nix let x = 1; y = 2; in y ``` -------------------------------- ### Open Nix File for Code Action Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/add-to-formals/multiple-formals.md Opens a Nix file with existing formals to trigger code actions. The file content is `{a, b, c}: d`. ```nix {a, b, c}: d ``` -------------------------------- ### Open Nix File and Request Hover Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/hover/options-in-config.md Opens a Nix file containing a configuration and then requests hover information for a specific position within that file. This tests nixd's ability to provide details about Nix options. ```nix { config = { foo }; } ``` ```json { "jsonrpc": "2.0", "id": 2, "method": "textDocument/hover", "params":{ "textDocument":{ "uri": "file:///test.nix" }, "position":{ "line": 0, "character": 15 } } } ``` -------------------------------- ### Open Nix File for Code Action Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/add-to-formals/basic.md Opens a Nix file with a simple function definition to test the 'add to formals' code action. The file content is `{x}: y`. ```nix {x}: y ``` -------------------------------- ### Open Nix File with JSON Array Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/json-to-nix/json-to-nix-array.md Simulates opening a Nix file containing a JSON array. This sets up the context for the code action. ```nix [1, 2, 3] ``` -------------------------------- ### Open Nix File for Testing Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/rewrite-string/not-string.md Opens a Nix file named 'not-string.nix' for the language server to process. ```nix { x = 42; y = ./path; z = true; } ``` -------------------------------- ### DidOpen Nix File Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/hover/2.md Opens a basic Nix file named 'basic.nix' with the content '{ a = 1; }'. This prepares the language server for subsequent requests on this file. ```nix { a = 1; } ``` -------------------------------- ### Initialize Request Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/completion/comment.md Sends an initialize request to the nixd server. This is typically the first message exchanged. ```json { "jsonrpc":"2.0", "id":0, "method":"initialize", "params":{ "processId":123, "rootPath":"", "capabilities": { }, "trace":"off" } } ``` -------------------------------- ### Verify Definition Result for Package Selection Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/definition/select-package.md This section uses FileCheck to verify that the definition provider correctly returns the URI and range for the selected package. ```text CHECK: "id": 2, CHECK-NEXT: "jsonrpc": "2.0", CHECK-NEXT: "result": { CHECK-NEXT: "range": { CHECK-NEXT: "end": { CHECK-NEXT: "character": 0, CHECK-NEXT: "line": 33 CHECK-NEXT: }, CHECK-NEXT: "start": { CHECK-NEXT: "character": 0, CHECK-NEXT: "line": 33 CHECK-NEXT: } CHECK-NEXT: }, CHECK-NEXT: "uri": "file:///foo" CHECK-NEXT: } ``` -------------------------------- ### Open Nix File for Analysis Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/with-to-let/with-to-let-shadowing.md Opens a Nix file to enable analysis and code action suggestions. ```nix with lib; let foo = 1; in foo + optionalString true "x" ``` -------------------------------- ### Open Nix File for Code Actions Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/pack-attrs/pack-attrs-bulk-non-contiguous.md Opens a Nix file to enable code analysis and action suggestions. ```nix { foo.a = 1; bar = 2; foo.b = 3; } ``` -------------------------------- ### Open Nix File Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/pack-attrs/pack-attrs-sibling-different-prefix.md Opens a Nix file for the language server to process. This file contains multiple dotted path bindings. ```nix { foo.bar = 1; baz.qux = 2; } ``` -------------------------------- ### Open Nix File for Code Action Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/convert-to-inherit/convert-to-inherit-from-nested.md Opens a Nix file containing a nested attribute set access. This prepares the file for code analysis and action requests. ```nix { x = lib.nested.x; } ``` -------------------------------- ### Open Nix File for Code Action Test Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/convert-to-inherit/convert-to-inherit-with-default.md Opens a Nix file named 'convert-to-inherit-with-default.nix' for analysis. The content includes a simple attribute set with a default value. ```nix { foo = lib.foo or null; } ``` -------------------------------- ### Open Nix File for Code Action Test Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/with-to-let/with-to-let-cursor-not-on-with.md Opens a Nix file containing a 'with' statement. This sets up the context for testing code actions. ```nix with lib; optionalString foo "yes" ``` -------------------------------- ### Open Nix File for Analysis Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/extract-to-file/extract-with-scope-vars.md Opens a Nix file to enable code analysis and actions. ```nix { pkgs }: with pkgs; { buildInputs = [ foo bar ]; } ``` -------------------------------- ### Nixd Hover Response with Documentation Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/hover/value-docs.md The expected response from the nixd language server when hovering over 'myFunc'. It includes the documentation string defined in the Nix code. ```text CHECK: "id": 2, CHECK-NEXT: "jsonrpc": "2.0", CHECK-NEXT: "result": { CHECK-NEXT: "contents": { CHECK-NEXT: "kind": "markdown", CHECK-NEXT: "value": "Documentation for myFunc " CHECK-NEXT: }, CHECK-NEXT: "range": { CHECK-NEXT: "end": { CHECK-NEXT: "character": 11, CHECK-NEXT: "line": 0 CHECK-NEXT: }, CHECK-NEXT: "start": { CHECK-NEXT: "character": 0, CHECK-NEXT: "line": 0 CHECK-NEXT: } CHECK-NEXT: } CHECK-NEXT: } ``` -------------------------------- ### Open Nix File for Analysis Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/unused-def/all-unused.md Opens a Nix file in the LSP client to enable analysis. The file content is provided for the server to process. ```nix let x = 1; y = 2; in 3 ``` -------------------------------- ### Open Completion Test File Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/completion/options-mid.md Opens a Nix file for completion testing. This snippet demonstrates the content of the file being analyzed. ```nix { bar = 1; fo. bar = 1; } ``` -------------------------------- ### Request Definition for Package Selection Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/definition/select-package.md This JSON-RPC request asks the nixd language server for the definition of the selected package at a specific position in the Nix file. ```json { "jsonrpc":"2.0", "id":2, "method":"textDocument/definition", "params":{ "textDocument":{ "uri":"file:///basic.nix" }, "position":{ "line": 0, "character":5 } } } ``` -------------------------------- ### Open Nix File for Conversion Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/convert-to-inherit/convert-to-inherit-simple.md Opens the Nix file containing the expression to be refactored. The content `{ foo = foo; }` is provided. ```nix { foo = foo; } ``` -------------------------------- ### Open Nix File for Completion Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/completion/option-stop.md Opens a Nix file containing an incomplete option definition to trigger completion. The file content is provided to the language server. ```nix { bar = 1; foo.bar. } ``` -------------------------------- ### Open Nix File for Code Action Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/pack-attrs/pack-attrs.md Opens a Nix file in the nixd language server to enable code analysis and action suggestions. The file content is provided directly. ```nix { foo.bar = 1; } ``` -------------------------------- ### Open Nix File for Code Action Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/flatten-attrs/flatten-attrs-multi.md Opens a Nix file to enable code analysis and actions. The content defines a nested attribute set. ```nix { foo = { bar = 1; baz = 2; }; } ``` -------------------------------- ### Open Nix File for Code Action Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/convert-to-inherit/convert-to-inherit-rec.md Opens a Nix file containing a recursive attribute set for analysis. ```nix rec { foo = foo; } ``` -------------------------------- ### Open Nix File for Completion Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/completion/options-attrs-of-submodule-body.md Opens a Nix file to enable code completion. The file defines a structure where completion is expected within a submodule. ```nix { foo.bar.x = { }; } ``` -------------------------------- ### Open Empty Nix File Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/json-to-nix/json-to-nix-empty-array.md Simulates opening an empty Nix file containing only an empty JSON array. This sets up the scenario for testing code actions. ```nix [] ``` -------------------------------- ### Open Nix File for Analysis Source: https://github.com/nix-community/nixd/blob/main/nixd/tools/nixd/test/code-action/noogle-doc/noogle-lib-simple.md Opens a Nix file with the language server to enable analysis. This allows subsequent code actions to be performed on the file's content. ```nix lib.optionalString ```