Php-language-server: Connection to server got closed.

Created on 2 Mar 2017  Â·  24Comments  Â·  Source: felixfbecker/php-language-server

Hi,

VS Code: 1.10.1
Node: 6.5.0
PHP extension pack: 1.0.0
Php intellisense: 1.1.3

I have this problem since installed the extension, server got closed and will not be restarted after 5 crash.
Console log:

extensionHost.ts:282 [Extension Host] TypeError: Return value of LanguageServer\DefinitionResolver::resolveExpressionNodeToType() must implement interface phpDocumentor\Reflection\Type, null returned in C:\Users\Varga S�ndor.vscode\extensions\felixfbecker.php-intellisense-1.1.3\vendor\felixfbecker\language-server\src\DefinitionResolver.php:445
Stack trace: ....

crash

Most helpful comment

Just a heads up to everyone watching this thread: The latest Version of PHP Intellisense (1.2.1) contains a fix for this bug. I would like to know if the problem persists or if it is fixed for all of you.

All 24 comments

I can provide a bit more information about this, and probably a mean to reproduce the problem : it happens on 3 different projects when trying to parse /api/api-field.php from the ACF WordPress plugin.

As a workaround, i've changed the return null; at line 816 in the file DefinitionResolver.php (function getTypeFromNode) to return new Types\Null_;
It probably shouldn't match this node to a Null type, but I lack the time to find why the type is not correctly matched or handle an error case, but at least it doesn't prevent the plugin from working;

Hello Alenore,
Where can I find the DefinitionResolver.php file? I searched but not found.

I just copy the custom post type code from ACF, and CPT ui and pasted it to the functions.php than removed these plugins from WP. Finally the Intellisense extension works, so thank you Alenore!

@designcraft I wouldn't advice you to do that, as it's going to pain to support ACF updates over the time.
As I know you're on Win10, the file is located here :
%USERPROFILE%\.vscode\extensions\felixfbecker.php-intellisense-1.1.3\vendor\felixfbecker\language-server\src
(Switch directory version depending on your current installed extension ;))

@Alenore @designcraft If you want painless future updates and have time to look at this, why not just do a PR? :)

@felixfbecker The main reason why I didn't do a PR is, my fix is an ugly one :p It doesn't really fix the source of the problem (why the function returns null in the first place, instead of correctly matching the type), just returns a Types\Null_ when it could possibly be something else.
If you're fine with this temporary workaround, I don't mind doing a PR :)

It just seems like you all are willing to invest so much time in the workaround, so just wanted to remind that this is a community project and anyone can find the real fix and submit it ;)

Hi there,

chiming in here since this seems to be the issue that's closest to what I'm seeing

I've got a php process at 75 or even 95% at times

  • Mac OS X 10.11.6
  • VSC 1.10.2
  • latest of both intellisense and debug extensions
  • PHP 7.1.0 (cli)

all I get from the console is

[Info - 5:11:14 PM] Connection to server got closed. Server will restart.

How would I go about getting more infos?

in my case too the WP ACF plugin is involved

the parsing stops at admin/admin.php

hope I can bring some more infos but I'd need guidance to do so

thanks a lot

I have got same error

my stack trace:

TypeError: Return value of LanguageServer\DefinitionResolver::resolveExpressionNodeToType() must implement interface phpDocumentor\Reflection\Type, null returned in C:\Users\777\.vscode-insiders\extensions\felixfbecker.php-intellisense-1.1.3\vendor\felixfbecker\language-server\src\DefinitionResolver.php:447
Stack trace:
#0 C:\Users\777\.vscode-insiders\extensions\felixfbecker.php-intellisense-1.1.3\vendor\felixfbecker\language-server\src\DefinitionResolver.php(240): LanguageServer\DefinitionResolver->resolveExpressionNodeToType(Object(PhpParser\Node\Expr\FuncCall))
#1 C:\Users\777\.vscode-insiders\extensions\felixfbecker.php-intellisense-1.1.3\vendor\felixfbecker\language-server\src\NodeVisitor\ReferencesCollector.php(38): LanguageServer\DefinitionResolver->resolveReferenceNodeToFqn(Object(PhpParser\Node\Expr\MethodCall))
#2 C:\Users\777\.vscode-insiders\extensions\felixfbecker.php-intellisense-1.1.3\vendor\nikic\php-parser\lib\PhpParser\NodeTraverser.php(159): LanguageServer\NodeVisitor\ReferencesCollector->enterNode(Object(PhpParser\Node\Expr\MethodCall))
#3 C:\Users\777\.vscode-insiders\extensions\felixfbecker.php-intellisense-1.1.3\vendor\nikic\php-parser\lib\PhpParser\NodeTraverser.php(101): PhpParser\NodeTraverser->traverseArray(Array)
#4 C:\Users\777\.vscode-insiders\extensions\felixfbecker.php-intellisense-1.1.3\vendor\nikic\php-parser\lib\PhpParser\NodeTraverser.php(171): PhpParser\NodeTraverser->traverseNode(Object(PhpParser\Node\Stmt\While_))
#5 C:\Users\777\.vscode-insiders\extensions\felixfbecker.php-intellisense-1.1.3\vendor\nikic\php-parser\lib\PhpParser\NodeTraverser.php(85): PhpParser\NodeTraverser->traverseArray(Array)
#6 C:\Users\777\.vscode-insiders\extensions\felixfbecker.php-intellisense-1.1.3\vendor\felixfbecker\language-server\src\PhpDocument.php(205): PhpParser\NodeTraverser->traverse(Array)
#7 C:\Users\777\.vscode-insiders\extensions\felixfbecker.php-intellisense-1.1.3\vendor\felixfbecker\language-server\src\PhpDocument.php(119): LanguageServer\PhpDocument->updateContent('<?php\r\n\r\n$eatpr...')
#8 C:\Users\777\.vscode-insiders\extensions\felixfbecker.php-intellisense-1.1.3\vendor\felixfbecker\language-server\src\PhpDocumentLoader.php(134): LanguageServer\PhpDocument->__construct('file:///c:/open...', '<?php\r\n\r\n$eatpr...', Object(LanguageServer\Index\Index), Object(LanguageServer\Parser), Object(phpDocumentor\Reflection\DocBlockFactory), Object(LanguageServer\DefinitionResolver))
#9 C:\Users\777\.vscode-insiders\extensions\felixfbecker.php-intellisense-1.1.3\vendor\felixfbecker\language-server\src\PhpDocumentLoader.php(113): LanguageServer\PhpDocumentLoader->create('file:///c:/open...', '<?php\r\n\r\n$eatpr...')
#10 [internal function]: LanguageServer\PhpDocumentLoader->LanguageServer\{closure}()
#11 C:\Users\777\.vscode-insiders\extensions\felixfbecker.php-intellisense-1.1.3\vendor\sabre\event\lib\coroutine.php(70): Generator->send('<?php\r\n\r\n$eatpr...')
#12 C:\Users\777\.vscode-insiders\extensions\felixfbecker.php-intellisense-1.1.3\vendor\sabre\event\lib\Promise.php(242): Sabre\Event\{closure}('<?php\r\n\r\n$eatpr...')
#13 C:\Users\777\.vscode-insiders\extensions\felixfbecker.php-intellisense-1.1.3\vendor\sabre\event\lib\Loop\Loop.php(261): Sabre\Event\Promise->Sabre\Event\{closure}()
#14 C:\Users\777\.vscode-insiders\extensions\felixfbecker.php-intellisense-1.1.3\vendor\sabre\event\lib\Loop\Loop.php(215): Sabre\Event\Loop\Loop->runNextTicks()
#15 C:\Users\777\.vscode-insiders\extensions\felixfbecker.php-intellisense-1.1.3\vendor\sabre\event\lib\Loop\Loop.php(194): Sabre\Event\Loop\Loop->tick(true)
#16 C:\Users\777\.vscode-insiders\extensions\felixfbecker.php-intellisense-1.1.3\vendor\sabre\event\lib\Loop\functions.php(122): Sabre\Event\Loop\Loop->run()
#17 C:\Users\777\.vscode-insiders\extensions\felixfbecker.php-intellisense-1.1.3\vendor\felixfbecker\language-server\bin\php-language-server.php(50): Sabre\Event\Loop\run()
#18 {main}d.logExtensionHostMessage @ extensionHost.ts:282(anonymous function) @ extensionHost.ts:137emitTwo @ events.js:106emit @ events.js:191process.nextTick @ internal/child_process.js:744_combinedTickCallback @ internal/process/next_tick.js:67_tickCallback @ internal/process/next_tick.js:98
extensionHost.ts:282 [Extension Host] PHP process disconnected

I have found, that a returned value $def->type is null in src\DefinitionResolver.php:445
I corrected line 444 from if ($def !== null ) { to if ($def !== null && $def->type!= null) {
and it's magic, all works

Hi @Sensirex
thanks,
this works for me too

I'm curious where you got that stack trace from though
would you explain?

and maybe you can submit a PR as it seems a good fix
and so @felixfbecker can review

thanks again

go to help - toggle developer tools - go to console (on windows version)

and now you can view here all messages(traces, errors and etc.)

many thanks

let me know if you have time for the PR
if not I'll try to find time to do it

On Thu, Mar 16, 2017 at 9:16 AM, Sensirex notifications@github.com wrote:

go to help - toggle developer tools - go to console (on windows version)

and now you can view here all messages(traces, errors and etc.)

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/felixfbecker/php-language-server/issues/326#issuecomment-286986770,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABbyTmG5h5KnDPihMdai_76WMR9Qng7uks5rmO_1gaJpZM4MQzKM
.

I already had added a commit :)

my bad,

missed it in the thread ...

thanks!

it's really nice to be able to use this again :)

On Thu, Mar 16, 2017 at 9:33 AM, Sensirex notifications@github.com wrote:

I already had added a commit :)

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/felixfbecker/php-language-server/issues/326#issuecomment-286990034,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABbyTrYTVwwtEM2UQ9oRvwKs0nTZLGecks5rmPPggaJpZM4MQzKM
.

I just installed 1.2.0 and I'm getting this same problem on line 466 of DefinitionResolver now. I don't know how to tell why the specific file that kills it every time is causing that problem. For now I fixed it with this code but I'm not sure that is the right way to fix the problem:

if ($def !== null && $def->type !== null) {
    return $def->type;
}

No, it's not.

@cardonator I have version 1.2.0 and got the same exact error on _line 466_ in src/DefinitionResolver.php. I believe this is the same issue in #286 . The error is gone after changing all occurrences of:

if ($def !== null) { return $def->type; }

to:

if ($def !== null) { return $def->type ?: new Types\Mixed; }

@felixfbecker According to your last comment this seem not to be a good fix to the problem. May be this is already in your plate. I am looking forward to see a fix come out.

I can tell you the exact thing that is killing my file, it's this code right here:

<?php

class JSON
{
    private static $JSON_ERRORS = array(
        //JSON_ERROR_NONE          =>'No errors',//leave this commented out
    JSON_ERROR_DEPTH         =>'Maximum stack depth exceeded',
    JSON_ERROR_STATE_MISMATCH=>'Underflow or the modes mismatch',
    JSON_ERROR_CTRL_CHAR     =>'Unexpected control character found',
    JSON_ERROR_SYNTAX        =>'Syntax error, malformed JSON',
    JSON_ERROR_UTF8          =>'Invalid UTF-8 or bad encoding',
    );
}

I said numerous times before, the issue is not that the null case isn't handled, the issue is that the property is set to null in the first place. The code will be obsolete with #357 so I will not invest time into this issue

@felixfbecker that's fair. I didn't realize another better fix was in the works. I don't really mind a cheap manual fix when it will be fixed permanently later.

I'm unsure if the cause of my error is the same as any of the above, but basically the vendor folder of my Laravel project is crashing the language server. This doesn't happen without the vendor folder.

Here's the output.


vscode: 1.12.0-insider
php-intellisense: 1.2.0
node: 6.9.4
npm: 4.2.0
php: 7.1.4

Just a heads up to everyone watching this thread: The latest Version of PHP Intellisense (1.2.1) contains a fix for this bug. I would like to know if the problem persists or if it is fixed for all of you.

It's definitely fixed for me!

Definitely fixed for me, I'm noticing a lot of files in my project are larger than the max size limit. Is there a way to override that value?

Was this page helpful?
0 / 5 - 0 ratings