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:
@@ -263,15 +263,7 @@ func (s *Server) generateASTSummary(ctx context.Context, path string, content []
|
||||
|
||||
var sb strings.Builder
|
||||
|
||||
// Get relative path
|
||||
relPath := path
|
||||
if absPath, err := filepath.Abs(path); err == nil {
|
||||
if rel, err := filepath.Rel(s.cfg.WorkspaceRoot, absPath); err == nil && !strings.HasPrefix(rel, "..") {
|
||||
relPath = rel
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprintf(&sb, "**%s** (%d lines, %s)\n\n", relPath, countLines(content), lang)
|
||||
fmt.Fprintf(&sb, "**%s** (%d lines, %s)\n\n", s.relPath(path), countLines(content), lang)
|
||||
sb.WriteString("Symbols:\n")
|
||||
|
||||
for _, sym := range symbols {
|
||||
@@ -282,6 +274,18 @@ func (s *Server) generateASTSummary(ctx context.Context, path string, content []
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
// relPath renders path relative to the workspace root for display, saving the
|
||||
// tokens an absolute path would cost. Falls back to the original path when it
|
||||
// can't be relativized (outside the root, or on error).
|
||||
func (s *Server) relPath(path string) string {
|
||||
if absPath, err := filepath.Abs(path); err == nil {
|
||||
if rel, err := filepath.Rel(s.cfg.WorkspaceRoot, absPath); err == nil && !strings.HasPrefix(rel, "..") {
|
||||
return rel
|
||||
}
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
// symbolKindIcon returns an icon/prefix for a symbol kind.
|
||||
func symbolKindIcon(kind protocol.SymbolKind) string {
|
||||
switch kind {
|
||||
|
||||
Reference in New Issue
Block a user