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

Autocomplete failing with "Cannot read property 'document' of undefined" #584

Closed
moberemk opened this issue Mar 22, 2017 · 11 comments
Closed

Comments

@moberemk
Copy link

moberemk commented Mar 22, 2017

Running into this issue that seems to be breaking all forms of autocomplete in C files, even with autocomplete set to "Disabled"

Cannot read property 'document' of undefined: TypeError: Cannot read property 'document' of undefined
    at vscode.window.onDidChangeTextEditorSelection (/Users/moberemk/.vscode/extensions/ms-vscode.cpptools-0.10.4/out/src/LanguageServer/C_Cpp.js:100:76)
    at e.invoke (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:5:9994)
    at e.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:5:13526)
    at t.$acceptSelectionsChanged (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:13:26056)
    at t.e.handle (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:12:20690)
    at s (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:8:30686)
    at p (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:8:31363)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/
@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented Mar 22, 2017

TextEditorSelectionChangeEvent.textEditor is undefined for some reason. It shouldn't happen. You could modify the javascript to check for undefined as a workaround. It would be nice to know how you're reproing this. We could change our code to protect against the undefined textEditor in a future update. Or maybe vscode.window.activeTextEditor is undefined ...looks like it could repro if the selection changes without a text editor active?

@moberemk
Copy link
Author

The repro case here is pretty straightforward, just opening any given C file breaks the autocomplete feature. Regular autocomplete/quick suggestions works after updating to 0.10.5 though, seems like it works when that setting is set to the "Disabled" flag now; makes me think this might be related to #572?

That said, I now get a second stack trace in my console, seen below:

Cannot read property 'document' of undefined: TypeError: Cannot read property 'document' of undefined
    at asCompletionResult (/Users/moberemk/.vscode/extensions/ms-vscode.cpptools-0.10.5/node_modules/vscode-languageclient/lib/protocolConverter.js:79:46)
    at process._tickCallback (internal/process/next_tick.js:103:7)

@sean-mcmanus
Copy link
Contributor

We're not able to repro the bug, so it sounds like another extension could be interfering. Can you show the results of code --list-extensions? That 2nd call stack is strange. The line I see is return new code.CompletionList(list.items.map(asCompletionItem), list.isIncomplete);.

@moberemk
Copy link
Author

moberemk commented Mar 23, 2017

Here's the output of that command:

DavidAnson.vscode-markdownlint
HookyQR.beautify
PeterJausovec.vscode-docker
Tyriar.sort-lines
alefragnani.project-manager
christian-kohler.npm-intellisense
christian-kohler.path-intellisense
codezombiech.gitignore
dbaeumer.vscode-eslint
donjayamanne.githistory
emmanuelbeziat.vscode-great-icons
flowtype.flow-for-vscode
formulahendry.auto-close-tag
formulahendry.auto-rename-tag
formulahendry.code-runner
joelday.docthis
mitaki28.vscode-clang
ms-vscode.atom-keybindings
ms-vscode.cpptools
msjsdiag.debugger-for-chrome
sleistner.vscode-fileutils
wayou.vscode-todo-highlight

@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented Mar 23, 2017

That list seems good enough.

I can repro a similar error message when I run our extension under the "Toggle Developer Tools": shell.ts:476 Cannot read property 'map' of undefined: TypeError: Cannot read property 'map' of undefined at asCompletionResult (f:\temp\vscode\node_modules\vscode-languageclient\lib\protocolConverter.js:79:46) at process._tickCallback (internal/process/next_tick.js:103:7).

6 months ago this was "by design" as a workaround to get VS Code to skip our completion results (which have nothing when disabled) and show other completion providers instead of a blank completion list. However, it's possible there is a better way to deal with this now via unregistering ourselves as a completion provider.

But normal users should not be seeing this internal error, so I suspect one of your extensions is exposing it. You should be able to safely ignore it. Do you experience any other functionality not working as a result?

@moberemk
Copy link
Author

I don't run in to any issues with that specific bug, no. I needed to add "C_Cpp.autocomplete": "Disabled" to my user settings to get autocomplete appearing though, otherwise I get the original TypeError and all autocomplete behaviour is broken.

@sean-mcmanus
Copy link
Contributor

Okay, I couldn't get the original issue to repro even with all your extensions -- I assume I have to configure one of the extensions a particular way to cause the undefined textEditor. Although this doesn't seem like expected behavior, we can just add undefined checks in a future update to be safe. If you disabled your extensions, maybe you could find the one that is causing the repro.

@moberemk
Copy link
Author

...okay, so here's where things get weird.

First off, this snippet made its way into my user settings file by what I identified after experimentation to be the install script for mitaki28.vscode-clang:

    "[cpp]": {
      "editor.quickSuggestions": false
    },
    "[c]": {
      "editor.quickSuggestions": false
    }

That totally disables code suggestions, which obviously would break the feature. Whoo. After deleting the new setting entries things worked fine with no console errors.

Either way, the problem is resolved now, but that still leaves open the question about where the console error was coming from...

@bobbrow
Copy link
Member

bobbrow commented Mar 23, 2017

If "C_Cpp.autocomplete" is set to Default, we add these snippets to the settings.json file so that the code suggestions don't pop up by default since our extension doesn't have keywords in the suggestion list yet (and VS Code auto-selects an entry in the list).

If you are using the Clang extension for autocomplete, you should set the "C_Cpp.autocomplete" setting to Disabled so that our extension doesn't attempt to interfere with the Clang extension. Doing this will also automatically remove the editor.quickSuggestions settings you saw in your settings.json file.

@moberemk
Copy link
Author

Okay so as @bobbrow says above adding "C_Cpp.autocomplete": "Disabled" to the user settings will remove those snippets and the CLang extension's autocompletion kicks in. This works well, but it brings back both errors (Cannot read property 'document' of undefined and Cannot read property 'map' of undefined) even if none of the functionality is broken.

@bobbrow
Copy link
Member

bobbrow commented Apr 25, 2017

This issue should be fixed with v0.11.0. Please let us know if it is not.

@bobbrow bobbrow closed this as completed Apr 25, 2017
@github-actions github-actions bot locked and limited conversation to collaborators Oct 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants