Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lsp: don't null-pointer-deref panic when TextDocumentCompletion.Context missing #39

Closed
wants to merge 1 commit into from

Conversation

cormacrelf
Copy link
Contributor

No description provided.

…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 [
@cormacrelf cormacrelf changed the title don't null-pointer-deref panic when TextDocumentCompletion.Context missing lsp: don't null-pointer-deref panic when TextDocumentCompletion.Context missing May 5, 2021
triggerChar := params.Context.TriggerCharacter
if params.Context.TriggerKind != protocol.CompletionTriggerKindTriggerCharacter || triggerChar == nil {
return nil, nil
triggerChar := "["
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The auto-completion is also used for tags, so I'm afraid that defaulting to [ would make it unreachable. Maybe we could just take a look at the previously entered characters (like here) and ignore the trigger character in this case?

I didn't encounter an editor which doesn't support the context and trigger characters yet. How is the auto-completion triggered in this case, manually with C-Space? Which editor / LSP plugin are you using?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neovim's built in LSP doesn't do it yet. Moreover the spec says it's optional, so you do have to check the nil. I think it is perhaps a low priority feature, because generally LSPs are accepting file content as well as completion requests, and have access to a stored copy of the file. So nobody actually needs to know the trigger character. Not even you! I'll fix with a look behind instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also optional because completion gets triggered in many other ways than typing a character.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah in the end this context is not super useful then. Thanks for addressing this!

@mickael-menu
Copy link
Member

Superseded by #41

@cormacrelf I took over this PR in another branch (as I didn't have write access on yours) but credited you in the changelog. Thanks again for spotting this 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants