Skip to content

Commit

Permalink
Normalize file paths to be relative to rootPath
Browse files Browse the repository at this point in the history
  • Loading branch information
netmute committed Nov 29, 2024
1 parent 7e102e1 commit ff2e40a
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}

Expand Down

0 comments on commit ff2e40a

Please sign in to comment.