mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
fix(aliases): Improve rename when definition entry is not available
This commit is contained in:
parent
590786e844
commit
1a70a5ad57
@ -1,7 +1,6 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"config-lsp/handlers/aliases/ast"
|
||||
"config-lsp/handlers/aliases/indexes"
|
||||
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
@ -9,17 +8,22 @@ import (
|
||||
|
||||
func RenameAlias(
|
||||
i indexes.AliasesIndexes,
|
||||
oldEntry *ast.AliasEntry,
|
||||
oldName string,
|
||||
newName string,
|
||||
) []protocol.TextEdit {
|
||||
occurrences := i.UserOccurrences[indexes.NormalizeKey(oldEntry.Key.Value)]
|
||||
normalizedName := indexes.NormalizeKey(oldName)
|
||||
definitionEntry := i.Keys[normalizedName]
|
||||
occurrences := i.UserOccurrences[normalizedName]
|
||||
|
||||
changes := make([]protocol.TextEdit, 0, len(occurrences))
|
||||
|
||||
if definitionEntry != nil {
|
||||
// Own rename
|
||||
changes = append(changes, protocol.TextEdit{
|
||||
Range: oldEntry.Key.Location.ToLSPRange(),
|
||||
Range: definitionEntry.Key.Location.ToLSPRange(),
|
||||
NewText: newName,
|
||||
})
|
||||
}
|
||||
|
||||
// Other AliasValueUser occurrences
|
||||
for _, value := range occurrences {
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"config-lsp/handlers/aliases"
|
||||
"config-lsp/handlers/aliases/ast"
|
||||
"config-lsp/handlers/aliases/handlers"
|
||||
"config-lsp/handlers/aliases/indexes"
|
||||
|
||||
"github.com/tliron/glsp"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
@ -24,7 +23,11 @@ func TextDocumentRename(context *glsp.Context, params *protocol.RenameParams) (*
|
||||
entry := rawEntry.(*ast.AliasEntry)
|
||||
|
||||
if character >= entry.Key.Location.Start.Character && character <= entry.Key.Location.End.Character {
|
||||
changes := handlers.RenameAlias(*d.Indexes, entry, params.NewName)
|
||||
changes := handlers.RenameAlias(
|
||||
*d.Indexes,
|
||||
entry.Key.Value,
|
||||
params.NewName,
|
||||
)
|
||||
|
||||
return &protocol.WorkspaceEdit{
|
||||
Changes: map[protocol.DocumentUri][]protocol.TextEdit{
|
||||
@ -44,9 +47,11 @@ func TextDocumentRename(context *glsp.Context, params *protocol.RenameParams) (*
|
||||
case ast.AliasValueUser:
|
||||
userValue := (*rawValue).(ast.AliasValueUser)
|
||||
|
||||
definitionEntry := d.Indexes.Keys[indexes.NormalizeKey(userValue.Value)]
|
||||
|
||||
changes := handlers.RenameAlias(*d.Indexes, definitionEntry, params.NewName)
|
||||
changes := handlers.RenameAlias(
|
||||
*d.Indexes,
|
||||
userValue.Value,
|
||||
params.NewName,
|
||||
)
|
||||
|
||||
return &protocol.WorkspaceEdit{
|
||||
Changes: map[protocol.DocumentUri][]protocol.TextEdit{
|
||||
|
Loading…
x
Reference in New Issue
Block a user