Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
52 changes: 33 additions & 19 deletions analysis/completion.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package analysis

import (
"regexp"
"strings"

"github.com/textwire/lsp/lsp"
"github.com/textwire/textwire/v2/lsp/completions"
)

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) {
Expand All @@ -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 {
Expand Down
5 changes: 1 addition & 4 deletions internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -29,11 +26,11 @@ var (
func init() {
config = Config{
Enabled: true,
Level: "info",
}

initLoggers()
}

func New(filename string) *log.Logger {
const fileMode = 0666

Expand Down