"TypeError: Cannot read property 'length' of undefined" error with PHP file
rsese opened this issue · comments
Description
Reported in atom/ide-php#63.
If you have a PHP file with a .html extension, the outline view doesn't work and you get this error in devtools console:
/Users/rsese/.atom/packages/atom-ide-ui/node_modules/react-dom/cjs/react-dom.production.min.js:164 TypeError: Cannot read property 'length' of undefined
at r.push.outline.tokenizedText.map (/Users/rsese/.atom/packages/atom-ide-ui/modules/atom-ide-ui/pkg/atom-ide-outline-view/lib/OutlineView.js:418:28)
at Array.map (native)
at renderItem (/Users/rsese/.atom/packages/atom-ide-ui/modules/atom-ide-ui/pkg/atom-ide-outline-view/lib/OutlineView.js:416:37)
at OutlineViewCore._outlineTreeToNode.outlineTree (/Users/rsese/.atom/packages/atom-ide-ui/modules/atom-ide-ui/pkg/atom-ide-outline-view/lib/OutlineView.js:335:18)
at Array.map (native)
at OutlineViewCore.render (/Users/rsese/.atom/packages/atom-ide-ui/modules/atom-ide-ui/pkg/atom-ide-outline-view/lib/OutlineView.js:390:39)
at h (/Users/rsese/.atom/packages/atom-ide-ui/node_modules/react-dom/cjs/react-dom.production.min.js:130:280)
at beginWork (/Users/rsese/.atom/packages/atom-ide-ui/node_modules/react-dom/cjs/react-dom.production.min.js:133:485)
snip...
Full error:
Expected Behavior
No error or if PHP files with a .html
extension isn't supported, maybe a notification/error/warning in the outline view that mentions this?
Actual Behavior
You get the error mentioned above and the outline view is blank.
Possible Fix
Not sure! 🤔
Steps to Reproduce
- Save a file called
test.html
with this content:
<?php
function foo() {
echo "<p>Hello World!</p>";
}
?>
<html>
<head>
<title>Hello World</title>
</head>
<body>a
<?
foo();
?>
</body>
</html>
- Toggle the outline view with
Outline View: Toggle
Context
The person that reported the error to ide-php
thought the error was coming from ide-php
but it was coming from ide-html
- it was confusing for us because we assumed the error was with ide-php
as well but we couldn't reproduce.
Your Environment
- Version used:
ide-html 0.4.1
atom -v
Atom : 1.24.0
Electron: 1.6.16
Chrome : 56.0.2924.87
Node : 7.4.0
- Environment name and version (e.g. Chrome 39, node.js 5.4):
- Operating System and version (desktop or mobile):
macOS 10.12.6
- Link to your project:
n/a
trying to find the root cause of this...
NOTE: whenever we have question mark ?
in the tag it generates error
the following file has no error until adding a ?
in some tag
<html>
<head>
<title>Hello World</title>
</head>
<body>a
- <
+ <?
foo();
>
</body>
</html>
@liuderchi Looking at the payload that comes back it seems to be because the language server is returning an object for the final part (the <? inside the body) that does not have a name.
According to the language server protocol at https://microsoft.github.io/language-server-protocol/specification the name is not optional and should always be returned.
We could put code in to try and deal with this inside atom-languageclient although the best solution is having the language server itself fixed.
Next version of atom-languageclient will filter out any document symbols that have a name missing atom/atom-languageclient@aac3505
... try and deal with this inside atom-languageclient although the best solution is having language server itself fixed.
@damieng huge thanks for this workaround! 💯
Will upgrade atom-languageclient when this feature is released (probably v0.9.0)
v0.9.0 is now out with much better autocomplete too
Actually use v0.9.1 - 0.9.0 has a weird autocomplete bug.
@damieng @rsese ide-html has just released v0.4.2 (along with latest atom-languageclient).
Please upgrade ide-html to confirm that it solves this issue.
I'm not getting any errors anymore.
I updated and can also no longer reproduce 👍 Thanks @liuderchi ✌️
LGTM. Will close this. Thank you guys 💯