Skip to content

feat(code-action): add code action to open noogle.dev docs for lib functions#764

Merged
inclyc merged 4 commits into
mainfrom
feature/code-actions-5
Jan 9, 2026
Merged

feat(code-action): add code action to open noogle.dev docs for lib functions#764
inclyc merged 4 commits into
mainfrom
feature/code-actions-5

Conversation

@takeokunn

@takeokunn takeokunn commented Jan 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add a new code action to open noogle.dev documentation for lib.* function paths directly from the editor.

When the cursor is on a lib.X or lib.X.Y.Z expression, the action opens the corresponding noogle.dev documentation page in the user's browser via window/showDocument.

Example:

  • lib.optionalString → Opens https://noogle.dev/f/lib/optionalString
  • lib.strings.optionalString → Opens https://noogle.dev/f/lib/strings/optionalString

Changes

File Description
nixd/include/nixd/Controller/Controller.h Add onCodeActionResolve handler and ShowDocument callback
nixd/lib/Controller/CodeAction.cpp Add buildNoogleUrl() and addNoogleDocAction() functions
nixd/lib/Controller/Support.cpp Register codeAction/resolve and window/showDocument methods
nixd/lspserver/include/lspserver/Protocol.h Add CodeAction.data, ShowDocumentParams, ShowDocumentResult
nixd/lspserver/src/Protocol.cpp JSON serialization for new protocol types

Behavior

Action offered when:

  • Cursor is on an ExprSelect with base variable lib
  • Path contains at least one static attribute name

Action NOT offered when:

  • Just lib variable without selection
  • Dynamic attributes (e.g., lib.${x})
  • Non-lib bases (e.g., pkgs.hello)

Test Plan

  • noogle-lib-simple.md - Basic lib.X path
  • noogle-lib-nested.md - Nested lib.X.Y path
  • noogle-lib-var-only.md - Negative: just lib variable
  • noogle-not-lib.md - Negative: non-lib select
CleanShot 2026-01-08 at 22 15 19@2x

Related

@inclyc inclyc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since we have a growing number of code actions and their functionalities are quite independent, I suggest we create a dedicated CodeActions subdirectory under Controller. We could then move each action into its own file. I'd recommend doing the same for the test directory as well, since the test files are starting to get a bit crowded, WDYT?

@takeokunn

Copy link
Copy Markdown
Collaborator Author

@inclyc
Sounds good to me. I'll go ahead with this PR for now and tackle the reorganization in the next one. I've got this!

@takeokunn takeokunn force-pushed the feature/code-actions-5 branch from fadb950 to 73a4136 Compare January 8, 2026 12:38
@takeokunn takeokunn changed the title [wip] feat(code-action): add code action to open noogle.dev docs for lib functions feat(code-action): add code action to open noogle.dev docs for lib functions Jan 8, 2026
@takeokunn takeokunn marked this pull request as ready for review January 8, 2026 12:39
…nctions

Add a new code action to open noogle.dev documentation for `lib.*`
function paths directly from the editor.

When the cursor is on a `lib.X` or `lib.X.Y.Z` expression, the action
opens the corresponding noogle.dev documentation page in the user's
browser via `window/showDocument`.

Examples:
- lib.optionalString → Opens https://noogle.dev/f/lib/optionalString
- lib.strings.optionalString → Opens https://noogle.dev/f/lib/strings/optionalString

Implementation includes:
- `addNoogleDocAction`: Provides code actions for lib.* paths
- `buildNoogleUrl`: Constructs noogle.dev URLs for function paths
- `onCodeActionResolve`: Triggers documentation display via window/showDocument
- Protocol serialization updates for CodeAction.data field
- Registration of codeAction/resolve and window/showDocument methods
@takeokunn takeokunn force-pushed the feature/code-actions-5 branch from 73a4136 to b553207 Compare January 8, 2026 12:47
- Add externalUri field to ShowDocumentParams for non-file URIs
- Update serialization to prefer externalUri over uri when set
- Adjust code actions to use externalUri for external links
- Enable resolveProvider and refactor codeActionKinds in LifeTime
@takeokunn takeokunn requested a review from inclyc January 8, 2026 13:27
@takeokunn takeokunn marked this pull request as ready for review January 8, 2026 13:27

@inclyc inclyc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall, this PR LGTM, but I think there are a few points that could be improved:

  1. Support for with scopes: Variables introduced via with (e.g., with lib; mkAfter), which are essentially members of lib, don't seem to be supported yet.
  2. Hover Integration: I usually expect to see "open docs" within the hover content (when mousing over). It might be worth checking nixd#745 to see if we can share some common code between "open in noogle" and that implementation.

@takeokunn

Copy link
Copy Markdown
Collaborator Author

Thanks review! You're right, so I'll fix it.

@inclyc

inclyc commented Jan 8, 2026

Copy link
Copy Markdown
Member

The current handling of with scopes via mkSelector feels overly complex for this project. Also, feel free to review #745 and consider whether it's ready to be merged. :)

@takeokunn

Copy link
Copy Markdown
Collaborator Author

Understood.
I agree that merging this first and then opening a follow-up PR is the best way to move forward.
If everything looks good to you, go ahead and merge it.

@takeokunn takeokunn requested a review from inclyc January 9, 2026 05:04
@inclyc inclyc merged commit b7ad03e into main Jan 9, 2026
19 checks passed
@inclyc inclyc deleted the feature/code-actions-5 branch January 9, 2026 05:06
@inclyc inclyc added enhancement New feature or request nixd:controller labels Jan 9, 2026
takeokunn added a commit that referenced this pull request Jan 9, 2026
…ed files

Extract code action implementations from CodeAction.cpp into a dedicated
CodeActions/ subdirectory with separate files for each action type:

- AttrName.{h,cpp}: Quote/unquote attribute name actions
- FlattenAttrs.{h,cpp}: Flatten nested attribute set action
- JsonToNix.{h,cpp}: JSON to Nix conversion action
- NoogleDoc.{h,cpp}: Noogle documentation link action
- PackAttrs.{h,cpp}: Pack dotted paths to nested set actions
- Utils.{h,cpp}: Shared utilities (identifier validation, escaping, etc.)

This improves maintainability as the number of code actions grows,
following the suggestion from PR #764 review.
takeokunn added a commit that referenced this pull request Jan 9, 2026
Move 63 test files from flat structure into category subdirectories
to improve discoverability and match the source code organization:

- attr-name/: Quote/unquote attribute name tests (14 files)
- flatten-attrs/: Flatten nested attribute set tests (7 files)
- json-to-nix/: JSON to Nix conversion tests (13 files)
- noogle-doc/: Noogle documentation link tests (4 files)
- pack-attrs/: Pack dotted paths tests (24 files)
- quick-fix/: Quick fix diagnostic tests (1 file)

This addresses the test directory organization suggested in PR #764 review.
takeokunn added a commit that referenced this pull request Jan 9, 2026
…ed files

Extract code action implementations from CodeAction.cpp into a dedicated
CodeActions/ subdirectory with separate files for each action type:

- AttrName.{h,cpp}: Quote/unquote attribute name actions
- FlattenAttrs.{h,cpp}: Flatten nested attribute set action
- JsonToNix.{h,cpp}: JSON to Nix conversion action
- NoogleDoc.{h,cpp}: Noogle documentation link action
- PackAttrs.{h,cpp}: Pack dotted paths to nested set actions
- Utils.{h,cpp}: Shared utilities (identifier validation, escaping, etc.)

This improves maintainability as the number of code actions grows,
following the suggestion from PR #764 review.
takeokunn added a commit that referenced this pull request Jan 9, 2026
Move 63 test files from flat structure into category subdirectories
to improve discoverability and match the source code organization:

- attr-name/: Quote/unquote attribute name tests (14 files)
- flatten-attrs/: Flatten nested attribute set tests (7 files)
- json-to-nix/: JSON to Nix conversion tests (13 files)
- noogle-doc/: Noogle documentation link tests (4 files)
- pack-attrs/: Pack dotted paths tests (24 files)
- quick-fix/: Quick fix diagnostic tests (1 file)

This addresses the test directory organization suggested in PR #764 review.
inclyc added a commit that referenced this pull request Jan 9, 2026
…nd test subdirectories (#765)

## Summary

This PR addresses the file structure suggestion from PR #764 review.

### Commits

1. **refactor(code-action): extract code action implementations to
dedicated files** c68c266
- Extract from `CodeAction.cpp` into `Controller/CodeActions/`
subdirectory
- Create dedicated files: AttrName, FlattenAttrs, JsonToNix, NoogleDoc,
PackAttrs, Utils

2. **test(code-action): reorganize test files into category
subdirectories** 078ba02
   - Move 63 test files into 6 category subdirectories
- Categories: attr-name, flatten-attrs, json-to-nix, noogle-doc,
pack-attrs, quick-fix

### Motivation

The growing number of code actions warrants a dedicated subdirectory
structure for better maintainability.

### Testing

- All unit tests pass
- All regression tests pass

---------

Co-authored-by: Yingchi Long <longyingchi24s@ict.ac.cn>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request nixd:controller

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants