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
808 stars 25 forks source link

Jump‐to‐definition for packages, library functions and options #538

Open emilazy opened 1 month ago

emilazy commented 1 month ago

Is your feature request related to a problem? Please describe. Using Nix, especially working on Nixpkgs, involves an awful lot of grepping over the Nixpkgs code to find definitions. It would be great to have it in the editor instead.

Describe the solution you'd like I think there are some pretty simple heuristics that would work for the majority of cases here:

This could also enable documentation‐on‐hover for these (nixdoc for library functions, description/longDescription/etc. for packages, and the native option documentation), which would be fantastic!

Describe alternatives you've considered Continue getting really fast at using ripgrep :)

inclyc commented 1 month ago

Hi @emilazy ,

Thanks for suggestions on this project ❤️ .

Currently nixd-attrs-eval is used for evaluating "nixpkgs" attribute set. It is basically working except lib completion, and I think lib will not be very difficult.

pkgs.‹name› could be assumed to point to a Nixpkgs package definition if the package

Yes, supporting selection effectively resolves this.

This could also enable documentation‐on‐hover for these (nixdoc for library functions,

I see, it is generally ugly to have nixdoc as an external source for documentation. Why not just read that file again by ourselves? AFAIK nixdoc is based on rnix-parser and the parser is not really maintained.

the native option documentation)

What is the "native" option documentation?

Continue getting really fast at using ripgrep :)

No, that's not an alternative 😄 . This project exists, and aims to replace "grepping" technology used in nix community for years. Theoretically programming languages cannot be fully analyzed without "AST", not just DFAs (regexp).

emilazy commented 1 month ago

I see, it is generally ugly to have nixdoc as an external source for documentation. Why not just read that file again by ourselves? AFAIK nixdoc is based on rnix-parser and the parser is not really maintained.

Ah, I just meant the RFC 145 comment syntax / CommonMark format / etc. used by nixdoc; I should probably have said that instead. That would be the standard for documenting “library values” (as opposed to options or packages).

What is the "native" option documentation?

The type/description/default{,Text}/example{,Text} option attributes, like the option documentation in the manual shows.

inclyc commented 1 month ago

option attributes, like the option documentation in the manual shows.

I suppose this feature has already implemented in https://github.com/nix-community/nixd/pull/526 ?

emilazy commented 1 month ago

Ah, so it is! Maybe there’s some issue with my editor integration that made it seem not to work, or maybe it’s just because of the ambiguous option sets I have in my configuration. I’ll report an issue if I manage to reproduce it.