config-lsp/handlers/aliases/lsp/text-document-completion.go
2024-09-01 21:42:52 +02:00

36 lines
797 B
Go

package lsp
import (
"config-lsp/handlers/aliases"
"config-lsp/handlers/aliases/ast"
"config-lsp/handlers/aliases/handlers"
"github.com/tliron/glsp"
protocol "github.com/tliron/glsp/protocol_3_16"
)
func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionParams) (any, error) {
d := aliases.DocumentParserMap[params.TextDocument.URI]
cursor := params.Position.Character
line := params.Position.Line
if _, found := d.Parser.CommentLines[line]; found {
return nil, nil
}
rawEntry, found := d.Parser.Aliases.Get(line)
if !found {
// For the key there are no completions available
return handlers.GetAliasesCompletions(d.Indexes), nil
}
entry := rawEntry.(*ast.AliasEntry)
return handlers.GetCompletionsForEntry(
cursor,
entry,
d.Indexes,
)
}