nil/docs/features.md
2022-11-24 03:43:03 +08:00

3.7 KiB

Features

This incomplete list tracks noteble features currently implemented or planned.

  • Goto definition. textDocument/definition

    • References to parameters, let and rec {} bindings.
    • Relative paths.
  • Find references. textDocument/reference

    • Parameters, let and rec {} bindings.
    • With expression.
  • Links. textDocument/documentLink

    • Links for relative and absolute paths.
    • Links for search paths like <nixpkgs>.
    • Links for URLs like "https://...", "http://..." and etc.
    • Links for flake references like "github:NixOS/nixpkgs".
  • Code actions. textDocument/codeAction

    • Convert name = name; bindings to inherit.
  • Completion. textDocument/completion

    • Builtin names.
      • With documentations.
    • Local bindings and rec-attrset fields.
    • Keywords.
    • Attrset fields.
  • Diagnostics. textDocument/publishDiagnostics

    • Syntax errors.
    • Hard semantic errors reported as parse errors by Nix, like duplicated keys in attrsets.
    • Undefiend names.
    • Warnings of legacy syntax.
    • Warnings of unnecessary syntax.
    • Warnings of unused bindings, with and rec.
    • Client pulled diagnostics.
    • Custom filter
      • You can disable some diagnostic messages via LSP setting diagnostics.ignored, which accepts an array of ignored diagnostic code strings, eg. ["unused_binding","unused_with"]. The code of diagnostics is usually shows in parentheses together with the message.

        See documentations of your editor about how to set LSP settings.

  • Expand selection. textDocument/selectionRange

  • Renaming. textDocument/renamme, textDocument/prepareRename

    • Identifiers in parameters and bindings, from let, rec and non-rec attrsets.
    • Static string literal bindings.
    • Merged path-value binding names.
    • Names introduced by inherit.
    • Names used by inherit.
    • Conflict detection.
    • Rename to string literals.
  • Semantic highlighting. textDocument/semanticTokens/{range,full}

    • Delta response. textDocument/semanticTokens/full/delta

    • ⚠️ Currently it has performance issue for large files. It may be slow to respond when editing all-packages.nix.

      coc.nvim doesn't enable semantic highlighting by default. You need to manually enable it in settings.

      // coc-settings.json
      {
        "semanticTokens": { "filetypes": ["nix"] }
      }
      
  • Hover text. textDocument/hover.

    • Show kind of names.
    • Documentation for builtin names.
  • File symbols with hierarchy (aka. outline). textDocument/documentSymbol

  • File formatting.

    • Whole file formatting.
    • Range formatting.
    • On-type formatting.
    • External formatter.
      • Currently, an external formatter must be configured via LSP setting formatting.command to enable this functionality. It accepts null for disabled, or an non-empty array for the formatting command, eg. ["nixpkgs-fmt"] for nixpkgs-fmt. The command must read Nix code from stdin and print the formatted code to stdout.

        You might need to set other editor settings to enable format-on-save. Like, for coc.nvim,

        // coc-settings.json
        {
          "coc.preferences.formatOnSaveFiletypes": ["nix"]
        }
        
  • Cross-file analysis.

  • Multi-threaded.

    • Request cancellation. $/cancelRequest