Skip to content

Connection to server got closed. #326

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

Closed
designcraft opened this issue Mar 2, 2017 · 24 comments
Closed

Connection to server got closed. #326

designcraft opened this issue Mar 2, 2017 · 24 comments
Labels

Comments

@designcraft
Copy link

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: ....

@Alenore
Copy link

Alenore commented Mar 2, 2017

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;

@designcraft
Copy link
Author

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

@designcraft
Copy link
Author

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!

@Alenore
Copy link

Alenore commented Mar 3, 2017

@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 ;))

@felixfbecker
Copy link
Owner

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

@Alenore
Copy link

Alenore commented Mar 3, 2017

@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 :)

@felixfbecker
Copy link
Owner

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 ;)

@thomasmery
Copy link

thomasmery commented Mar 12, 2017

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

@Sensirex
Copy link

Sensirex commented Mar 16, 2017

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

Sensirex added a commit to Sensirex/php-language-server that referenced this issue Mar 16, 2017
@thomasmery
Copy link

thomasmery commented Mar 16, 2017

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

@Sensirex
Copy link

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

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

@thomasmery
Copy link

thomasmery commented Mar 16, 2017 via email

@Sensirex
Copy link

I already had added a commit :)

@thomasmery
Copy link

thomasmery commented Mar 16, 2017 via email

@cardonator
Copy link

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;
}

@felixfbecker
Copy link
Owner

No, it's not.

@chenmin201
Copy link

@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.

@cardonator
Copy link

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',
    );
}

@felixfbecker
Copy link
Owner

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

@cardonator
Copy link

@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.

@shaneparsons
Copy link

shaneparsons commented Apr 21, 2017

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

@sunverwerth
Copy link
Contributor

sunverwerth commented Apr 24, 2017

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.

@shaneparsons
Copy link

It's definitely fixed for me!

@cardonator
Copy link

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?

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

No branches or pull requests

9 participants