Skip to content

Commit

Permalink
don't null-pointer-deref panic when TextDocumentCompletion.Context mi…
Browse files Browse the repository at this point in the history
…ssing

It's not compulsory. Clients don't have to send it if they don't support it yet.
This solution just defaults the trigger character to [
  • Loading branch information
cormacrelf committed May 5, 2021
1 parent 83b14ca commit 05efb28
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions internal/adapter/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,13 @@ func NewServer(opts ServerOpts) *Server {
}

handler.TextDocumentCompletion = func(context *glsp.Context, params *protocol.CompletionParams) (interface{}, error) {
triggerChar := params.Context.TriggerCharacter
if params.Context.TriggerKind != protocol.CompletionTriggerKindTriggerCharacter || triggerChar == nil {
return nil, nil
triggerChar := "["
server.logger.Printf("params.Context: %v", params.Context)
if params.Context != nil {
if params.Context.TriggerKind != protocol.CompletionTriggerKindTriggerCharacter || params.Context.TriggerCharacter == nil {
return nil, nil
}
triggerChar = *params.Context.TriggerCharacter
}

doc, ok := server.documents[params.TextDocument.URI]
Expand All @@ -189,7 +193,7 @@ func NewServer(opts ServerOpts) *Server {
return nil, err
}

switch *triggerChar {
switch triggerChar {
case "#":
if notebook.Config.Format.Markdown.Hashtags {
return server.buildTagCompletionList(notebook, "#")
Expand Down

0 comments on commit 05efb28

Please sign in to comment.