diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e33676..9f25d6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Release Notes +## v0.1.1 (2025-05-12) +- Fixed issue with autocompletion not working properly in some cases + ## v0.1.0 (2025-05-03) - Added `build.yml` file for GitHub actions to build releases with all LSP binaries diff --git a/analysis/completion.go b/analysis/completion.go index fffb366..f4d0a6c 100644 --- a/analysis/completion.go +++ b/analysis/completion.go @@ -1,6 +1,7 @@ package analysis import ( + "regexp" "strings" "github.com/textwire/lsp/lsp" @@ -8,8 +9,11 @@ import ( ) func (s *State) Completion(id int, uri string, pos lsp.Position) (lsp.CompletionResponse, error) { - // TODO: check if document exists - doc := s.Documents[uri] + doc, ok := s.Documents[uri] + + if !ok { + return lsp.CompletionResponse{}, nil + } lines := strings.Split(doc, "\n") if int(pos.Line) >= len(lines) { @@ -20,28 +24,38 @@ func (s *State) Completion(id int, uri string, pos lsp.Position) (lsp.Completion cursorPos := int(pos.Character) textBeforeCursor := line[:cursorPos] - if textBeforeCursor == "@" { - directives, err := completions.GetDirectives("en") - if err != nil { - return lsp.CompletionResponse{}, err - } + directiveRegex := regexp.MustCompile(`(^|[^\\])@(\w*)$`) + directiveMatch := directiveRegex.FindStringSubmatch(textBeforeCursor) + + if directiveMatch == nil { + return s.completionResponse(id, []lsp.CompletionItem{}), nil + } + + directiveName := directiveMatch[2] + + directives, err := completions.GetDirectives("en") + if err != nil { + return lsp.CompletionResponse{}, err + } + + items := make([]lsp.CompletionItem, 0, len(directives)) - items := make([]lsp.CompletionItem, 0, len(directives)) - for _, dir := range directives { - items = append(items, lsp.CompletionItem{ - Label: dir.Label, - InsertText: dir.Insert, - Documentation: dir.Documentation, - LabelDetails: &lsp.CompletionItemLabelDetails{ - Kind: lsp.CIKSnippet, - }, - }) + for _, dir := range directives { + if !strings.HasPrefix(dir.Insert, directiveName) { + continue } - return s.completionResponse(id, items), nil + items = append(items, lsp.CompletionItem{ + Label: dir.Label, + InsertText: dir.Insert, + Documentation: dir.Documentation, + LabelDetails: &lsp.CompletionItemLabelDetails{ + Kind: lsp.CIKSnippet, + }, + }) } - return s.completionResponse(id, []lsp.CompletionItem{}), nil + return s.completionResponse(id, items), nil } func (s *State) completionResponse(id int, items []lsp.CompletionItem) lsp.CompletionResponse { diff --git a/internal/logger/logger.go b/internal/logger/logger.go index a2cbb6d..655beff 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -12,9 +12,6 @@ import ( type Config struct { Enabled bool - // Level can be: error, warn, info, debug - Level string - // CustomPath for logs directory, not a file (optional) CustomPath string } @@ -29,11 +26,11 @@ var ( func init() { config = Config{ Enabled: true, - Level: "info", } initLoggers() } + func New(filename string) *log.Logger { const fileMode = 0666