From ff2e40a6cec2500f946742667ae75a59708b9806 Mon Sep 17 00:00:00 2001 From: Simon Ernst Date: Fri, 29 Nov 2024 20:11:08 +0100 Subject: [PATCH] Normalize file paths to be relative to rootPath --- main.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index fff0cff..454af1d 100644 --- a/main.go +++ b/main.go @@ -817,16 +817,24 @@ func (s *Server) scanRecursiveTags() error { // scanSingleFileTag scans a single file, removing previous entries for that file func (s *Server) scanSingleFileTag(filePath string) error { s.mu.Lock() + // Convert filePath to relative path + relPath, err := filepath.Rel(s.rootPath, filePath) + if err != nil { + s.mu.Unlock() + return fmt.Errorf("failed to make file path relative: %v", err) + } + + // Remove previous entries for that file newEntries := make([]TagEntry, 0, len(s.tagEntries)) for _, entry := range s.tagEntries { - if entry.Path != filePath { + if entry.Path != relPath { newEntries = append(newEntries, entry) } } s.tagEntries = newEntries s.mu.Unlock() - cmd := exec.Command("ctags", "--output-format=json", "--fields=+n", filePath) + cmd := exec.Command("ctags", "--output-format=json", "--fields=+n", relPath) cmd.Dir = s.rootPath return s.processTagsOutput(cmd) } @@ -850,6 +858,15 @@ func (s *Server) processTagsOutput(cmd *exec.Cmd) error { log.Printf("Failed to parse ctags JSON entry: %v", err) continue } + + // Normalize the Path to be relative to rootPath + relPath, err := filepath.Rel(s.rootPath, filepath.Join(s.rootPath, entry.Path)) + if err != nil { + log.Printf("Failed to make path relative for %s: %v", entry.Path, err) + continue + } + entry.Path = relPath + entries = append(entries, entry) }