From c5d9634ab3c411915960159997cec33e4ee72ace Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sat, 7 Sep 2024 14:49:45 +0200 Subject: [PATCH] fix(aliases): Do not provide completions for already defined users --- handlers/aliases/handlers/completions.go | 33 ++++++++++++++++++++---- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/handlers/aliases/handlers/completions.go b/handlers/aliases/handlers/completions.go index 615c765..61ca11d 100644 --- a/handlers/aliases/handlers/completions.go +++ b/handlers/aliases/handlers/completions.go @@ -51,6 +51,8 @@ func GetCompletionsForEntry( value := GetValueAtCursor(cursor, entry) relativeCursor := cursor - entry.Key.Location.Start.Character + excludedUsers := getUsersFromEntry(entry) + if value == nil { completions = append(completions, getCommandCompletion()) completions = append(completions, getIncludeCompletion()) @@ -58,12 +60,11 @@ func GetCompletionsForEntry( completions = append(completions, getUserCompletions( i, - indexes.NormalizeKey(entry.Key.Value), + excludedUsers, "", 0, )...) - println("la completions etaient", completions) return completions, nil } @@ -73,7 +74,7 @@ func GetCompletionsForEntry( return getUserCompletions( i, - indexes.NormalizeKey(entry.Key.Value), + excludedUsers, userValue.Value, relativeCursor, ), nil @@ -126,7 +127,7 @@ func getErrorCompletion() protocol.CompletionItem { func getUserCompletions( i *indexes.AliasesIndexes, - excludeKey string, + excluded map[string]struct{}, line string, cursor uint32, ) []protocol.CompletionItem { @@ -137,7 +138,7 @@ func getUserCompletions( completions := make([]protocol.CompletionItem, 0) for name, user := range users { - if name == excludeKey { + if _, found := excluded[name]; found { continue } @@ -150,3 +151,25 @@ func getUserCompletions( 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 +} +