Skip to content

Feat/lsp symbols#9

Open
HimanshuSardana wants to merge 2 commits into
cachebag:masterfrom
HimanshuSardana:feat/lsp-symbols
Open

Feat/lsp symbols#9
HimanshuSardana wants to merge 2 commits into
cachebag:masterfrom
HimanshuSardana:feat/lsp-symbols

Conversation

@HimanshuSardana
Copy link
Copy Markdown

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
Copy link
Copy Markdown
Owner

@cachebag cachebag left a comment

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
return require("jumpy").config
end

local function get_workspace_symbols(bufnr)
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.

Please move @lsp resolution into prompt._submit (or perhaps a new jumpy/context_tools.lua) and pass the resolved string through context.

This file should only know how to format extra sections it's handed.

Comment thread lua/jumpy/llm.lua
local function get_workspace_symbols(bufnr)
local filename = vim.fn.expand("%:t:r")

local res = vim.lsp.buf_request_sync(bufnr, "workspace/symbol", { query = filename }, 1000)
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.

Sync call blocks the UI for up to 1s inside the otherwise-async LLM pipeline. You should use vim.lsp.buf_request with a callback.

Additionally, bufnr is never actually passed in from prompt._submit, so this is always 0. Plumb source_buf through context explicitly instead of relying on expand("%").

Comment thread lua/jumpy/llm.lua
end

local function get_workspace_symbols(bufnr)
local filename = vim.fn.expand("%:t:r")
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.

I don't think this is the right decision. For most files, it will return either noting or an unrelated set (which kind of defeats the purpose of this feature).

We can probably file an issue for prompt-derived queries later but for now, please drop the query so the LLM can see the real project structure.

Comment thread lua/jumpy/llm.lua

for _, r in pairs(res or {}) do
for _, s in ipairs(r.result or {}) do
out[#out + 1] = string.format("- %s [%s]", s.name, kinds[s.kind] or "?")
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.

You should include s.containerName and a workspace-relative path from s.location.uri, and cap the list to like 200.

A flat list of bare names with no location is not useful to the model and can blow up the prompt on bigger workspaces.

Comment thread lua/jumpy/llm.lua
local prompt = context.prompt
local symbols = ""

if prompt:find("@lsp") then
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.

Use a frontier pattern like prompt:gsub("%f[%w@]@lsp%f[%W]", "") instead.

Also: if no LSP client supports workspace/symbol, this silently produces an empty section. Please vim.notify so the user knows @lsp did nothing.

Comment thread lua/jumpy/prompt.lua

if match then
vim.schedule(function()
vim.fn.complete(col - #match, completionItems)
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.

Nit: could we guard this with if vim.fn.mode() == "i"?

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