Skip to content

Cannot read property 'range' of null: CompletionItem.textEdit cannot be null #127

Closed

Description

The protocol defines that all properties on CompletionItem except label are optional. However, sending a completion item with only a label results in this exception:

Cannot read property 'range' of null: TypeError: Cannot read property 'range' of null
    at asTextEdit (C:\Users\felix\git\OpenSource\vscode-php-intellisense\node_modules\vscode-languageclient\lib\protocolConverter.js:108:46)
    at C:\Users\felix\git\OpenSource\vscode-php-intellisense\node_modules\vscode-languageclient\lib\protocolConverter.js:101:67
    at set (C:\Users\felix\git\OpenSource\vscode-php-intellisense\node_modules\vscode-languageclient\lib\protocolConverter.js:89:13)
    at asCompletionItem (C:\Users\felix\git\OpenSource\vscode-php-intellisense\node_modules\vscode-languageclient\lib\protocolConverter.js:101:9)
    at Array.map (native)
    at asCompletionResult (C:\Users\felix\git\OpenSource\vscode-php-intellisense\node_modules\vscode-languageclient\lib\protocolConverter.js:82:26)
    at process._tickCallback (internal/process/next_tick.js:103:7)

That is because here textEdit is passed to asTextEdit, which passes textEdit.range to asRange. textEdit can be null though, which leads to the exception.

The same happens with asCommand.

I highly recommend you to take a look at strictNullChecks - it prevents these bugs at compile-time!

Activity

  1. felixfbecker commented on Nov 19, 2016

    @felixfbecker
    ContributorAuthor

    Looking more at the code, it seems like the set() helper only checks if the value is undefined, but allows null just fine. Many static languages unfortunately only know null and no undefined.
    (Btw all these helper functions are really confusing - why a function that does nothing but return value === null, or call a function if a condition is true (like an if)?)

  2. felixfbecker commented on Nov 26, 2016

    @felixfbecker
    ContributorAuthor

    Dirk Bäumer (@dbaeumer) I'm not insisting that #128 gets accepted, if you would like to see a different solution I would happily provide a different PR, but can we please resolve this? It blocks completion support for PHP

  3. dbaeumer commented on Dec 16, 2016

    @dbaeumer
    Member

    Although all these properties are defined as optional they aren't really all optional :-). I (and Joh) were too lazy to define different type defining the legal combinations. What I will do is to change the code that if all properties are missing I will create a completion item which does nothing.

  4. felixfbecker commented on Dec 16, 2016

    @felixfbecker
    ContributorAuthor

    Thanks for the explanation! Is there any reference which combination of properties are actually legal?

  5. dbaeumer commented on Dec 16, 2016

    @dbaeumer
    Member

    Actually no. Will add to the list of things to do. What happens as a fallback is that the item does nothing when selected but such an item is not very useful :-)

  6. felixfbecker commented on Dec 16, 2016

    @felixfbecker
    ContributorAuthor

    Could you give a rough description for the meantime?

  7. dbaeumer commented on Dec 16, 2016

    @dbaeumer
    Member

    It should either have a { insertString } a { insertString, range } (new in 3.0) or a { textEdit }

  8. dbaeumer commented on Dec 16, 2016

    @dbaeumer
    Member

    I fixed the code to create a noop completion item in case all properties except label are missing.

  9. felixfbecker commented on Dec 16, 2016

    @felixfbecker
    ContributorAuthor

    Isn't insertString + range exactly the same as textEdit?
    Also, the LSP docs state that if insertText is not set, label is used in its place

  10. dbaeumer commented on Dec 19, 2016

    @dbaeumer
    Member

    Felix Becker (@felixfbecker) you are correct that the label is used. My code fix does result in this. Sorry for the incorrect comment. My change creates an empty CompletionItem.

  11. locked and limited conversation to collaborators on Nov 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions