Oxalica Nil Versions Save

NIx Language server, an incremental analysis assistant for writing in Nix.

2023-08-09

9 months ago

Features

  • Load LSP configuration from initializationOptions (#84), for clients without workspace/configuration support.

  • Use semantic token type boolean for true and false. (#52) This makes it possible to distinguish them from null which has the token type constant.

  • nil diagnostics exists with code 1 only if there is any error. (#90) Warnings are not counted for exit code now.

  • Impl memory limit configuration for flake evaluation, with config key nil.nix.maxMemoryMB. Only Linux platforms are supported yet.

  • Highly experimental SSR (Structural Search & Replace) impl as CLI nil ssr.

Fixes

  • Send workspace/configuration only if the client supports it (#85)

  • Only show references of with when the cursor is exactly on with.

  • Also show references of a variable when cursor's on one of them (#86).

  • Fix flake reloading condition on file changes (#92).

  • Fix popup message to mention autoArchive config (#96).

  • Fix build with nix 2.17 (#94).

  • Fix missed diagnostic update on the first open (#89).

  • Fix nondeterminism of diagnostics ordering.

  • Fix parsing of block comments.

  • Fix offset conversion for end of file (#100).

  • Fix many more typos.

Internal

  • Response time and size logging via NIL_LOG=nil=debug. Useful for debugging. Log messages >=DEBUG are now included in the release build, though disabled unless having filter envvar NIL_LOG set.

  • Delay link resolution in textDocument/documentLink. This reduces the time of textDocument/documentLink from ~100ms down to ~20ms for MB-sized files. Editors doing frequent query of links like coc.nvim can benefit a lot from it.

  • Filter out far away spans in textDocument/documentHighlight as optimization. They are not displayed anyway.

  • Enable LTO for release builds.

  • Bump MSRV to 1.70

  • Drop support for file-backed stdin/stdout in language server mode. It makes no sense.

2023-05-09

1 year ago

This is a patch release for previously missing configurables of the new auto-evaluation features.

Fixes

  • Add configurations to enable/disable and customize auto-evaluations. nil.nix.flake.{autoArchive,autoEvalInputs,nixpkgsInputName} See ./docs/configuration.md for more details.

  • autoEvalInputs is disabled by default due to issues (#79) about flake locks.

  • Nixpkgs detection for NixOS options now checks existences of lib and module-list.nix to reduce mis-detections. (#80)

2023-05-02

1 year ago

Happy International Workers' Day! Fight for workers' rights against overwork "culture" in China!

Features

  • Automatic flake archiving.

  • Flake inputs evaluation and type inference. (#76)

    Due to limitations of nix flake show backend, only known output fields are completed, including packages or devShells, but not custom lib. legacyPackages is only traversed since Nix 2.14, the first version to support filtering packages for only the current system.

    # flake.nix
    {
      inputs.rust-overlay.url = "github:oxalica/rust-overlay";
      outputs = { rust-overlay, ... }: let
        rustPkg = rust-overlay.packages.x86_64-linux.|; # default, rust, rust_nightly, ...
      in ...;
    }
    
  • Dynamic fields are now inferred to the rest type. This helps the common flake output usage: rust-overlay.packages.${system}.| # default, rust, ...

  • Auto-reloading flake when flake.{nix,lock} is changed on disk.

    This requires the LSP client to support didChangeWatchedFiles capability. VSCode and coc.nvim support it out-of-box, while Neovim's builtin LSP requires manual configurations (https://github.com/neovim/neovim/pull/22405#issuecomment-1453269735).

  • Progress bars for various costly loading operations.

Fixes

  • Suppress unused warnings for flake auto-inputs. (#73)
  • Parsing errors for string escapes. (#75)
  • Completion for fresh-created unsaved flake.nix.

Internal

  • The LSP frontend is heavily refactored into async-style. The framework library is also switched from lsp-server to async-lsp. (#74)
  • MSRV is bumped to 1.68

2023-04-03

1 year ago

Features

  • Code actions about string rewriting. (#69)

    • quote_attr and unquote_attr to quote/unquote attributes in attrset or let-in.
    • rewrite_string_to_indented and rewrite_indented_to_string to rewrite between two string styles.
    • rewrite_uri_to_string to rewrite deprecated URI literals into strings.
  • Completion for NixOS options.

    This requires a working Flake setup, which has an input named nixpkgs for the source of NixOS options. It must be a relatively recent version of github:NixOS/nixpkgs. If you have multiple nixpkgs in your inputs, you can create an alias inputs.nixpkgs.follows = "the-input-to-use" to select one.

    If it's correctly recognized and evaluated, any NixOS-module-like Nix files will get completions and type information for NixOS options.

    For example:

    { ... }:
    {
      nix.settings.|  # -> allowed-users, auto-optimise-store, ...
    }
    
  • The LSP server now reports server name nil and its version (if any) to the client through serverInfo during initialization.

Fixes

  • Parsing errors when ' appears in indented strings.
  • Panics when a flake input is named self.
  • Unescaped identifiers and/or attributes in completions.
  • Recognition of flake.nix when rec { ... } is used in top-level.

2023-03-11

1 year ago

Features

  • Warnings for unused parameters in limited known cases, including NixOS modules, packages, and flake inputs.
  • Code action remove_empty_let_in. (#63) let in foo => foo
  • Type inferences for attrset with unknown keys but known value types. (#68)

Fixes

  • Documentations. (#65)
  • Types of some flake outputs. (#66)
  • Crash when saving files. (#67)
  • Errors when handling flakes with cyclic inputs. (#71)

2023-03-01

1 year ago

Features

  • Better completions, documentations and types for builtins. Now builtins.| completes correctly with signatures and documentations.

  • Virtual path support. This is used by VSCode or coc.nvim when editing a new untitled file with filetype set to nix.

  • A coc.nvim extension coc-nil under editors/coc-nil for simpler startup. Currently it is still working in progress and does nothing more than passing coc.nvim configurations to the LSP.

    The extension is exported as flake output package coc-nil, or vimPlugins.coc-nil when using overlays.

Fixes

  • follows resolution of flake locks.
  • Panics when flake_graph is accessed but not set.
  • Documentation typos.

2023-02-03

1 year ago

Happy EastAsianLunisolarCalendar new year!

Breaking

  • Bump minimal supported rust version to 1.66

Features

  • Type schema for flake.nix. Common fields of flake definitions as well as defined inputs are subjects to completion now.

  • Goto-definition for flake inputs. The name in inputs.name = ... and outputs = { name, ... }: ... will take you to the flake.nix of the input inside Nix store.

    This requires an working nix binary and a valid flake.lock.

  • Completion for pat-parameters definitions. This also works in parameters of flake outputs. { inputs.nixpkgs.url = "..."; outputs = { n| }: { }; }

  • Add CLI for diagnostics. Now you can also run nil as a linter.

  • Support convert_to_inherit for let in and rec { }.

  • Documentation of all code actions now lives in docs/code_actions.md.

Fixes

  • LSP mishandling in DidChangeTextDocument, which caused issues on kakoune.
  • Missed error and panic information in log. Now a backtrace is captured if possible when the worker panicked.

2023-01-01

1 year ago

Happy GregorianCalendar new year!

Features

  • Add many code actions for refactoring or fix. Thanks to figsoda@github for implementations.

    • "Convert to inherit" now supports multiple LHS or RHS. { a.b = b; } => { a = { inherit b; }; } { a = b.a; } => { inherit (b) a; }

    • Add unresolved names to top-level lambda parameters. { foo }: foo + bar => { foo, bar }: foo + bar

    • Remove empty inherits. { inherit; } => { }

  • Names from with now have a special semantic token modifier withAttribute. One can add styles like underlines to them to distinguish them from other static bindings. There are examples dev/nix-ide-semantic-highlighting.patch for VSCode and dev/vim-coc.nix for (Neo)Vim/coc.nvim.

Fixes

  • Names of semantic highlighting are tweaked. Now we use constant and builtin for builtin constants (true) and functions (map). The standard defaultLibrary group in themes usually represent names from the "standard library", like rust-analyzer did, which is not the same as "builtin" constants.

2022-12-01

1 year ago

Snapshot release 2022-12-01

Features

  • Code actions.

    • foo = foo; => inherit foo;
    • foo.bar = 1; foo.bux = 2; => foo = { bar = 1; bux = 2; };
    • foo = { bar = 1; bux = 2; }; => foo.bar = 1; foo.bux = 2;

    Currently comments and whitespaces (including indentations) are preserved.

  • Highlight related texts.

    Highlight texts related to the one under the cursor. Don't be confused with semantic highlighting.

    • Highlight definitions and references when cursor's on identifiers.
    • Highlight all (attribute) references when cursor's on with.
    • Highlight all effective withs when cursor's on attributes from with.
  • Add configuration nil.diagnostics.excludedFiles to disable diagnostics for some file paths, like generated ones.

  • Configurations are now fully documented in docs/configuration.md.

Fixes

  • Don't emit debuginfo for the default release profile. This is somehow introduced accidentally. Nix builds are not affected due to strip.

  • Semantic highlighting is optimized and should work fluently with big files.

  • Semantic highlighting now ignores string literal inners, to integrate better with language injections (eg. nvim-treesitter). They would still be rendered as default string color if there is no injection.

Internal changes

  • More syntax desugaring code are moved into syntax crate and are made more portable.

  • More tests and optimizations for syntax.

2022-11-15

1 year ago

Snapshot release 2022-11-15

Mostly for bug fixes, some of which are annoying. The snapshot period will be slowing down if there are no interesting changes or big bug fixes.

New features:

  • Document links. textDocument/documentLink

    Valid relative paths, URLs and flake references now report as links. For VSCode, it's shown as underlined text, and a hand-shaped cursor is shown when moving over them. Ctrl-Click would open the target file or URL.

  • Store Attr source information in types.

    It is not quite useful for now, and is only be used by the "completion kind" during completion. We'll find a way to support goto-definition for it in the future.

Fixes:

  • Fixed type inference for if conditions.
  • Fixed errors from client exit monitor.
  • Fixed a deadlock that occurs when changing text rapidly.