Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value doc #625

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Value doc #625

wants to merge 3 commits into from

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.

@@ -70,4 +70,10 @@ selectStringViews(nix::EvalState &State, nix::Value &V,
return selectSymbols(State, V, toSymbols(State.symbols, AttrPath));
}

/// 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

@@ -31,6 +32,7 @@ constexpr inline std::string_view AttrPathInfo = "attrset/attrpathInfo";
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

@@ -87,6 +87,10 @@ class NixpkgsHoverProvider {
return OS.str();
}

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.

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.

2 participants