Skip to content

Commit cdd37d0

Browse files
committed
Remove unused LSP helpers and fix log verbosity
1 parent 5e0d5cb commit cdd37d0

5 files changed

Lines changed: 8 additions & 72 deletions

File tree

internal/cli/cli.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ func Main(version string, buildDate string) int {
136136
if errors.As(err, &depErr) {
137137
executor.PrintDependencyTree(depErr, os.Stderr)
138138
log.Errorf("%s", depErr.FailureMessage())
139+
139140
return getExitCode(err, 1)
140141
}
141142

internal/lsp/handlers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func (h *definitionHandler) findMixinsDefinition(doc *string, params *lsp.Defini
9191

9292
func (h *definitionHandler) findCommandDefinition(doc *string, params *lsp.DefinitionParams) (any, error) {
9393
path := normalizePath(params.TextDocument.URI)
94+
9495
commandName := h.parser.extractCommandReference(doc, params.Position)
9596
if commandName == "" {
9697
h.parser.log.Debugf("no command reference resolved at %s:%d:%d", path, params.Position.Line, params.Position.Character)

internal/lsp/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ func (s *lspServer) Run() error {
2525
return s.server.RunStdio()
2626
}
2727

28-
func lspLogVerbosity() (verbosity int) {
29-
verbosity = 1
28+
func lspLogVerbosity() int {
29+
verbosity := 1
3030

3131
defer func() {
3232
_ = recover()

internal/lsp/treesitter.go

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -106,49 +106,6 @@ func executeYAMLQuery(document *string, queryText string, visit func(capture ts.
106106
return false
107107
}
108108

109-
func getLine(document *string, line uint32) string {
110-
lines := strings.Split(*document, "\n")
111-
if line >= uint32(len(lines)) {
112-
return ""
113-
}
114-
115-
return lines[line]
116-
}
117-
118-
// position.
119-
func wordUnderCursor(text string, position *lsp.Position) string {
120-
if len(text) == 0 {
121-
return ""
122-
}
123-
124-
character := position.Character
125-
126-
if character >= uint32(len(text)) {
127-
return ""
128-
}
129-
130-
if text[character] == ' ' {
131-
return ""
132-
}
133-
134-
// Find word boundaries
135-
start := position.Character
136-
for start > 0 && isWordChar(text[start-1]) {
137-
start--
138-
}
139-
140-
end := position.Character
141-
for end < uint32(len(text)) && isWordChar(text[end]) {
142-
end++
143-
}
144-
145-
return text[start:end]
146-
}
147-
148-
func isWordChar(c byte) bool {
149-
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_' || c == '-'
150-
}
151-
152109
type parser struct {
153110
log commonlog.Logger
154111
}
@@ -457,8 +414,10 @@ func (p *parser) findCommandNameByAnchor(document *string, anchorName string) st
457414
break
458415
}
459416

460-
var commandName string
461-
var matchedAnchor string
417+
var (
418+
commandName string
419+
matchedAnchor string
420+
)
462421

463422
for _, capture := range match.Captures {
464423
switch capture.Name {

internal/lsp/treesitter_test.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -694,28 +694,3 @@ commands:
694694
t.Fatalf("extractDependsValues() = %#v, want %#v", got, want)
695695
}
696696
}
697-
698-
func TestWordUnderCursor(t *testing.T) {
699-
tests := []struct {
700-
line string
701-
position lsp.Position
702-
want string
703-
}{
704-
{"test word here", lsp.Position{Character: 0}, "test"},
705-
{"test word here", lsp.Position{Character: 2}, "test"},
706-
{"test word here", lsp.Position{Character: 5}, "word"},
707-
{"test word here", lsp.Position{Character: 10}, "here"},
708-
{"test-word_123", lsp.Position{Character: 5}, "test-word_123"},
709-
{"", lsp.Position{Character: 0}, ""},
710-
{"test", lsp.Position{Character: 10}, ""},
711-
{"test word", lsp.Position{Character: 4}, ""},
712-
{" test ", lsp.Position{Character: 3}, "test"},
713-
}
714-
715-
for i, tt := range tests {
716-
got := wordUnderCursor(tt.line, &tt.position)
717-
if got != tt.want {
718-
t.Errorf("case %d: got %q, want %q", i, got, tt.want)
719-
}
720-
}
721-
}

0 commit comments

Comments
 (0)