Skip to content

Feat/lsp symbols#9

Merged
cachebag merged 8 commits into
cachebag:masterfrom
HimanshuSardana:feat/lsp-symbols
May 21, 2026
Merged

Feat/lsp symbols#9
cachebag merged 8 commits into
cachebag:masterfrom
HimanshuSardana:feat/lsp-symbols

Conversation

@HimanshuSardana

Copy link
Copy Markdown
Contributor

Added support for @lsp completions in the prompt buffer. When used, the plugin now calls vim.lsp.buf.workspace_symbol, formats the returned symbols, and prepends the resulting workspace context to the prompt sent to the LLM.

image

Notes

workspace_symbol behavior appears to vary across LSP servers:

  • basedpyright and gopls return no results when provided with an empty query ("")
  • lua_ls returns all project symbols for the same request (intended behaviour)

I also tried an alternative implementation that called textDocument/documentSymbol for every file in the workspace and merged the results manually. While this produced better results across servers, it often resulted in severe lag (3-4s) even in relatively small projects. So, I decided not to use that approach and just rely on the LSP's workspace_symbol implementation

@HimanshuSardana HimanshuSardana requested a review from cachebag as a code owner May 20, 2026 04:57
@cachebag cachebag added feature New functionality ux User experience or polish area:llm Providers, API calls, system prompt labels May 20, 2026

@cachebag cachebag left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Generally speaking as well, I noticed that on reprompts, @lsp is just treated as literal text because we didn't update build_reprompt_messages.

You should either strip it entirely or support it in this PR.

Thanks so much for your contribution :D

Comment thread lua/jumpy/llm.lua Outdated
Comment thread lua/jumpy/llm.lua Outdated
Comment thread lua/jumpy/llm.lua Outdated
Comment thread lua/jumpy/llm.lua Outdated
Comment thread lua/jumpy/llm.lua Outdated
Comment thread lua/jumpy/prompt.lua
@HimanshuSardana

Copy link
Copy Markdown
Contributor Author

just fixed the linting error, could you re-run the GitHub Actions workflow?

cachebag added 2 commits May 21, 2026 09:12
- Replace vim.tbl_any (Neovim 0.10+) with a plain loop so the plugin works on older nvim and in configs that override vim.* helpers.

- Filter workspace/symbol results to files under cwd, dropping LSP stdlib/meta files that otherwise crowd out real project symbols (e.g. lua_ls dumps Lua stdlib meta into the response).

- Keep only structural SymbolKinds (Function, Method, Class, Field, Struct, etc.) so locals/vars don't blow the 200-entry cap.

- Thread context.symbols into build_reprompt_messages, mirroring build_messages. Previously @Lsp on a reprompt computed and then silently discarded the workspace context.
- Split insert-mode <CR>: accept pumenu selection if visible, otherwise submit. Previously <CR> always submitted, so hitting Enter on the @Lsp popup item just sent the prompt without inserting the mention.

- Disable nvim-cmp inside the prompt buffer so it doesn't fight with vim.fn.complete or intercept <CR>.

- Highlight confirmed @Lsp tokens via a JumpyMention extmark group (linked to Special) so users can see when the mention will actually be picked up by _submit. Partial typing like '@l'/'@ls' does not highlight; only the standalone, word-bounded token does — matching the frontier-pattern gsub used by _submit.

@cachebag cachebag left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

LGTM. I went ahead and pushed a few follow-ups- happy to discuss them with you:

  • vim.tbl_any -> plain loop, so this doesn't break on older nvim / shimmed vim.*.
  • Filter symbols to files under cwd and to structural SymbolKinds — without this, lua_ls floods the response with stdlib meta and the 200-cap eats real project symbols.
  • Threaded context.symbols through build_reprompt_messages so @Lsp actually reaches the LLM on reprompts.
  • Prompt UX: insert-mode now accepts the pumenu before submitting, disabled cmp inside the prompt buf, and added a JumpyMention highlight that only fires on the standalone @Lsp token so you can see when it'll be picked up.

Thanks for the contribution @HimanshuSardana ! I really love this feature.

@cachebag cachebag merged commit ad2dd17 into cachebag:master May 21, 2026
2 of 3 checks passed
cachebag added a commit that referenced this pull request May 21, 2026
* chore: move get_workspace_symbols to context-tools.lua

fix: formatting

fix: replace buf_request_sync with buf_request

* fix: make buf_request async

* chore: pass workspace symbols via context

* fix: notify user if LSP doesnt support workspace_symbols

* fix: enable @Lsp completion in reprompts

* style: fix lint error

* fix(context-tools): broaden compatibility and reduce symbol noise

- Replace vim.tbl_any (Neovim 0.10+) with a plain loop so the plugin works on older nvim and in configs that override vim.* helpers.

- Filter workspace/symbol results to files under cwd, dropping LSP stdlib/meta files that otherwise crowd out real project symbols (e.g. lua_ls dumps Lua stdlib meta into the response).

- Keep only structural SymbolKinds (Function, Method, Class, Field, Struct, etc.) so locals/vars don't blow the 200-entry cap.

- Thread context.symbols into build_reprompt_messages, mirroring build_messages. Previously @Lsp on a reprompt computed and then silently discarded the workspace context.

* fix(prompt): make @Lsp completion usable in prompt float

- Split insert-mode <CR>: accept pumenu selection if visible, otherwise submit. Previously <CR> always submitted, so hitting Enter on the @Lsp popup item just sent the prompt without inserting the mention.

- Disable nvim-cmp inside the prompt buffer so it doesn't fight with vim.fn.complete or intercept <CR>.

- Highlight confirmed @Lsp tokens via a JumpyMention extmark group (linked to Special) so users can see when the mention will actually be picked up by _submit. Partial typing like '@l'/'@ls' does not highlight; only the standalone, word-bounded token does — matching the frontier-pattern gsub used by _submit.

---------

Co-authored-by: Himanshu Sandana <himanshusardana2005@gmail.com>
cachebag added a commit that referenced this pull request May 21, 2026
* chore: move get_workspace_symbols to context-tools.lua

fix: formatting

fix: replace buf_request_sync with buf_request

* fix: make buf_request async

* chore: pass workspace symbols via context

* fix: notify user if LSP doesnt support workspace_symbols

* fix: enable @Lsp completion in reprompts

* style: fix lint error

* fix(context-tools): broaden compatibility and reduce symbol noise

- Replace vim.tbl_any (Neovim 0.10+) with a plain loop so the plugin works on older nvim and in configs that override vim.* helpers.

- Filter workspace/symbol results to files under cwd, dropping LSP stdlib/meta files that otherwise crowd out real project symbols (e.g. lua_ls dumps Lua stdlib meta into the response).

- Keep only structural SymbolKinds (Function, Method, Class, Field, Struct, etc.) so locals/vars don't blow the 200-entry cap.

- Thread context.symbols into build_reprompt_messages, mirroring build_messages. Previously @Lsp on a reprompt computed and then silently discarded the workspace context.

* fix(prompt): make @Lsp completion usable in prompt float

- Split insert-mode <CR>: accept pumenu selection if visible, otherwise submit. Previously <CR> always submitted, so hitting Enter on the @Lsp popup item just sent the prompt without inserting the mention.

- Disable nvim-cmp inside the prompt buffer so it doesn't fight with vim.fn.complete or intercept <CR>.

- Highlight confirmed @Lsp tokens via a JumpyMention extmark group (linked to Special) so users can see when the mention will actually be picked up by _submit. Partial typing like '@l'/'@ls' does not highlight; only the standalone, word-bounded token does — matching the frontier-pattern gsub used by _submit.

---------

Co-authored-by: Himanshu Sandana <himanshusardana2005@gmail.com>
cachebag added a commit that referenced this pull request May 21, 2026
* chore: move get_workspace_symbols to context-tools.lua

fix: formatting

fix: replace buf_request_sync with buf_request

* fix: make buf_request async

* chore: pass workspace symbols via context

* fix: notify user if LSP doesnt support workspace_symbols

* fix: enable @Lsp completion in reprompts

* style: fix lint error

* fix(context-tools): broaden compatibility and reduce symbol noise

- Replace vim.tbl_any (Neovim 0.10+) with a plain loop so the plugin works on older nvim and in configs that override vim.* helpers.

- Filter workspace/symbol results to files under cwd, dropping LSP stdlib/meta files that otherwise crowd out real project symbols (e.g. lua_ls dumps Lua stdlib meta into the response).

- Keep only structural SymbolKinds (Function, Method, Class, Field, Struct, etc.) so locals/vars don't blow the 200-entry cap.

- Thread context.symbols into build_reprompt_messages, mirroring build_messages. Previously @Lsp on a reprompt computed and then silently discarded the workspace context.

* fix(prompt): make @Lsp completion usable in prompt float

- Split insert-mode <CR>: accept pumenu selection if visible, otherwise submit. Previously <CR> always submitted, so hitting Enter on the @Lsp popup item just sent the prompt without inserting the mention.

- Disable nvim-cmp inside the prompt buffer so it doesn't fight with vim.fn.complete or intercept <CR>.

- Highlight confirmed @Lsp tokens via a JumpyMention extmark group (linked to Special) so users can see when the mention will actually be picked up by _submit. Partial typing like '@l'/'@ls' does not highlight; only the standalone, word-bounded token does — matching the frontier-pattern gsub used by _submit.

---------

Co-authored-by: Akrm Al-Hakimi <akrm@cachebag.sh>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:llm Providers, API calls, system prompt feature New functionality ux User experience or polish

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants