Giter VIP home page Giter VIP logo

vscode-nix-ide's Introduction

nix-ide

Adds nix language support for VSCode Editor.

Features

Language Servers

Full editing support when using a language server. Generally, any nix LSP implementation should work. The following are tested so far:

{
  "nix.enableLanguageServer": true,
  "nix.serverPath": "nil"
  // "nix.serverPath": "nixd"
}

Pass settings to the language server via serverSettings.

{
  "nix.serverSettings": {
    // settings for 'nil' LSP
    "nil": {
      "diagnostics": {
        "ignored": ["unused_binding", "unused_with"]
      },
      "formatting": {
        "command": ["nixpkgs-fmt"]
      }
    }
  }
}
{
    "nix.serverSettings": {
        // settings for 'nixd' LSP
        "nixd": {
            "formatting": {
                "command": [ "nixpkgs-fmt" ]
            },
            "options": {
                // By default, this entriy will be read from `import <nixpkgs> { }`
                // You can write arbitary nix expression here, to produce valid "options" declaration result.
                // Tip: for flake-based configuration, utilize `builtins.getFlake`
                "nixos": {
                    "expr": "(builtins.getFlake \"/absolute/path/to/flake\").nixosConfigurations.<name>.options"
                },
                "home-manager": {
                    "expr": "(builtins.getFlake \"/absolute/path/to/flake\").homeConfigurations.<name>.options"
                }
            }
        }
  }
}

Standalone (No LSP)

When Language Server support is not enabled some tools can still be used.

  • Enable formatting support by setting nix.formatterPath to any command which can accept file contents on stdin and return formatted text on stdout; e.g.,
{
  "nix.formatterPath": "nixpkgs-fmt" // default
  // "nix.formatterPath": "nixfmt"
  // "nix.formatterPath": ["treefmt", "--stdin", "{file}"]
  // "nix.formatterPath": ["nix", "fmt", "--", "-"] // using flakes with `formatter = pkgs.alejandra;`
}
  • Error Report

    • Using nix-instantiate errors reported

    example of linting hover

  • Snippets

Todos

PRs welcome for them

Installation

Visual Studio Code

Hit F1 and enter the ext install jnoortheen.nix-ide command or search for nix-ide.

*.vsix file

The extension can be downloaded from the release page.

Installing the extension Locally

Just clone the GitHub repository under your local extensions folder:

  • Windows: %USERPROFILE%\.vscode\extensions
  • Mac / Linux: $HOME/.vscode/extensions

Contributing

  • Document the purpose of functions and classes.
  • Please mention a new feature in the README.md Features section when adding it. Use screenshots when applicable.
  • Conventional Commit style should be used for commit messages as it is used to generate changelog.

Development

There is direnv and nix-shell support so a dev environment can be created with the nix-shell command or a one-time direnv allow at the root of the repo.

Press F5 in VSCode to run an Extension Development Host instance with the extension installed.

TypeScript is used to develop the extension.

yarn install # install dependencies
yarn build   # build the extension

Releasing a new version

  • fill .env from .env.template
# this is needed to publish extensions to [openvsx](https://open-vsx.org/) from local machine.
yarn env-cmd

# this will generate changelog and will create a GitHub release. This will also trigger jobs to publish the extension.
yarn release

# to manually publish the extension
yarn publish

Special thanks to

  • wmertens for writing the syntax definitions.
  • The extension vscode-fish is modified to work for nix .

Links

vscode-nix-ide's People

Contributors

aaronjheng avatar adamcstephens avatar carlthome avatar crogers avatar dependabot[bot] avatar farwyler avatar frantisekhanzlikbl avatar georgefst avatar hall avatar inclyc avatar jamiemagee avatar jnoortheen avatar kclejeune avatar mkhl avatar nokazn avatar piousdeer avatar profpatsch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

vscode-nix-ide's Issues

`nil` lsp support

Hello ๐Ÿ‘‹

nil is a new nix LSP. By changing this setting to use it instead of rnix-lsp seems to work fine:

{
  // ...
  "nix.serverPath": "nil"
}

But I wonder if anything else would be necessary from this extension to improve the integration.

Related: oxalica/nil#6

NIL unwraps URI without checking path's existence

The NIL server breaks when there is an unsaved, untitled file open (which is detected to be Nix).

I understand that this is an issue with NIL, but would it be best for the extension to not pass invalid file URIs?

[Error - 2:12:44 PM] Client Nix: connection to server is erroring. Shutting down server.
[Error - 2:12:44 PM] Connection to server got closed. Server will not be restarted.
[Error - 2:12:44 PM] Stopping server failed
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 2:12:44 PM] Stopping server failed
  Message: Pending response rejected since connection got disposed
  Code: -32097 
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: "SendError(..)"', /build/cargo-vendor-dir/lsp-server-0.7.0/src/stdio.rs:29:37
stack backtrace:
2023-02-04T21:12:44.371058Z ERROR nil: Unexpected error: Non-file URI: untitled:Untitled-1
Non-file URI: untitled:Untitled-1

Antiquotation inside paths is broken

As of Nix 2.4, antiquotations are allowed in paths. The only restriction is the path must contain a slash prior to any antiquotations. This means that ./${foo}-${bar}.nix is a valid path, whereas a.${foo}/b.${bar} is a division operation.

The syntax currently does not know about this. It accepts antiquotations in paths under some conditions by parsing it as a different sequence of tokens, e.g. it will accept import /${x}/bar, which it appears to be doing by parsing the / as a division operator and then accepting ${x}/bar as an argument for no good reason. It also takes import ./${x}/bar, although in this case adding the space like import ./ ${x}/bar produces an error and I'm not quite sure what's going on with this parse. When used as the RHS of a let-binding it will highlight the leading / or ./ as invalid (but will not mark this as an error).

However, what is a hard error is stuff like /${x}.nix. This construct doesn't just highlight the .nix as wrong, it highlights the entire rest of the file too. This is really frustrating as antiquotations in paths is far more convenient than concatenating with +. It's also annoying to have things like ./${x}/bar have their prefix highlighted as invalid, but that's at least tolerable as there's no error placed there. The error I get with /${x}.nix is bad enough that it makes this whole syntax feature unusable.

How do I enable NixOS, Flake-parts, and Home-manager options at the same time when using nixd?

The example in the README is not very clear on this. Copying this example leads to the obvious duplicate key errors, but there's also the <name> part. Is this supposed to be my username? Should it be .<myname>. or .myname.? Thanks

Relevant config:

"nix.serverSettings": {
    // settings for 'nixd' LSP
    "formatting": {
        "command": "nixpkgs-fmt"
    },
    "options": {
        "enable": true,
        "target": {
            // tweak arguments here
            "args": [],
            // NixOS options
            "installable": "<flakeref>#nixosConfigurations.<name>.options",
            // Flake-parts options
            "installable": "<flakeref>#debug.options",
            // Home-manager options
            "installable": "<flakeref>#homeConfigurations.<name>.options"
        }
    }
}

Can't make it use treefmt

Working on dream2nix, have direnv installed and working in the shell and in other vscode projects; it uses treefmt for formatting.

I set the workspace nix.formatter to treefmt and it keeps using my previous one until I reload the window. I assume

const FORMATTER = config.formatterPath;
needs to be resolved at format time instead of at module load time.

But after reloading the window, it doesn't format at all. Passing treefmt or the full path (+reload) doesn't make a difference, vscode now says there's no formatter for nix files installed.

Get `Failed to run nixpkgs-fmt: spawn nixpkgs-fmt ENOENT` error

Every time I save a file (default.nix) in my case, I get above error. I have Nix installed on macOS. This nix code from the file formats perfectly well with https://nix-community.github.io/nixpkgs-fmt/ so it's something with extension not working.

I actually tested it myself on my macOS terminal and got:

โฏ nixpkgs-fmt default.nix
default.nix
1 / 1 have been reformatted

So something is going wrong in VSCode, can I see the logs somewhere?

Making Formatter Path Configurable

Currently, nixpkgs-fmt is hard coded as the formatter for all nix files. Ideally, it should be configurable to allow things like nixfmt to be used as a drop-in replacements.

Path click navigate to current sources

When I build and run via nix, it see in console in case of failure of my code:

/nix/store/<hash>-foobar/my.ts
error: failed

my.ts is located in my my current local git folder in root (or it can be any other subfolder).

When I click file path it jumps to store copy.

Is it possible to make ability to jump to original file from which store one was created for editing?

Or some command to jump from store to local if stored opened first?

Will donate 5 DOT for this feature.

keywords whitespace is not included in syntax checker

image
as you can see, it seems like rec is being counted as keyword, nix parse this correctly, but this ext does not

I assume its a problem in /syntaxes/nix.YAML-tmLanguage sections of line 607 or 114
or,
a general case for all keywords, I'm not used to its syntax

Feature: Path intellisense

I'd like to track the path intellisense feature (mentioned in README) and there didn't seem to be an issue doing so yet :)

I would like to give this a crack, but looking through https://github.com/ChristianKohler/PathIntellisense (and having never written a VS Code extension), it isn't obvious to me what is stopping that plugin from activating in .nix files and/or how this plugin should invoke/prompt the path intellisense plugin.

Incorrect handling of # within strings

See screenshot:

image

Seems like the grammar assumes that any # automatically turns the rest of the line into a comment, regardless of the context. But this is not true within a string:

nix-repl> foo = "#foo" 

nix-repl> foo
"#foo"

Auto Fetch Flake Inputs

auto-fetch

I see this across all my Nix repositories but cannot find the configuration setting in the docs or plugin codebase.

Can you provide a full list of all configuration settings in the documentation?

.vscode/settings.json

{
  "nix.enableLanguageServer": true,
  "nix.serverPath": "nil",
  "nix.formatterPath": "nixpkgs-fmt",
  "nix.serverSettings": {
    "nil": {
      "diagnostics": {
        "ignored": [
          "unused_binding",
          "unused_with"
        ]
      },
      "formatting": {
        "command": [
          "nixpkgs-fmt"
        ]
      }
    }
  }
}

Incorrect syntax highlighting for long comments

test case:

{ sha256 = /*/ lib.fakeSha256 /**/ "sha256-QFBRG/xsV7FI0+sYudxIMxx8wm6UFbbkftDSrKqpZig="; } # incorrect
{ sha256 = /*/ lib.fakeSha256 / **/ "sha256-QFBRG/xsV7FI0+sYudxIMxx8wm6UFbbkftDSrKqpZig="; } # incorrect
{ sha256 = /*/ lib.fakeSha256 /* */ "sha256-QFBRG/xsV7FI0+sYudxIMxx8wm6UFbbkftDSrKqpZig="; } # correct

see also:

version info:

  • jnoortheen.nix-ide v0.2.2
  • VSCodium

Version: 1.78.2
Release: 23132
Commit: e06ea6147733c975d26c3d3552462681e05cb147
Date: 2023-05-12T00:42:22.773Z
Electron: 22.3.5
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Linux x64 6.1.38
Sandboxed: No

`punctuation.definition.attrset-or-function.nix` doesn't allow antiquotation as first key

If I have an attrset with a newline after the { in a position that admits functions, this is scoped as punctuation.definition.attrset-or-function.nix. In this context, if the first key is an antiquotation, it flags this as a syntax error. Besides being an incorrect error, this can cause the rest of the file to tokenize incorrectly as well.

As an example, see lib/generators.nix in nixpkgs. This also highlights incorrectly in GitHub of course. Sample extract:

{
  # โ€ฆ
  recurse = path: value:
    # โ€ฆ
    if length path > 1 then {
      ${concatStringsSep "." (lib.reverseList (tail path))}.${head path} = value;
    } else {
      ${head path} = value;
    };
}

In this example, the rest of the line ends up being treated as inside a double-quoted string, and so the rest of the file is highlighted incorrectly.

This particular issue is actually something I fixed in my vscode-nix fork a year ago, see lilyball/vscode-nix@2a7db0f, but I'm not in a position to port this to vscode-nix-ide or open any PRs at the moment.

Contribute to nix-community?

I started working on a similar project over the weekend (JamieMagee/vscode-nix), and I just discovered your project as well! I don't really want to duplicate any effort, so I think I should contribute to your extension instead.

I was wondering if you would consider re-homing your extension to nix-community and maintaining it there? There was an ask to do this on the existing extension (bbenoist/vscode-nix#6), but the maintainer there appears to be missing. I think that with your extension, the community could more easily contribute (I know I would) and it would be more discoverable for Nix users.

What do you think?

Command to restart language server

Sometimes I'll get a notification saying the language server crashed 5 times in the past 3 minutes and will not be restarted1. I can't find any way to restart the language server without reloading the whole window. Perhaps this extension could offer a command for the command palette to restart the language server?

Footnotes

  1. When I check it's always due to calling Result::unwrap() on an Err value, usually "EOF while parsing a value" though not always. โ†ฉ

Can we call `nix-instantiate` without `--parse`?

In linter.ts#L95, we call nix-instantiate with the --parse argument.
If we omit it, we will also get diagnosis for things like pkgs.foozz doesn't exist.
Currently it only analyzes syntatical errors like misplaced semicolons/parens etc and missing top-level variables.

Other than the fact that omiting --parse is slow, is there any other reason we can't use that?
nix-instantiate takes 1.4s to execute on my machine. Whereas, nix-instantiate --parse only takes 0.1s.

If there are no other issues, I think I'll be able to do a PR that runs nix-instantiate --parse first, and then fires off nix-instantiate in the background and update the output once it completes.

Commenting a line of code uses `//` instead of `#`

When I edit a nix file and execute the 'Add Line Comment' through the command palette, it adds // in front of the line. That's not a valid nix comment though. It should add # .

Also, I'm not sure whether the commenting logic is done by this extension or by nil, the language server that I'm using. So maybe this is a nil bug? How do I find out?

Support passing custom LSP settings to the server

Currently we doesn't pass any LSP settings to the server.

const serverExecutable: Executable = {
command: config.serverPath,
};
const serverOptions: ServerOptions = serverExecutable;

But nil LSP needs settings to enable some functionalities, like formatting requires nil.formatting.command: [string].

Maybe we should accepts an untyped settings nix.lspSettings or nix.nilSettings to allow users to customize server options. And also be future-proof.

Related: oxalica/nil#24

Syntax highlighting doesn't work

let
  pkgs = import (builtins.fetchTarball {
    # nixos unstable
    url = "https://github.com/nixos/nixpkgs-channels/tarball/a31736120c5de6e632f5a0ba1ed34e53fc1c1b00";
    sha256 = "0xfjizw6w84w1fj47hxzw2vwgjlszzmsjb8k8cgqhb379vmkxjfl";
  }) {config = {}; overlays = [];};
  vscode-nix-ide = builtins.fetchGit {
    url = "https://github.com/nix-community/vscode-nix-ide";
    rev = "699c803e056d9ef080061c211ace0518dbcb4fc4";
  };
  codium-nix = pkgs.writeScriptBin "codium-nix" ''
    #!/usr/bin/env bash
    ${pkgs.vscodium}/bin/codium --extensions-dir ${
      pkgs.runCommand "extensions-dir" { buildInputs = [ vscode-nix-ide ]; } ''
        mkdir $out
        cp -r ${vscode-nix-ide} $out/vscode-nix-ide
      ''
    } --user-data-dir $(pwd)/.data $@
  '';
in
pkgs.mkShell {
  buildInputs = [ codium-nix ];
}

Inside this shell, run codium-nix. The extension is enabled in the settings, but doesn't seem to do anything

Failing to load LSP

I love this extension, and I use it for developing rnix-lsp.

I noticed that on v0.1.12, the extension works as expected. However, after updating to v0.1.15, the LSP fails to load. I see the following error message in Log (Extension Host), which is resolved by rolling back to v0.1.12:

[2021-08-19 10:38:55.611] [exthost] [error] Error: Cannot find module 'vscode-languageclient/node'
Require stack:
- /home/ajanse/.vscode/extensions/jnoortheen.nix-ide-0.1.15/dist/client.js
- /home/ajanse/.vscode/extensions/jnoortheen.nix-ide-0.1.15/dist/extension.js
- /nix/store/gdzyg1lc5rxvm3rghnc3anjip5h5bn2q-vscode-1.57.1/lib/vscode/resources/app/out/vs/loader.js
- /nix/store/gdzyg1lc5rxvm3rghnc3anjip5h5bn2q-vscode-1.57.1/lib/vscode/resources/app/out/bootstrap-amd.js
- /nix/store/gdzyg1lc5rxvm3rghnc3anjip5h5bn2q-vscode-1.57.1/lib/vscode/resources/app/out/bootstrap-fork.js
	at Function.Module._resolveFilename (internal/modules/cjs/loader.js:934:15)
	at Module._load (internal/modules/cjs/loader.js:779:27)
	at Function.f._load (electron/js2c/asar_bundle.js:5:12684)
	at Function.n._load (/nix/store/gdzyg1lc5rxvm3rghnc3anjip5h5bn2q-vscode-1.57.1/lib/vscode/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:103:27815)
	at Function.E._load (/nix/store/gdzyg1lc5rxvm3rghnc3anjip5h5bn2q-vscode-1.57.1/lib/vscode/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:103:24567)
	at Function.c._load (/nix/store/gdzyg1lc5rxvm3rghnc3anjip5h5bn2q-vscode-1.57.1/lib/vscode/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:93:59196)
	at Module.require (internal/modules/cjs/loader.js:1006:19)
	at v (/nix/store/gdzyg1lc5rxvm3rghnc3anjip5h5bn2q-vscode-1.57.1/lib/vscode/resources/app/out/vs/loader.js:4:698)
	at Object.<anonymous> (/home/ajanse/.vscode/extensions/jnoortheen.nix-ide-0.1.15/dist/client.js:15:16)
	at Module.u._compile (/nix/store/gdzyg1lc5rxvm3rghnc3anjip5h5bn2q-vscode-1.57.1/lib/vscode/resources/app/out/vs/loader.js:4:1315)
	at Object.Module._extensions..js (internal/modules/cjs/loader.js:1155:10)
	at Module.load (internal/modules/cjs/loader.js:982:32)
	at Module._load (internal/modules/cjs/loader.js:823:14)
	at Function.f._load (electron/js2c/asar_bundle.js:5:12684)
	at Function.n._load (/nix/store/gdzyg1lc5rxvm3rghnc3anjip5h5bn2q-vscode-1.57.1/lib/vscode/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:103:27815)
	at Function.E._load (/nix/store/gdzyg1lc5rxvm3rghnc3anjip5h5bn2q-vscode-1.57.1/lib/vscode/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:103:24567)
	at Function.c._load (/nix/store/gdzyg1lc5rxvm3rghnc3anjip5h5bn2q-vscode-1.57.1/lib/vscode/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:93:59196)
	at Module.require (internal/modules/cjs/loader.js:1006:19)
	at v (/nix/store/gdzyg1lc5rxvm3rghnc3anjip5h5bn2q-vscode-1.57.1/lib/vscode/resources/app/out/vs/loader.js:4:698)
	at Object.<anonymous> (/home/ajanse/.vscode/extensions/jnoortheen.nix-ide-0.1.15/dist/extension.js:17:16)
	at Module.u._compile (/nix/store/gdzyg1lc5rxvm3rghnc3anjip5h5bn2q-vscode-1.57.1/lib/vscode/resources/app/out/vs/loader.js:4:1315)
	at Object.Module._extensions..js (internal/modules/cjs/loader.js:1155:10)
	at Module.load (internal/modules/cjs/loader.js:982:32)
	at Module._load (internal/modules/cjs/loader.js:823:14)
	at Function.f._load (electron/js2c/asar_bundle.js:5:12684)
	at Function.n._load (/nix/store/gdzyg1lc5rxvm3rghnc3anjip5h5bn2q-vscode-1.57.1/lib/vscode/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:103:27815)
	at Function.E._load (/nix/store/gdzyg1lc5rxvm3rghnc3anjip5h5bn2q-vscode-1.57.1/lib/vscode/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:103:24567)
	at Function.c._load (/nix/store/gdzyg1lc5rxvm3rghnc3anjip5h5bn2q-vscode-1.57.1/lib/vscode/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:93:59196)
	at Module.require (internal/modules/cjs/loader.js:1006:19)
	at require (internal/modules/cjs/helpers.js:88:18)
	at Function.t [as __$__nodeRequire] (/nix/store/gdzyg1lc5rxvm3rghnc3anjip5h5bn2q-vscode-1.57.1/lib/vscode/resources/app/out/vs/loader.js:5:101)
	at m._loadCommonJSModule (/nix/store/gdzyg1lc5rxvm3rghnc3anjip5h5bn2q-vscode-1.57.1/lib/vscode/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:103:25973)
	at m._doActivateExtension (/nix/store/gdzyg1lc5rxvm3rghnc3anjip5h5bn2q-vscode-1.57.1/lib/vscode/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:89:12617)
	at m._activateExtension (/nix/store/gdzyg1lc5rxvm3rghnc3anjip5h5bn2q-vscode-1.57.1/lib/vscode/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:89:11676)
	at processTicksAndRejections (internal/process/task_queues.js:93:5)
	at async Promise.all (index 0)

Does not load with Remote SSH connection

I'm using a local VS Code on macOS to connect to a remote NixOS server using the Remote - SSH extension.

I have NixIDE installed on my local VS Code and in the SSH remote. Locally it works properly, but when opening a remote project I see this in the "Log (Remote Extension Host)":

[2022-02-03 22:12:51.470] [exthost] [error] Activating extension jnoortheen.nix-ide failed due to an error:
[2022-02-03 22:12:51.470] [exthost] [error] null

Command nil not found in $PATH

I have installed nil and added it to the $PATH. But the vscode Nix IDE extension still shows Command nil not found in $PATH.

I also checked the integrated terminal in vscode and it shows the nil in the PATH:

image

Any suggestions here? Below is my settings:

  "nix.enableLanguageServer": true,
  "nix.serverPath": "nil",
  "nix.formatterPath": "nixpkgs-fmt",

Thank you!

Mark unused attributes?

I'm wondering if this extension can somehow leverage rnix-lsp to find out which attributes are unused in an expression.

Example:

let a=5; b=true; in b

would mark a as unused.

Frequently getting `Request textDocument/documentSymbol failed`

I'm frequently getting this error while typing. Not really sure why.

[Error - 8:49:21 PM] Request textDocument/documentSymbol failed.
Error: name must not be falsy
	at d.validate (/nix/store/s7accqb6id4p71p56mr5hb4vay0cnj1c-vscode-1.88.1/lib/vscode/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:150:17471)
	at new d (/nix/store/s7accqb6id4p71p56mr5hb4vay0cnj1c-vscode-1.88.1/lib/vscode/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:150:17766)
	at Qt (/nix/store/qqgl0yg1c5j0dawqm3xzzvjg72bl5c6q-vscode-extension-jnoortheen-nix-ide-0.3.1/share/vscode/extensions/jnoortheen.nix-ide/dist/extension.js:35:72226)
	at Qt (/nix/store/qqgl0yg1c5j0dawqm3xzzvjg72bl5c6q-vscode-extension-jnoortheen-nix-ide-0.3.1/share/vscode/extensions/jnoortheen.nix-ide/dist/extension.js:35:72403)
	at Qt (/nix/store/qqgl0yg1c5j0dawqm3xzzvjg72bl5c6q-vscode-extension-jnoortheen-nix-ide-0.3.1/share/vscode/extensions/jnoortheen.nix-ide/dist/extension.js:35:72403)
	at Qt (/nix/store/qqgl0yg1c5j0dawqm3xzzvjg72bl5c6q-vscode-extension-jnoortheen-nix-ide-0.3.1/share/vscode/extensions/jnoortheen.nix-ide/dist/extension.js:35:72403)
	at Qt (/nix/store/qqgl0yg1c5j0dawqm3xzzvjg72bl5c6q-vscode-extension-jnoortheen-nix-ide-0.3.1/share/vscode/extensions/jnoortheen.nix-ide/dist/extension.js:35:72403)
	at o (/nix/store/qqgl0yg1c5j0dawqm3xzzvjg72bl5c6q-vscode-extension-jnoortheen-nix-ide-0.3.1/share/vscode/extensions/jnoortheen.nix-ide/dist/extension.js:35:46654)
	at Object.GC [as map] (/nix/store/qqgl0yg1c5j0dawqm3xzzvjg72bl5c6q-vscode-extension-jnoortheen-nix-ide-0.3.1/share/vscode/extensions/jnoortheen.nix-ide/dist/extension.js:35:46740)
	at Object.Bn [as asDocumentSymbols] (/nix/store/qqgl0yg1c5j0dawqm3xzzvjg72bl5c6q-vscode-extension-jnoortheen-nix-ide-0.3.1/share/vscode/extensions/jnoortheen.nix-ide/dist/extension.js:35:72193)
	at u (/nix/store/qqgl0yg1c5j0dawqm3xzzvjg72bl5c6q-vscode-extension-jnoortheen-nix-ide-0.3.1/share/vscode/extensions/jnoortheen.nix-ide/dist/extension.js:39:56050)
	at async d.provideDocumentSymbols (/nix/store/s7accqb6id4p71p56mr5hb4vay0cnj1c-vscode-1.88.1/lib/vscode/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:152:90504)

Request textDocument/hover failed (with Nil)

On hover on anything in a nix flake file in VSC I receive this error:

image

My Nix IDE settings:

  "nix.enableLanguageServer": true, // Enable LSP.
  "nix.serverPath": "nil", // The path to the LSP server executable.
  "nix.serverSettings": {
    "nil": {
      "formatting": { "command": ["alejandra"] }
    }
  }
$ nil --version
nil 2023-02-03
Output

thread 'Worker' panicked at 'no value set for FlakeGraphQuery(())', /private/tmp/nix-build-nil-2023-02-03.drv-0/nil-2023-02-03-vendor.tar.gz/salsa/src/input.rs:106:32
stack backtrace:
0: _rust_begin_unwind
1: core::panicking::panic_fmt
2: <salsa::input::InputStorage as salsa::plumbing::QueryStorageOps>::try_fetch
3: ::flake_graph::__shim
4: <ide::base::SourceRootFlakeInfoQuery as salsa::plumbing::QueryFunction>::execute
5: salsa::runtime::Runtime::execute_query_implementation
6: salsa::derived::slot::Slot<Q,MP>::read_upgrade
7: salsa::derived::slot::Slot<Q,MP>::read
8: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps>::try_fetch
9: ::source_root_flake_info::__shim
10: <ide::def::ModuleKindQuery as salsa::plumbing::QueryFunction>::execute
11: salsa::runtime::Runtime::execute_query_implementation
12: salsa::derived::slot::Slot<Q,MP>::read_upgrade
13: salsa::derived::slot::Slot<Q,MP>::read
14: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps>::try_fetch
15: ::module_kind::__shim
16: <ide::ty::ModuleExpectedTyQuery as salsa::plumbing::QueryFunction>::execute
17: salsa::runtime::Runtime::execute_query_implementation
18: salsa::derived::slot::Slot<Q,MP>::read_upgrade
19: salsa::derived::slot::Slot<Q,MP>::read
20: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps>::try_fetch
21: ::module_expected_ty::__shim
22: ide::ty::infer::infer_query
23: salsa::runtime::Runtime::execute_query_implementation
24: salsa::derived::slot::Slot<Q,MP>::read_upgrade
25: salsa::derived::slot::Slot<Q,MP>::read
26: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps>::try_fetch
27: ::infer::__shim
28: ide::ide::hover::hover
29: ide::ide::Analysis::hover
30: nil::handler::hover
31: std::panicking::try
32: core::ops::function::FnOnce::call_once{{vtable.shim}}
33: nil::server::Server::worker
note: Some details are omitted, run with RUST_BACKTRACE=full for a verbose backtrace.
2023-03-04T01:48:39.305034Z ERROR nil::server: Panicked in textDocument/hover: no value set for FlakeGraphQuery(())
Location: /private/tmp/nix-build-nil-2023-02-03.drv-0/nil-2023-02-03-vendor.tar.gz/salsa/src/input.rs:106:32
Backtrace: 0: 0x105243d54 - std::backtrace::Backtrace::create::h21e81d81bdd55ba7
1: 0x10504f670 - nil::server::with_catch_unwind::{{closure}}::{{closure}}::h0106fd83172da2c7
2: 0x10521b988 - std::panicking::rust_panic_with_hook::h4fd621c91a468c7f
3: 0x105221f80 - std::panicking::begin_panic_handler::{{closure}}::he01d096e07de0ad7
4: 0x105221acc - std::sys_common::backtrace::__rust_end_short_backtrace::h9ae8acbb3142fca8
5: 0x10521b4d8 - _rust_begin_unwind
6: 0x10527baf8 - core::panicking::panic_fmt::h57ba5f760604e990
7: 0x10516ab5c - <salsa::input::InputStorage as salsa::plumbing::QueryStorageOps>::try_fetch::h5aced266cb1723fa
8: 0x10513dae4 - ::flake_graph::__shim::h1c745908acf363ba
9: 0x10513dd1c - <ide::base::SourceRootFlakeInfoQuery as salsa::plumbing::QueryFunction>::execute::h900db813d7235463
10: 0x10511ad90 - salsa::runtime::Runtime::execute_query_implementation::h4d2cdb3dd9a8f261
11: 0x1050f1f1c - salsa::derived::slot::Slot<Q,MP>::read_upgrade::h0e1ee44308bfa9ba
12: 0x10510c22c - salsa::derived::slot::Slot<Q,MP>::read::hc4854ee782a42d46
13: 0x105154388 - <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps>::try_fetch::ha43b54a75b6f52d4
14: 0x10513d938 - ::source_root_flake_info::__shim::hcd8eb6024dd49888
15: 0x10513f4e8 - <ide::def::ModuleKindQuery as salsa::plumbing::QueryFunction>::execute::hc3ac4c15077acbfb
16: 0x10511ba70 - salsa::runtime::Runtime::execute_query_implementation::hd487263aefc4afa4
17: 0x1050fdb8c - salsa::derived::slot::Slot<Q,MP>::read_upgrade::he4053e2a02704a43
18: 0x10510cbe8 - salsa::derived::slot::Slot<Q,MP>::read::hdcc73f4f21548ae8
19: 0x1051533c0 - <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps>::try_fetch::h996247433401e59f
20: 0x10513e738 - ::module_kind::__shim::had42e7488ca744ad
21: 0x10517d49c - <ide::ty::ModuleExpectedTyQuery as salsa::plumbing::QueryFunction>::execute::h22ea1b7789e4fe17
22: 0x10511a9a4 - salsa::runtime::Runtime::execute_query_implementation::h375b324eae29cc6d
23: 0x1050f4a90 - salsa::derived::slot::Slot<Q,MP>::read_upgrade::h2d4489be5bccd836
24: 0x10510863c - salsa::derived::slot::Slot<Q,MP>::read::h16fe165762438542
25: 0x105150b88 - <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps>::try_fetch::h4d7c486d8584cb19
26: 0x10517d300 - ::module_expected_ty::__shim::h3935a77d38110fbd
27: 0x10513a5fc - ide::ty::infer::infer_query::hae5e7fe49551563c
28: 0x10511b138 - salsa::runtime::Runtime::execute_query_implementation::h68ce30569bee21da
29: 0x1050f7724 - salsa::derived::slot::Slot<Q,MP>::read_upgrade::h36d29e4de67a7eca
30: 0x105109050 - salsa::derived::slot::Slot<Q,MP>::read::h27a7ae1922f542c4
31: 0x105153ba4 - <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps>::try_fetch::h9dd925e35d15b1c1
32: 0x10517d3e4 - ::infer::__shim::h340e15f1b650b184
33: 0x10517a67c - ide::ide::hover::hover::h5e35b300829e66db
34: 0x10516cda4 - ide::ide::Analysis::hover::h6cf21156b2908ef4
35: 0x105072114 - nil::handler::hover::h81cec957d584c3fe
36: 0x1050540a8 - std::panicking::try::h1812a2daeacfc2e8
37: 0x10503f5e8 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h4e17771df77439b5
38: 0x105048070 - nil::server::Server::worker::hafad0785ea22951b
39: 0x105029288 - std::sys_common::backtrace::__rust_begin_short_backtrace::h37336cd76b47ad2f
40: 0x105055f44 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h05197e50149f44d6
41: 0x105232358 - std::sys::unix::thread::Thread::new::thread_start::hb3139456ed8bbfa5
42: 0x195b3606c - __pthread_deallocate

[Error - 02:48:39] Request textDocument/hover failed.
Message: Panicked in textDocument/hover: no value set for FlakeGraphQuery(())
Location: /private/tmp/nix-build-nil-2023-02-03.drv-0/nil-2023-02-03-vendor.tar.gz/salsa/src/input.rs:106:32
Backtrace: 0: 0x105243d54 - std::backtrace::Backtrace::create::h21e81d81bdd55ba7
1: 0x10504f670 - nil::server::with_catch_unwind::{{closure}}::{{closure}}::h0106fd83172da2c7
2: 0x10521b988 - std::panicking::rust_panic_with_hook::h4fd621c91a468c7f
3: 0x105221f80 - std::panicking::begin_panic_handler::{{closure}}::he01d096e07de0ad7
4: 0x105221acc - std::sys_common::backtrace::__rust_end_short_backtrace::h9ae8acbb3142fca8
5: 0x10521b4d8 - _rust_begin_unwind
6: 0x10527baf8 - core::panicking::panic_fmt::h57ba5f760604e990
7: 0x10516ab5c - <salsa::input::InputStorage as salsa::plumbing::QueryStorageOps>::try_fetch::h5aced266cb1723fa
8: 0x10513dae4 - ::flake_graph::__shim::h1c745908acf363ba
9: 0x10513dd1c - <ide::base::SourceRootFlakeInfoQuery as salsa::plumbing::QueryFunction>::execute::h900db813d7235463
10: 0x10511ad90 - salsa::runtime::Runtime::execute_query_implementation::h4d2cdb3dd9a8f261
11: 0x1050f1f1c - salsa::derived::slot::Slot<Q,MP>::read_upgrade::h0e1ee44308bfa9ba
12: 0x10510c22c - salsa::derived::slot::Slot<Q,MP>::read::hc4854ee782a42d46
13: 0x105154388 - <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps>::try_fetch::ha43b54a75b6f52d4
14: 0x10513d938 - ::source_root_flake_info::__shim::hcd8eb6024dd49888
15: 0x10513f4e8 - <ide::def::ModuleKindQuery as salsa::plumbing::QueryFunction>::execute::hc3ac4c15077acbfb
16: 0x10511ba70 - salsa::runtime::Runtime::execute_query_implementation::hd487263aefc4afa4
17: 0x1050fdb8c - salsa::derived::slot::Slot<Q,MP>::read_upgrade::he4053e2a02704a43
18: 0x10510cbe8 - salsa::derived::slot::Slot<Q,MP>::read::hdcc73f4f21548ae8
19: 0x1051533c0 - <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps>::try_fetch::h996247433401e59f
20: 0x10513e738 - ::module_kind::__shim::had42e7488ca744ad
21: 0x10517d49c - <ide::ty::ModuleExpectedTyQuery as salsa::plumbing::QueryFunction>::execute::h22ea1b7789e4fe17
22: 0x10511a9a4 - salsa::runtime::Runtime::execute_query_implementation::h375b324eae29cc6d
23: 0x1050f4a90 - salsa::derived::slot::Slot<Q,MP>::read_upgrade::h2d4489be5bccd836
24: 0x10510863c - salsa::derived::slot::Slot<Q,MP>::read::h16fe165762438542
25: 0x105150b88 - <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps>::try_fetch::h4d7c486d8584cb19
26: 0x10517d300 - ::module_expected_ty::__shim::h3935a77d38110fbd
27: 0x10513a5fc - ide::ty::infer::infer_query::hae5e7fe49551563c
28: 0x10511b138 - salsa::runtime::Runtime::execute_query_implementation::h68ce30569bee21da
29: 0x1050f7724 - salsa::derived::slot::Slot<Q,MP>::read_upgrade::h36d29e4de67a7eca
30: 0x105109050 - salsa::derived::slot::Slot<Q,MP>::read::h27a7ae1922f542c4
31: 0x105153ba4 - <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps>::try_fetch::h9dd925e35d15b1c1
32: 0x10517d3e4 - ::infer::__shim::h340e15f1b650b184
33: 0x10517a67c - ide::ide::hover::hover::h5e35b300829e66db
34: 0x10516cda4 - ide::ide::Analysis::hover::h6cf21156b2908ef4
35: 0x105072114 - nil::handler::hover::h81cec957d584c3fe
36: 0x1050540a8 - std::panicking::try::h1812a2daeacfc2e8
37: 0x10503f5e8 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h4e17771df77439b5
38: 0x105048070 - nil::server::Server::worker::hafad0785ea22951b
39: 0x105029288 - std::sys_common::backtrace::__rust_begin_short_backtrace::h37336cd76b47ad2f
40: 0x105055f44 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h05197e50149f44d6
41: 0x105232358 - std::sys::unix::thread::Thread::new::thread_start::hb3139456ed8bbfa5
42: 0x195b3606c - __pthread_deallocate

Code: -32603

Support "nix fmt" for flakes in non-project root directories?

This is kinda a specific issue that I'm having but I was hoping to use the nix fmt command to format my flake. The only problem is that my flake.nix file is not in the root directory of my project; instead it's nested in a nix/ directory, since I also want to include some non-nix stuff in this specific repository.

I have my Nix IDE plugin set up like so:

{
  "nix.enableLanguageServer": true,
  "nix.serverPath": "nil",
  "nix.serverSettings": {
    "nil": {
      "formatting": { "command": ["nix", "fmt"] }
    }
  },
  // ...
}

The language server is working fine, but when I save a Nix file, I get an error in the output:

[Error - 11:56:44 PM] Request textDocument/formatting failed.
  Message: Failed to run formatter: Process exited with exit status: 1.
path '/home/matt/projects/devmattrick/infrastructure' does not contain a 'flake.nix', searching up
error: path '/home/matt/projects/devmattrick/infrastructure' is not part of a flake (neither it nor its parent directories contain a 'flake.nix' file)

The issue is that my flake.nix (and all other .nix files) are in the nix/ directory of this project. I don't know if this is possible but I think the desired behavior of this would be to run the formatter command relative to the .nix file I'm saving instead of the VSCode project root.

Thanks for the help!


EDIT: It seems like nix fmt also doesn't accept input from stdin. nix fmt might need to be special cased since it will format the entire flake on save, which would probably be undesirable. It doesn't look like there's an easy way to tell nix fmt to "only format this one file" from what I can tell from the documentation.

Become self-contained (cut the nixpkgs-fmt dependency)

The package seems to need nixpkgs-fmt to be installed in order for code formatting to work (related forum support thread). (This seems to be completely undocumented, which is another issue, but becoming self-contained would obviate that) I think it's clear that it would be better to ship a copy of nixpkgs-fmt in the vscode extension, as it's unlikely that the user will have it installed for any other purpose.

It seems that there is a wasm version of nixpkgs-fmt, and I believe vscode can run wasm (on any platform, of course), so we could use that?

Would a pull request, making this change, be accepted?

Failed to run : The argument 'file' cannot be empty. Received ''

That's the error message I get in VSCode when I hit cmd+shift+f as usual. It used to work perfectly fine, but it doesn't any longer. I don't know what has changed.

Formatting for other file types with this shortcut works fine.

Does anyone have a clue how I can fix this? Or how to figure out what the problem is?

Syntax does not understand antiquotations inside paths

Nix 2.4 introduced the ability to put antiquotations inside path literals (release notes):

Languages changes: the only new language feature is that you can now have antiquotations in paths, e.g. ./${foo} instead of ./. + foo.

The Nix syntax definition doesn't understand this. If I write /${foo} it marks the / as either invalid.illegal or as an operator depending on context. If I write foo/bar/${baz}/wat it highlights this just like it does foo/bar / ${baz} /wat.

Consider publishing to open-vsx

The libre distribution of VS Code (VS Codium) is now by default configured to use https://open-vsx.org/ instead of the Microsoft Marketplace for licensing reasons.

https://github.com/VSCodium/vscodium/blob/master/DOCS.md#extensions-marketplace

Please consider publishing the extension there.
Wiki Guide https://github.com/eclipse/openvsx/wiki/Publishing-Extensions

Alternatively one can request their CI to publish the extension for you by adding it to the list in https://github.com/open-vsx/publish-extensions

create github actions

  • 1. to check the commit message format is in conventional commit style

  • 2. uploads to vscode extensions page upon pushing tags

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.