From 05efb280261366d6ede546be061d04bb72ffc070 Mon Sep 17 00:00:00 2001 From: Cormac Relf Date: Wed, 5 May 2021 18:00:12 +1000 Subject: [PATCH] don't null-pointer-deref panic when TextDocumentCompletion.Context missing 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 [ --- internal/adapter/lsp/server.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/adapter/lsp/server.go b/internal/adapter/lsp/server.go index 8ff8e7e6..0e43cd3d 100644 --- a/internal/adapter/lsp/server.go +++ b/internal/adapter/lsp/server.go @@ -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] @@ -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, "#")