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

No suggestions in VSCode #4345

Closed
juanrgm opened this issue Jan 7, 2021 · 4 comments · Fixed by #4346
Closed

No suggestions in VSCode #4345

juanrgm opened this issue Jan 7, 2021 · 4 comments · Fixed by #4346
Labels
language server https://github.com/phan/phan/wiki/Editor-Support question

Comments

@juanrgm
Copy link

juanrgm commented Jan 7, 2021

The analysis works correctly but the I don't know why the autocompletion does not work. Other functions like go to declaration does not work either.

  • Phan 4.0.1

  • php-ast version 1.0.10

  • PHP version used to run Phan: 7.4.7

  • VSCode Extension: 2.2.0

  • ./.phan/config.php

<?php

return [
    'target_php_version' => null,
    'directory_list' => [
        'src'
    ],
    'exclude_file_regex' => '@^vendor/.*/(tests?|Tests?)/@',
    'exclude_analysis_directory_list' => [
        'vendor/'
    ],
];
  • ./src/index.php
# ./src
<?php

$dt = new DateTime();
$dt->
  • Flags
[ 
   "--unused-variable-detection",
    "--language-server-verbose",
    "--language-server-allow-missing-pcntl",
    "--allow-polyfill-parser",
    "--language-server-completion-vscode",
    "--language-server-enable-completion",
    "--language-server-enable-hover",
    "--language-server-enable-go-to-definition",
    "--use-fallback-parser",
    "--language-server-tcp-connect=127.0.0.1:50412"
]
  • Completion request
{
    "jsonrpc": "2.0",
    "id": 2,
    "method": "textDocument/completion",
    "params": {
        "textDocument": {
            "uri": "file:///d:/project/src/index.php"
        },
        "position": {
            "line": 3,
            "character": 5
        },
        "context": {
            "triggerKind": 1
        }
    }
}
  • Completion response
{
    "id": 2,
    "method": "textDocument\/completion",
    "params": {
        "textDocument": {
            "uri": "file:\/\/\/d:\/project\/src\/index.php"
        },
        "position": {
            "line": 3,
            "character": 5
        },
        "context": {
            "triggerKind": 1
        }
    },
    "jsonrpc": "2.0"
}
@TysonAndre
Copy link
Member

TysonAndre commented Jan 8, 2021

I'm not able to reproduce this on linux. I don't know why there would be issues specific to windows for this.

I see the exact same response contents as the request contents - are you sure that's the right message body for the response? It's identical to the completion request; there should be a JSON array or null somewhere in the response.
What extensions do you have installed with php? Do you continue having issues after upgrading php, disabling opcache, etc. - https://www.php.net/downloads.php#v7.4.14 is out and 7.4.7 is 7 months out of date

first
second

What happens if you clone phan, run composer install, then run PHAN_RUN_INTEGRATION_TEST=1 vendor/bin/phpunit tests/Phan/LanguageServer/LanguageServerIntegrationTest.php (I forget how to set an environment variable in windows command lines, if that's done no tests should be skipped)

Did you disable or uninstall other php language servers such as intelliphense - those may or may not interfere (haven't tried that - it's more of an issue for hover types)

You may want to disable VS Code's built-in IntelliSense for PHP by setting php.suggest.basic to false, to avoid duplicate suggestions.

@TysonAndre TysonAndre added language server https://github.com/phan/phan/wiki/Editor-Support question labels Jan 8, 2021
@juanrgm
Copy link
Author

juanrgm commented Jan 8, 2021

$ PHAN_RUN_INTEGRATION_TEST=1 vendor/bin/phpunit tests/Phan/LanguageServer/LanguageServerIntegrationTest.php
PHPUnit 8.5.13 by Sebastian Bergmann and contributors.

Time: 25.15 minutes, Memory: 8.00 MB

There were 24 failures:

1) Phan\Tests\LanguageServer\LanguageServerIntegrationTest::testCompletionBasic with data set #6 (Phan\LanguageServer\Protocol\Position Object (...), array(array('class', 6, ''M9Example'', null, null, null, null), array('my_class_const', 6, 'array{0:'literalString'}', null, null, null, null), array('my_static_function', 2, 'mixed', null, null, null, null), array('myVar', 10, 'int', null, null, null, 'myVar')), false)
Failed completions at 41:25
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
                 'filterText' => null
                 'insertText' => null
             )
-            2 => Array &5 (
-                'label' => 'my_static_function'
-                'kind' => 2
-                'detail' => 'mixed'
-                'documentation' => null
-                'sortText' => null
-                'filterText' => null
-                'insertText' => null
-            )
-            3 => Array &6 (
-                'label' => 'myVar'
-                'kind' => 10
-                'detail' => 'int'
-                'documentation' => null
-                'sortText' => null
-                'filterText' => null
-                'insertText' => 'myVar'
-            )
         )
     )
     'id' => 2
     'jsonrpc' => '2.0'
 )

D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:385
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:403
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:412

2) Phan\Tests\LanguageServer\LanguageServerIntegrationTest::testCompletionBasic with data set #7 (Phan\LanguageServer\Protocol\Position Object (...), array(array('my_static_function', 2, 'mixed', null, null, null, null), array('myInstanceVar', 10, 'int', null, null, null, null)), false)
Failed completions at 44:26
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
 Array &0 (
-    'result' => Array &1 (
-        'isIncomplete' => false
-        'items' => Array &2 (
-            0 => Array &3 (
-                'label' => 'my_static_function'
-                'kind' => 2
-                'detail' => 'mixed'
-                'documentation' => null
-                'sortText' => null
-                'filterText' => null
-                'insertText' => null
-            )
-            1 => Array &4 (
-                'label' => 'myInstanceVar'
-                'kind' => 10
-                'detail' => 'int'
-                'documentation' => null
-                'sortText' => null
-                'filterText' => null
-                'insertText' => null
-            )
-        )
-    )
+    'result' => null
     'id' => 2
     'jsonrpc' => '2.0'
 )

D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:385
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:403
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:412

3) Phan\Tests\LanguageServer\LanguageServerIntegrationTest::testCompletionBasic with data set #14 (Phan\LanguageServer\Protocol\Position Object (...), array(array('class', 6, ''M9Example'', null, null, null, null), array('my_class_const', 6, 'array{0:'literalString'}', null, null, null, null), array('my_static_function', 2, 'mixed', null, null, null, null), array('$myVar', 10, 'int', 
null, null, null, null)), true)
Failed completions at 41:25
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
                 'filterText' => null
                 'insertText' => null
             )
-            2 => Array &5 (
-                'label' => 'my_static_function'
-                'kind' => 2
-                'detail' => 'mixed'
-                'documentation' => null
-                'sortText' => null
-                'filterText' => null
-                'insertText' => null
-            )
-            3 => Array &6 (
-                'label' => '$myVar'
-                'kind' => 10
-                'detail' => 'int'
-                'documentation' => null
-                'sortText' => null
-                'filterText' => null
-                'insertText' => null
-            )
         )
     )
     'id' => 2
     'jsonrpc' => '2.0'
 )

D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:385
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:403
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:412

4) Phan\Tests\LanguageServer\LanguageServerIntegrationTest::testCompletionBasic with data set #15 (Phan\LanguageServer\Protocol\Position Object (...), array(array('my_static_function', 2, 'mixed', null, null, null, null), array('myInstanceVar', 10, 'int', null, null, null, null)), true)
Failed completions at 44:26
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
 Array &0 (
-    'result' => Array &1 (
-        'isIncomplete' => false
-        'items' => Array &2 (
-            0 => Array &3 (
-                'label' => 'my_static_function'
-                'kind' => 2
-                'detail' => 'mixed'
-                'documentation' => null
-                'sortText' => null
-                'filterText' => null
-                'insertText' => null
-            )
-            1 => Array &4 (
-                'label' => 'myInstanceVar'
-                'kind' => 10
-                'detail' => 'int'
-                'documentation' => null
-                'sortText' => null
-                'filterText' => null
-                'insertText' => null
-            )
-        )
-    )
+    'result' => null
     'id' => 2
     'jsonrpc' => '2.0'
 )

D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:385
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:403
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:412

5) Phan\Tests\LanguageServer\LanguageServerIntegrationTest::testHoverInOtherFile with data set #0 ('<?php // line 0\r\n\r\nfuncti...5\r\n}', Phan\LanguageServer\Protocol\Position Object (...), '```php\r\nclass MyClass\r\n``...yClass')
Unexpected hover response for 2:20 (0-based) on line "function example(MyClass $arg) {\r" at "lass $arg)"
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'result' => Array (
         'contents' => Array (
             'kind' => 'markdown'
-            'value' => '```php\r\n
-            class MyClass\r\n
-            ```\r\n
-            \r\n
+            'value' => '```php\n
+            class MyClass\n
+            ```\n
+            \n
             A description of MyClass'
         )
         'range' => null

D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:1428
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:893

6) Phan\Tests\LanguageServer\LanguageServerIntegrationTest::testHoverInOtherFile with data set #2 ('<?php // line 0\r\n\r\nfuncti...5\r\n}', Phan\LanguageServer\Protocol\Position Object (...), '```php\r\nconst MY_GLOBAL_CON...r\n```')
Unexpected hover response for 3:12 (0-based) on line "    echo \\MY_GLOBAL_CONST;\r" at "_GLOBAL_CO"
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'result' => Array (
         'contents' => Array (
             'kind' => 'markdown'
-            'value' => '```php\r\n
-            const MY_GLOBAL_CONST = 2\r\n
+            'value' => '```php\n
+            const MY_GLOBAL_CONST = 2\n
             ```'
         )
         'range' => null

D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:1428
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:893

7) Phan\Tests\LanguageServer\LanguageServerIntegrationTest::testHoverInOtherFile with data set #3 ('<?php // line 0\r\n\r\nfuncti...5\r\n}', Phan\LanguageServer\Protocol\Position Object (...), '```php\r\nconst MY_NAMESPACED...to 1+1')
Unexpected hover response for 4:22 (0-based) on line "    echo \\MyNS\\SubNS\\MY_NAMESPACED_CONST;\r" at "Y_NAMESPAC"
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'result' => Array (
         'contents' => Array (
             'kind' => 'markdown'
-            'value' => '```php\r\n
-            const MY_NAMESPACED_CONST = 2\r\n
-            ```\r\n
-            \r\n
+            'value' => '```php\n
+            const MY_NAMESPACED_CONST = 2\n
+            ```\n
+            \n
             This constant is equal to 1+1'
         )
         'range' => null

D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:1428
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:893

8) Phan\Tests\LanguageServer\LanguageServerIntegrationTest::testHoverInOtherFile with data set #4 ('<?php // line 0\r\n\r\nfuncti...5\r\n}', Phan\LanguageServer\Protocol\Position Object (...), '```php\r\npublic static funct...etails')
Unexpected hover response for 5:12 (0-based) on line "    $arg->myMethod();  \/\/ line 5\r" at "Method(); "
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'result' => Array (
         'contents' => Array (
             'kind' => 'markdown'
-            'value' => '```php\r\n
-            public static function myMethod(): \MyOtherClass\r\n
-            ```\r\n
-            \r\n
+            'value' => '```php\n
+            public static function myMethod(): \MyOtherClass\n
+            ```\n
+            \n
             `@return MyOtherClass` details'
         )
         'range' => null

D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:1428
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:893

9) Phan\Tests\LanguageServer\LanguageServerIntegrationTest::testHoverInOtherFile with data set #5 ('<?php // line 0\r\n\r\nfuncti...5\r\n}', Phan\LanguageServer\Protocol\Position Object (...), '```php\r\npublic function myI...string')
Unexpected hover response for 6:12 (0-based) on line "    $arg->myInstanceMethod();\r" at "InstanceMe"
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'result' => Array (
         'contents' => Array (
             'kind' => 'markdown'
-            'value' => '```php\r\n
-            public function myInstanceMethod()\r\n
-            ```\r\n
-            \r\n
+            'value' => '```php\n
+            public function myInstanceMethod()\n
+            ```\n
+            \n
             myInstanceMethod echoes a string'
         )
         'range' => null

D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:1428
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:893

10) Phan\Tests\LanguageServer\LanguageServerIntegrationTest::testHoverInOtherFile with data set #6 ('<?php // line 0\r\n\r\nfuncti...5\r\n}', Phan\LanguageServer\Protocol\Position Object (...), '```php\r\nfunction global_fun... well.')
Unexpected hover response for 7:4 (0-based) on line "    global_function_with_comment(0, '');\r" at "global_fun"
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'result' => Array (
         'contents' => Array (
             'kind' => 'markdown'
-            'value' => '```php\r\n
-            function global_function_with_comment(int $x, ?string $y): void\r\n
-            ```\r\n
-            \r\n
-            This has a mix of comments and annotations, annotations are included in hover\r\n
-            \r\n
-            - Markup in comments is preserved,\r\n
+            'value' => '```php\n
+            function global_function_with_comment(int $x, ?string $y): void\n
+            ```\n
+            \n
+            This has a mix of comments and annotations, annotations are included in hover\n
+            \n
+            - Markup in comments is preserved,\n
               and leading whitespace is as well.'
         )
         'range' => null

D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:1428
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:893

11) Phan\Tests\LanguageServer\LanguageServerIntegrationTest::testHoverInOtherFile with data set #7 ('<?php // line 0\r\n\r\nfuncti...5\r\n}', Phan\LanguageServer\Protocol\Position Object (...), '```php\r\npublic $counter\r\n... count')
Unexpected hover response for 9:10 (0-based) on line "    $c->counter += 1;\r" at "unter += 1"
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'result' => Array (
         'contents' => Array (
             'kind' => 'markdown'
-            'value' => '```php\r\n
-            public $counter\r\n
-            ```\r\n
-            \r\n
+            'value' => '```php\n
+            public $counter\n
+            ```\n
+            \n
             `@var int` this tracks a count'
         )
         'range' => null

D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:1428
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:893

12) Phan\Tests\LanguageServer\LanguageServerIntegrationTest::testHoverInOtherFile with data set #8 ('<?php // line 0\r\n\r\nfuncti...5\r\n}', Phan\LanguageServer\Protocol\Position Object (...), '```php\r\nconst HTTP_500 = 50...e code')
Unexpected hover response for 10:30 (0-based) on line "    var_export(ExampleClass::HTTP_500);  \/\/ line 10\r" at "TTP_500); "  
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'result' => Array (
         'contents' => Array (
             'kind' => 'markdown'
-            'value' => '```php\r\n
-            const HTTP_500 = 500\r\n
-            ```\r\n
-            \r\n
+            'value' => '```php\n
+            const HTTP_500 = 500\n
+            ```\n
+            \n
             `@var int` value of an HTTP response code'
         )
         'range' => null

D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:1428
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:893

13) Phan\Tests\LanguageServer\LanguageServerIntegrationTest::testHoverInOtherFile with data set #9 ('<?php // line 0\r\n\r\nfuncti...5\r\n}', Phan\LanguageServer\Protocol\Position Object (...), '```php\r\nclass ExampleClass\...eClass')
"nexpected hover response for 11:16 (0-based) on line "    var_export($c);\r" at "c);
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'result' => Array (
         'contents' => Array (
             'kind' => 'markdown'
-            'value' => '```php\r\n
-            class ExampleClass\r\n
-            ```\r\n
-            \r\n
+            'value' => '```php\n
+            class ExampleClass\n
+            ```\n
+            \n
             description of ExampleClass'
         )
         'range' => null

D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:1428
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:893

14) Phan\Tests\LanguageServer\LanguageServerIntegrationTest::testHoverInOtherFile with data set #10 ('<?php // line 0\r\n\r\nfuncti...5\r\n}', Phan\LanguageServer\Protocol\Position Object (...), '```php\r\npublic $description...lass>`')
Unexpected hover response for 12:24 (0-based) on line "    var_export($c->descriptionlessProp); var_export(ExampleClass::$typelessProp);\r" at "iptionless"
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'result' => Array (
         'contents' => Array (
             'kind' => 'markdown'
-            'value' => '```php\r\n
-            public $descriptionlessProp\r\n
-            ```\r\n
-            \r\n
+            'value' => '```php\n
+            public $descriptionlessProp\n
+            ```\n
+            \n
             `@var array<string, \stdClass>`'
         )
         'range' => null

D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:1428
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:893

15) Phan\Tests\LanguageServer\LanguageServerIntegrationTest::testHoverInOtherFile with data set #11 ('<?php // line 0\r\n\r\nfuncti...5\r\n}', Phan\LanguageServer\Protocol\Position Object (...), '```php\r\npublic static $type...o type')
Unexpected hover response for 12:70 (0-based) on line "    var_export($c->descriptionlessProp); var_export(ExampleClass::$typelessProp);\r" at "elessProp)"
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'result' => Array (
         'contents' => Array (
             'kind' => 'markdown'
-            'value' => '```php\r\n
-            public static $typelessProp\r\n
-            ```\r\n
-            \r\n
+            'value' => '```php\n
+            public static $typelessProp\n
+            ```\n
+            \n
             This has no type'
         )
         'range' => null

D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:1428
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:893

16) Phan\Tests\LanguageServer\LanguageServerIntegrationTest::testHoverInOtherFile with data set #14 ('<?php // line 0\r\n\r\nfuncti...5\r\n}', Phan\LanguageServer\Protocol\Position Object (...), '```php\r\nfunction strlen(str...length')
Unexpected hover response for 22:10 (0-based) on line "    echo strlen($strVal);\r" at "trlen($str"
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'result' => Array (
         'contents' => Array (
             'kind' => 'markdown'
-            'value' => '```php\r\n
-            function strlen(string $string): int\r\n
-            ```\r\n
-            \r\n
+            'value' => '```php\n
+            function strlen(string $string): int\n
+            ```\n
+            \n
             Get string length'
         )
         'range' => null

D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:1428
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:893

17) Phan\Tests\LanguageServer\LanguageServerIntegrationTest::testHoverInOtherFile with data set #15 ('<?php // line 0\r\n\r\nfuncti...5\r\n}', Phan\LanguageServer\Protocol\Position Object (...), '```php\r\nnamespace ast;\r\nf... node.')
Unexpected hover response for 23:14 (0-based) on line "    $n = ast\\parse_code($strVal, 70);\r" at "arse_code("
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'result' => Array (
         'contents' => Array (
             'kind' => 'markdown'
-            'value' => '```php\r\n
-            namespace ast;\r\n
-            function parse_code(string $code, int $version, string $filename = unknown): \ast\Node\r\n
-            ```\r\n
-            \r\n
+            'value' => '```php\n
+            namespace ast;\n
+            function parse_code(string $code, int $version, string $filename = unknown): \ast\Node\n
+            ```\n
+            \n
             Parses code string and returns AST root node.'
         )
         'range' => null

D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:1428
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:893

18) Phan\Tests\LanguageServer\LanguageServerIntegrationTest::testHoverInOtherFile with data set #16 ('<?php // line 0\r\n\r\nfuncti...5\r\n}', Phan\LanguageServer\Protocol\Position Object (...), '```php\r\npublic $propWithDef...efault')
Unexpected hover response for 26:20 (0-based) on line "    var_export($c->propWithDefault);\r" at "ropWithDef"
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'result' => Array (
         'contents' => Array (
             'kind' => 'markdown'
-            'value' => '```php\r\n
-            public $propWithDefault\r\n
-            ```\r\n
-            \r\n
+            'value' => '```php\n
+            public $propWithDefault\n
+            ```\n
+            \n
             `@var array{0:2,1:3}` This has a default'
         )
         'range' => null

D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:1428
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:893

19) Phan\Tests\LanguageServer\LanguageServerIntegrationTest::testHoverInOtherFile with data set #17 ('<?php // line 0\r\n\r\nfuncti...5\r\n}', Phan\LanguageServer\Protocol\Position Object (...), '```php\r\nconst JSON_PRETTY_P...5.4.0.')
Unexpected hover response for 27:12 (0-based) on line "    echo JSON_PRETTY_PRINT;\r" at "N_PRETTY_P"
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'result' => Array (
         'contents' => Array (
             'kind' => 'markdown'
-            'value' => '```php\r\n
-            const JSON_PRETTY_PRINT = 128\r\n
-            ```\r\n
-            \r\n
+            'value' => '```php\n
+            const JSON_PRETTY_PRINT = 128\n
+            ```\n
+            \n
             Use whitespace in returned data to format it. Available since PHP 5.4.0.'
         )
         'range' => null

D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:1428
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:893

20) Phan\Tests\LanguageServer\LanguageServerIntegrationTest::testHoverInOtherFile with data set #18 ('<?php // line 0\r\n\r\nfuncti...5\r\n}', Phan\LanguageServer\Protocol\Position Object (...), '```php\r\npublic function __c...fails.')
Unexpected hover response for 28:45 (0-based) on line "    if (rand() % 2 > 0) { throw new AssertionError('some condition failed'); }\r" at "Error('som"
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'result' => Array (
         'contents' => Array (
             'kind' => 'markdown'
-            'value' => '```php\r\n
-            public function __construct(string $message = unknown, int $code = unknown, ?\Error|?\Throwable $previous = null): void\r\n
-            ```\r\n
-            \r\n
-            Construct an instance of `\AssertionError`.\r\n
-            \r\n
+            'value' => '```php\n
+            public function __construct(string $message = unknown, int $code = unknown, ?\Error|?\Throwable $previous = null): void\n
+            ```\n
+            \n
+            Construct an instance of `\AssertionError`.\n
+            \n
             `AssertionError` is thrown when an assertion made via `assert` fails.'
         )
         'range' => null

D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:1428
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:893

21) Phan\Tests\LanguageServer\LanguageServerIntegrationTest::testHoverInOtherFile with data set #19 ('<?php // line 0\r\n\r\nfuncti...5\r\n}', Phan\LanguageServer\Protocol\Position Object (...), '```php\r\npublic $kind\r\n```...tants.')
Unexpected hover response for 30:20 (0-based) on line "    var_export($n->kind);  \/\/ line 30\r" at "ind);  // "
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'result' => Array (
         'contents' => Array (
             'kind' => 'markdown'
-            'value' => '```php\r\n
-            public $kind\r\n
-            ```\r\n
-            \r\n
+            'value' => '```php\n
+            public $kind\n
+            ```\n
+            \n
             AST Node Kind. Values are one of `ast\AST_*` constants.'
         )
         'range' => null

D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:1428
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:893

22) Phan\Tests\LanguageServer\LanguageServerIntegrationTest::testHoverInOtherFile with data set #21 ('<?php // line 0\r\n\r\nfuncti...5\r\n}', Phan\LanguageServer\Protocol\Position Object (...), '```php\r\npublic function cou...Object')
"nexpected hover response for 33:22 (0-based) on line "    var_export($y->count());\r" at "nt());
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'result' => Array (
         'contents' => Array (
             'kind' => 'markdown'
-            'value' => '```php\r\n
-            public function count(): int\r\n
-            ```\r\n
-            \r\n
+            'value' => '```php\n
+            public function count(): int\n
+            ```\n
+            \n
             Get the number of public properties in the ArrayObject'
         )
         'range' => null

D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:1428
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:893

23) Phan\Tests\LanguageServer\LanguageServerIntegrationTest::testHoverInOtherFile with data set #22 ('<?php // line 0\r\n\r\nfuncti...5\r\n}', Phan\LanguageServer\Protocol\Position Object (...), '```php\r\npublic function cou...Object')
Unexpected hover response for 35:22 (0-based) on line "    var_export($z->count());  \/\/ line 35\r" at "nt());  //"
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'result' => Array (
         'contents' => Array (
             'kind' => 'markdown'
-            'value' => '```php\r\n
-            public function count(): int\r\n
-            ```\r\n
-            \r\n
+            'value' => '```php\n
+            public function count(): int\n
+            ```\n
+            \n
             Get the number of public properties in the ArrayObject'
         )
         'range' => null

D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:1428
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:893

24) Phan\Tests\LanguageServer\LanguageServerIntegrationTest::testHoverInOtherFile with data set #23 ('<?php // line 0\r\n\r\nfuncti...5\r\n}', Phan\LanguageServer\Protocol\Position Object (...), '```php\r\nclass anonymous_cla... class')
Unexpected hover response for 35:16 (0-based) on line "    var_export($z->count());  \/\/ line 35\r" at "z->count()"
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'result' => Array (
         'contents' => Array (
             'kind' => 'markdown'
-            'value' => '```php\r\n
-            class anonymous_class\r\n
-            ```\r\n
-            \r\n
+            'value' => '```php\n
+            class anonymous_class\n
+            ```\n
+            \n
             Documentation of anonymous class'
         )
         'range' => null

D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:1428
D:\repo\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:893

FAILURES!
Tests: 80, Assertions: 927, Failures: 24, Skipped: 3.

@TysonAndre
Copy link
Member

I can reproduce the unit test failure and overall slowness (and the test failure) if I run unix2dos to convert \n to \r\n in tests\Phan\LanguageServer\LanguageServerIntegrationTest.php and then run wine /mnt/DATA/software/php-7.4.14-nts-windows/php.exe vendor/phpunit/phpunit/phpunit --testdox tests/Phan/LanguageServer/LanguageServerIntegrationTest.php

  • This is definitely a bug that should be fixed
  • I suspect your editor is saving all files with the windows file format - if it saved files with unix newlines that might work around this issue

(Running it on tests/misc/lsp/ for other files didn't have any impact)

So it may somehow be an issue specific to completions when the character following the cursor is \r instead of \n.
(e.g. phan's check if the cursor is at the end of a line)

A simpler way to reproduce this than running unix2dos is this patch (for which tests on Linux fail quickly (< 2 seconds each), and tests on Windows surprisingly fail slowly):

--- a/tests/Phan/LanguageServer/LanguageServerIntegrationTest.php
+++ b/tests/Phan/LanguageServer/LanguageServerIntegrationTest.php
@@ -1966,6 +1966,7 @@ EOT;
      */
     private static function writeDidChangeNotificationToFile($proc_in, string $requested_uri, string $new_contents): void
     {
+        $new_contents = \str_replace("\n", "\r\n", $new_contents);
         $params = [
             'textDocument' => ['uri' => $requested_uri],
             'contentChanges' => [
Language Server Integration (Phan\Tests\LanguageServer\LanguageServerIntegration)
 ��� Initialize with data set 0
 ��� Initialize with data set 1
 ��� Generate diagnostics with data set 0
 ��� Generate diagnostics with data set 1
 ��� Definition in same file
 ��� Completion basic with data set 0
 ��� Completion basic with data set 1
 ��� Completion basic with data set 2
 ��� Completion basic with data set 3
 ��� Completion basic with data set 4
 ��� Completion basic with data set 5
 ��� Completion basic with data set 6
   ���
   ��� Failed completions at 41:25                     
   ��� Failed asserting that two arrays are identical. 
   ��� --- Expected                                    
   ��� +++ Actual                                      
   ��� @@ @@                                           
   ���                  'filterText' => null           
   ���                  'insertText' => null           
   ���              )                                  
   ��� -            2 => Array &5 (                    
   ��� -                'label' => 'my_static_function'
   ��� -                'kind' => 2                    
   ��� -                'detail' => 'mixed'            
   ��� -                'documentation' => null        
   ��� -                'sortText' => null             
   ��� -                'filterText' => null           
   ��� -                'insertText' => null           
   ��� -            )                                  
   ��� -            3 => Array &6 (                    
   ��� -                'label' => 'myVar'             
   ��� -                'kind' => 10                   
   ��� -                'detail' => 'int'              
   ��� -                'documentation' => null        
   ��� -                'sortText' => null             
   ��� -                'filterText' => null           
   ��� -                'insertText' => 'myVar'        
   ��� -            )                                  
   ���          )                                      
   ���      )                                          
   ���      'id' => 2                                  
   ���      'jsonrpc' => '2.0'                         
   ���  )                                              
   ���
   ��� Z:\path\to\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:385
   ��� Z:\path\to\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:403
   ��� Z:\path\to\phan\tests\Phan\LanguageServer\LanguageServerIntegrationTest.php:412
   ���

@TysonAndre
Copy link
Member

This should be fixed in version 3.0.0 of the vscode extension (by default, it uses an installation of Phan bundled with that extension, not the phan version installed in the project) and in version 4.0.2 of Phan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language server https://github.com/phan/phan/wiki/Editor-Support question
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants