Skip to content

Commit

Permalink
fix: only call gopls if the source exists at the location, fixes #801
Browse files Browse the repository at this point in the history
  • Loading branch information
a-h committed Jul 4, 2024
1 parent bf98022 commit bc6e65a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.738
0.2.742
10 changes: 10 additions & 0 deletions cmd/templ/lspcmd/proxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,16 @@ func (p *Server) Completion(ctx context.Context, params *lsp.CompletionParams) (
if !ok {
return nil, nil
}

// Ensure that Go source is available.
gosrc := strings.Split(p.GoSource[string(templURI)], "\n")
if len(gosrc)-1 < int(params.TextDocumentPositionParams.Position.Line) {
return nil, nil
}
if len(gosrc[params.TextDocumentPositionParams.Position.Line])-1 < int(params.TextDocumentPositionParams.Position.Character) {
return nil, nil
}

// Call the target.
result, err = p.Target.Completion(ctx, params)
if err != nil {
Expand Down

0 comments on commit bc6e65a

Please sign in to comment.