nix-community / nixd

Nix language server, based on nix libraries [maintainer=@inclyc,@Aleksanaa]
https://github.com/nix-community/nixd
GNU Lesser General Public License v3.0
818 stars 25 forks source link

Implementing LSP Features for devenv.sh #587

Open k3yss opened 3 weeks ago

k3yss commented 3 weeks ago

I've been working on implementing LSP features for devenv.sh and have submitted the following proof-of-concept PRs: PR 1 and PR 2. While the current implementation works, it has the following issues:

  1. Version Compatibility: The flake is fetched from the latest master branch. This approach can cause issues for users on older versions of devenv, as they won't receive the correct completions for their version.

  2. Custom Flake Handling: devenv uses its own version of nix and a custom implementation of the flake (.devenv.flake.nix). The default builtins.getFlake doesn't work with this setup, so we need an alternative method to parse this flake.

  3. Custom Option Completion: While the current implementation works in case of the default devenv options, but in case we are defining custom option in the devenv.nix file, it won't load. The only probable solution to this, is to parse the devenv flake (.devenv.flake.nix)

Desired Solution

After discussions with the maintainers of devenv, a probable solution has been identified:

pinging @domenkozar @sandydoo for their input on this discussion

inclyc commented 2 weeks ago

I'm glad to accept PRs to get language support for devenv.

  • Another option discussed is enabling nixd to support a JSON format that could be generated dynamically and provided to the LSP.

I don't think it is a good idea to open general dynamic settings in configuration, otherwise finally we will invent a broken LISP interpreter. If this is necessary, then it should be devenv-specific at first.

  • We could introduce a command, such as devenv autocomplete-options, that generates the required data structure for nixd.

The solution LGTM, I kindly ask what is that "required data structure"?