Skip to content

Conversation

@inclyc
Copy link
Member

@inclyc inclyc commented Nov 23, 2024

This PR introduces nix-repl's :doc command to nixd.

Since NixOS/nix#11072, we can utilize the API exposed by nix::EvalState::getDoc. (i.e. to provide hover/completions(todo) from nixpkgs's doc comments).

Current status:

  • support hovering
  • support completion-list resolve
The :doc command in nix-repl Hovering on that value

Also CC @roberth (author of nix implementation), @hsjobeki (author of doc-comments RFC). How can we co-operate to make these stuff more fancy? (It looks very ugly so far, 😆 )

I see there are some information for "definition" here, generally this information is separated from "hover-ed documentation" in LSP, can we have a new API to get a structured output?

@hsjobeki
Copy link

hsjobeki commented Nov 23, 2024

I am also in favor or just returning the content without Rendering it. Maybe as a function on the C-abi.
But it should Return a struct with content, Position, and probably more metadata.
Rendering is best done using the markdown Extensions from the documentation readme in nixpkgs.


/// TODO: use https://github.com/NixOS/nix/pull/11914 on nix version bump
/// \brief Get nix's `builtins` constant
inline nix::Value &getBuiltins(const nix::EvalState &State) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe remove, not used in this PR

constexpr inline std::string_view AttrPathComplete = "attrset/attrpathComplete";
constexpr inline std::string_view OptionInfo = "attrset/optionInfo";
constexpr inline std::string_view OptionComplete = "attrset/optionComplete";

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty


std::optional<ValueDescription> describeValue(nix::EvalState &State,
nix::Value &V) {
const auto Doc = State.getDoc(V);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nix::EvalState::getDoc() is invoked here

}

static std::string mkValueMarkdown(const ValueDescription &ValueDesc) {
return ValueDesc.Doc;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here, the documentation is replied directly without any formatting/tokenization.

@inclyc
Copy link
Member Author

inclyc commented Dec 12, 2024

kindly ping @roberth, can we have a structured helper function exposed from nix-expr?

@roberth
Copy link

roberth commented Feb 18, 2025

Hey @inclyc, sorry for the delay. Happy to help if I can, but it's not quite clear to me what needs to be done in nix-expr.
Currently the inside of the comment is not parsed, except with a markdown parser, of which I'm not even sure that it's the right parser, considering the mismatch with some extended syntax that's used in Nixpkgs.
If, on the other hand, you're looking for some improvements in the interface around the already implemented functionality, we might have some low hanging fruit to pick there.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/why-nix-will-win-and-whats-stopping-it-a-3-year-production-story/70621/42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants