mirror of
https://github.com/lukaszraczylo/filepuff-mcp.git
synced 2026-10-20 05:57:51 +00:00
perf(lsp): emit workspace-relative paths in definition/references
lsp_query printed absolute paths from URIToFile (e.g. the full /Users/.../internal/... prefix repeated per result) while file_search and the AST summary already relativize. On a find_references across many files that ~60-char root prefix repeats per file group — wasted tokens for the LLM consumer. Extract a Server.relPath helper (dedups the AST summary's inline block) and apply it to definition and references display paths; the absolute path is kept where the file is actually re-read for previews. Adds a relPath unit test (in-workspace relativized, out-of-workspace unchanged).
This commit is contained in:
@@ -181,7 +181,7 @@ func (s *Server) lspDefinition(ctx context.Context, file string, line, col int,
|
||||
|
||||
for _, loc := range locations {
|
||||
filePath := lsp.URIToFile(loc.URI)
|
||||
fmt.Fprintf(&output, "**%s:%d:%d**\n", filePath, loc.Range.Start.Line+1, loc.Range.Start.Character+1)
|
||||
fmt.Fprintf(&output, "**%s:%d:%d**\n", s.relPath(filePath), loc.Range.Start.Line+1, loc.Range.Start.Character+1)
|
||||
|
||||
preview := s.readFilePreview(filePath, loc.Range.Start.Line+1, 3)
|
||||
if preview != "" {
|
||||
@@ -210,7 +210,9 @@ func (s *Server) lspReferences(ctx context.Context, file string, line, col int,
|
||||
fileGroups := make(map[string][]lsp.Location)
|
||||
fileOrder := make([]string, 0)
|
||||
for _, loc := range locations {
|
||||
filePath := lsp.URIToFile(loc.URI)
|
||||
// Relativize for display; references are not re-read so the absolute
|
||||
// path isn't needed downstream.
|
||||
filePath := s.relPath(lsp.URIToFile(loc.URI))
|
||||
if _, seen := fileGroups[filePath]; !seen {
|
||||
fileOrder = append(fileOrder, filePath)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user