fix(lsp): apply each rename edit to its own document
Assisted-by: GLM 5.3 Flash
This commit is contained in:
+6
-6
@@ -229,7 +229,9 @@ func (s *Server) references(p referenceParams) []Location {
|
||||
return out
|
||||
}
|
||||
|
||||
// rename renames a label across the document.
|
||||
// rename renames a label across every document the references reach. Each
|
||||
// edit is grouped under the URI it belongs to: a range collected in another
|
||||
// file must never be applied to the document that started the rename.
|
||||
func (s *Server) rename(p renameParams) *WorkspaceEdit {
|
||||
text := s.docs[p.TextDocument.URI]
|
||||
word, _ := wordAt(text, p.Position)
|
||||
@@ -244,13 +246,11 @@ func (s *Server) rename(p renameParams) *WorkspaceEdit {
|
||||
if len(refs) == 0 {
|
||||
return nil
|
||||
}
|
||||
edits := make([]TextEdit, 0, len(refs))
|
||||
edits := make(map[string][]TextEdit, len(refs))
|
||||
for _, loc := range refs {
|
||||
edits = append(edits, TextEdit{Range: loc.Range, NewText: p.NewName})
|
||||
}
|
||||
return &WorkspaceEdit{
|
||||
Changes: map[string][]TextEdit{p.TextDocument.URI: edits},
|
||||
edits[loc.URI] = append(edits[loc.URI], TextEdit{Range: loc.Range, NewText: p.NewName})
|
||||
}
|
||||
return &WorkspaceEdit{Changes: edits}
|
||||
}
|
||||
|
||||
// documentFormatting returns a single edit that replaces the whole document
|
||||
|
||||
Reference in New Issue
Block a user