fix(aliases): Do not provide completions for already defined users

This commit is contained in:
Myzel394 2024-09-07 14:49:45 +02:00
parent 89d11a16dc
commit c5d9634ab3
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185

View File

@ -51,6 +51,8 @@ func GetCompletionsForEntry(
value := GetValueAtCursor(cursor, entry) value := GetValueAtCursor(cursor, entry)
relativeCursor := cursor - entry.Key.Location.Start.Character relativeCursor := cursor - entry.Key.Location.Start.Character
excludedUsers := getUsersFromEntry(entry)
if value == nil { if value == nil {
completions = append(completions, getCommandCompletion()) completions = append(completions, getCommandCompletion())
completions = append(completions, getIncludeCompletion()) completions = append(completions, getIncludeCompletion())
@ -58,12 +60,11 @@ func GetCompletionsForEntry(
completions = append(completions, getUserCompletions( completions = append(completions, getUserCompletions(
i, i,
indexes.NormalizeKey(entry.Key.Value), excludedUsers,
"", "",
0, 0,
)...) )...)
println("la completions etaient", completions)
return completions, nil return completions, nil
} }
@ -73,7 +74,7 @@ func GetCompletionsForEntry(
return getUserCompletions( return getUserCompletions(
i, i,
indexes.NormalizeKey(entry.Key.Value), excludedUsers,
userValue.Value, userValue.Value,
relativeCursor, relativeCursor,
), nil ), nil
@ -126,7 +127,7 @@ func getErrorCompletion() protocol.CompletionItem {
func getUserCompletions( func getUserCompletions(
i *indexes.AliasesIndexes, i *indexes.AliasesIndexes,
excludeKey string, excluded map[string]struct{},
line string, line string,
cursor uint32, cursor uint32,
) []protocol.CompletionItem { ) []protocol.CompletionItem {
@ -137,7 +138,7 @@ func getUserCompletions(
completions := make([]protocol.CompletionItem, 0) completions := make([]protocol.CompletionItem, 0)
for name, user := range users { for name, user := range users {
if name == excludeKey { if _, found := excluded[name]; found {
continue continue
} }
@ -150,3 +151,25 @@ func getUserCompletions(
return completions return completions
} }
func getUsersFromEntry(
entry *ast.AliasEntry,
) map[string]struct{} {
users := map[string]struct{}{
indexes.NormalizeKey(entry.Key.Value): {},
}
if entry.Values != nil {
for _, value := range entry.Values.Values {
switch (value).(type) {
case ast.AliasValueUser:
userValue := value.(ast.AliasValueUser)
users[indexes.NormalizeKey(userValue.Value)] = struct{}{}
}
}
}
return users
}