phpactor: Windows gVim 8.1.1 - "phpactor returned an error"

Hi, Any idea why I get the error below when I issue the :call phpactor#Status() command?

screenshot

I installed the plugin with minpac and the dependencies manually, inside the phpactor directory. Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 25

Most upvoted comments

This plugin does not work at all in windows environment because it cannot find files with windows style paths e:\this\that/.phpactor.json. Error:

Path is not absolute "e:\this\that/.phpactor.json"

This is error I get when run :call phpactor#Status()

I pushed a fix for the AbsolutePathCandidate one phpactor/config-loader@2962044

But for the first is more tricky, and without a test setup not sure how to proceed: we expect either a URI file:///path/to/my/thing or a unix path /path/to/my/thing and the parse_uri will interpret windows path with c as the scheme and fail.

So, probably need to introduce some custom logic to detect a window path and canonicalize it (with Webmozart\PathUtil\Path:cannonicalize($path))

The relevant code is here if you want to try and implement it and see if you can get Phpactor working on Windows (I’d hope that this would cover most of the cases … but not sure)

I just clean-clone the repo (default branch: develop) and this “Path is not absolute” error is still present, making phpactor completely unusable in Windows.

In most case I prefer using DIRECTORY_SEPARATOR instead of hard-coded / when I’m dealing with filesystem paths, but if it’s necessary to use / (like AbsolutePathCandidate.php did),

file://d:/folder/filename.ext

is a valid path string in windows and parse_url can correctly understand it:

D:\workspace>php -r "print_r(parse_url('file://d:/folder/filename.ext'));"
Array
(
    [scheme] => file
    [host] => d
    [path] => /folder/filename.ext
)

This may still affects a lot of code, but at least it allow / to be used across major platforms.

I don’t have Windows, so it’s difficult for me to address this issue. It would be good to run the status command with -vvv to get the stack trace, I could then try and fix the issue and we can iterate on any other similar problems that turn up.

PS C:\Users\Ben> phpactor status -vvv

In AbsolutePathCandidate.php line 27:

  [RuntimeException]
  Path is not absolute "C:\Users\Ben/.phpactor.json"


Exception trace:
  at C:\Users\Ben\AppData\Roaming\Composer\vendor\phpactor\config-loader\lib\Adapter\PathCandidate\AbsolutePathCandidate.php:27
 Phpactor\ConfigLoader\Adapter\PathCandidate\AbsolutePathCandidate->__construct() at C:\Users\Ben\AppData\Roaming\Composer\vendor\phpactor\config-loader\lib\ConfigLoaderBuilder.php:52
 Phpactor\ConfigLoader\ConfigLoaderBuilder->addCandidate() at C:\Users\Ben\AppData\Roaming\Composer\vendor\phpactor\phpactor\lib\Phpactor.php:70
 Phpactor\Phpactor::boot() at C:\Users\Ben\AppData\Roaming\Composer\vendor\phpactor\phpactor\lib\Application.php:111
 Phpactor\Application->initialize() at C:\Users\Ben\AppData\Roaming\Composer\vendor\phpactor\phpactor\lib\Application.php:38
 Phpactor\Application->doRun() at C:\Users\Ben\AppData\Roaming\Composer\vendor\symfony\console\Application.php:147
 Symfony\Component\Console\Application->run() at C:\Users\Ben\AppData\Roaming\Composer\vendor\phpactor\phpactor\bin\phpactor:42

Tried to change on

  1. TextDocumentUri.php

       if ($components["scheme"] != "file://" && strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
            $components["path"]   = "file://".$components["scheme"].":".$components["path"];
            $components["scheme"] = "file";
        }

        if (isset($components['scheme']) && $components['scheme'] !== 'file') {
            throw new InvalidUriException(sprintf(
                'Only "file://" scheme is supported, got "%s"',
                $components['scheme']
            ));
        }
  1. FilePath.php
       if ($url["scheme"] != "file://" && strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
            $url["path"]   = "file://".$url["scheme"].":".$url["path"];
            $scheme = "file";
        }

        if (null !== $scheme && 'file' !== $scheme) {
            throw new RuntimeException(sprintf('Unsupported scheme "%s" for path "%s"', $scheme, $string));
        }

Result on This.

[DEBU][732777.002492] Resolved path "%project_root%" to "D:\htdocs\hokky-laravel"[]
[DEBU][732777.008074] Resolved path "%project_root%" to "D:\htdocs\hokky-laravel"[]
[DEBU][732777.009184] Resolved path "%project_root%" to "D:\htdocs\hokky-laravel"[]
[DEBU][732777.010315] Resolved path "%project_root%/vendor/autoload.php" to "D:\htdocs\hokky-laravel/vendor/autoload.php"[]
[DEBU][732777.099341] Resolved path "%project_root%" to "D:\htdocs\hokky-laravel"[]
[DEBU][732777.100567] Resolved path "%project_root%/composer.json" to "D:\htdocs\hokky-laravel/composer.json"[] PHP Fatal error:  Uncaught TypeError: Argument 1 passed to Symfony\Component\Process\Process::__construct() must be of the type array, string given, called in C:\Users\Ben\AppData\Roaming\Composer\vendor\phpactor\phpactor\lib\Extension\Core\Application\Status.php on line 88 and defined in C:\Users\Ben\AppData\Roaming\Composer\vendor\symfony\process\Process.php:140
Stack trace:
#0 C:\Users\Ben\AppData\Roaming\Composer\vendor\phpactor\phpactor\lib\Extension\Core\Application\Status.php(88): Symfony\Component\Process\Process->__construct('git log -1 --pr...', 'C:\\Users\\Ben\\Ap...')
#1 C:\Users\Ben\AppData\Roaming\Composer\vendor\phpactor\phpactor\lib\Extension\Core\Command\StatusCommand.php(30): Phpactor\Extension\Core\Application\Status->check()
#2 C:\Users\Ben\AppData\Roaming\Composer\vendor\symfony\console\Command\Command.php(255): Phpactor\Extension\Core\Command\StatusCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 C:\Users\Ben\AppData\Roaming\Com in C:\Users\Ben\AppData\Roaming\Composer\vendor\symfony\process\Process.php on line 140
Fatal error: Uncaught TypeError: Argument 1 passed to Symfony\Component\Process\Process::__construct() must be of the type array, string given, called in C:\Users\Ben\AppData\Roaming\Composer\vendor\phpactor\phpactor\lib\Extension\Core\Application\Status.php on line 88 and defined in C:\Users\Ben\AppData\Roaming\Composer\vendor\symfony\process\Process.php:140
Stack trace:
#0 C:\Users\Ben\AppData\Roaming\Composer\vendor\phpactor\phpactor\lib\Extension\Core\Application\Status.php(88): Symfony\Component\Process\Process->__construct('git log -1 --pr...', 'C:\\Users\\Ben\\Ap...')
#1 C:\Users\Ben\AppData\Roaming\Composer\vendor\phpactor\phpactor\lib\Extension\Core\Command\StatusCommand.php(30): Phpactor\Extension\Core\Application\Status->check()
#2 C:\Users\Ben\AppData\Roaming\Composer\vendor\symfony\console\Command\Command.php(255): Phpactor\Extension\Core\Command\StatusCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 C:\Users\Ben\AppData\Roaming\Com in C:\Users\Ben\AppData\Roaming\Composer\vendor\symfony\process\Process.php on line 140

C:\Users\hetao.vim\plugged\phpactor>php bin\phpactor status -vvv

In TextDocumentUri.php line 45:

[Phpactor\TextDocument\Exception\InvalidUriException] Only “file://” scheme is supported, got “C”

Exception trace: at C:\Users\hetao.vim\plugged\phpactor\vendor\phpactor\text-document\lib\TextDocumentUri.php:45 Phpactor\TextDocument\TextDocumentUri::fromString() at C:\Users\hetao.vim\plugged\phpactor\vendor\phpactor\file-path-resolver-extension\lib\FilePathResolverExtension.php:132 Phpactor\FilePathResolverExtension\FilePathResolverExtension::calculateProjectId() at C:\Users\hetao.vim\plugged\phpactor\vendor\phpactor\file-path-resolver-extension\lib\FilePathResolverExtension.php:102 Phpactor\FilePathResolverExtension\FilePathResolverExtension->Phpactor\FilePathResolverExtension{closure}() at C:\Users\hetao.vim\plugged\phpactor\vendor\phpactor\container\lib\PhpactorContainer.php:79 Phpactor\Container\PhpactorContainer->get() at C:\Users\hetao.vim\plugged\phpactor\vendor\phpactor\file-path-resolver-extension\lib\FilePathResolverExtension.php:95 Phpactor\FilePathResolverExtension\FilePathResolverExtension->Phpactor\FilePathResolverExtension{closure}() at C:\Users\hetao.vim\plugged\phpactor\vendor\phpactor\container\lib\PhpactorContainer.php:79 Phpactor\Container\PhpactorContainer->get() at C:\Users\hetao.vim\plugged\phpactor\vendor\phpactor\file-path-resolver-extension\lib\FilePathResolverExtension.php:67 Phpactor\FilePathResolverExtension\FilePathResolverExtension->Phpactor\FilePathResolverExtension{closure}() at C:\Users\hetao.vim\plugged\phpactor\vendor\phpactor\container\lib\PhpactorContainer.php:79 Phpactor\Container\PhpactorContainer->get() at C:\Users\hetao.vim\plugged\phpactor\vendor\phpactor\source-code-filesystem-extension\lib\SourceCodeFilesystemExtension.php:95 Phpactor\Extension\SourceCodeFilesystem\SourceCodeFilesystemExtension->projectRoot() at C:\Users\hetao.vim\plugged\phpactor\vendor\phpactor\source-code-filesystem-extension\lib\SourceCodeFilesystemExtension.php:69 Phpactor\Extension\SourceCodeFilesystem\SourceCodeFilesystemExtension->Phpactor\Extension\SourceCodeFilesystem{closure}() at C:\Users\hetao.vim\plugged\phpactor\vendor\phpactor\container\lib\PhpactorContainer.php:79 Phpactor\Container\PhpactorContainer->get() at C:\Users\hetao.vim\plugged\phpactor\vendor\phpactor\source-code-filesystem-extension\lib\SourceCodeFilesystemExtension.php:53 Phpactor\Extension\SourceCodeFilesystem\SourceCodeFilesystemExtension->Phpactor\Extension\SourceCodeFilesystem{closure}() at C:\Users\hetao.vim\plugged\phpactor\vendor\phpactor\container\lib\PhpactorContainer.php:79 Phpactor\Container\PhpactorContainer->get() at C:\Users\hetao.vim\plugged\phpactor\lib\Extension\Core\CoreExtension.php:134 Phpactor\Extension\Core\CoreExtension->Phpactor\Extension\Core{closure}() at C:\Users\hetao.vim\plugged\phpactor\vendor\phpactor\container\lib\PhpactorContainer.php:79 Phpactor\Container\PhpactorContainer->get() at C:\Users\hetao.vim\plugged\phpactor\lib\Extension\Core\CoreExtension.php:87 Phpactor\Extension\Core\CoreExtension->Phpactor\Extension\Core{closure}() at C:\Users\hetao.vim\plugged\phpactor\vendor\phpactor\container\lib\PhpactorContainer.php:79 Phpactor\Container\PhpactorContainer->get() at C:\Users\hetao.vim\plugged\phpactor\vendor\symfony\console\CommandLoader\ContainerCommandLoader.php:45 Symfony\Component\Console\CommandLoader\ContainerCommandLoader->get() at C:\Users\hetao.vim\plugged\phpactor\vendor\phpactor\console-extension\lib\PhpactorCommandLoader.php:11 Phpactor\Extension\Console\PhpactorCommandLoader->get() at C:\Users\hetao.vim\plugged\phpactor\vendor\symfony\console\Application.php:541 Symfony\Component\Console\Application->has() at C:\Users\hetao.vim\plugged\phpactor\vendor\symfony\console\Application.php:634 Symfony\Component\Console\Application->find() at C:\Users\hetao.vim\plugged\phpactor\vendor\symfony\console\Application.php:235 Symfony\Component\Console\Application->doRun() at C:\Users\hetao.vim\plugged\phpactor\lib\Application.php:53 Phpactor\Application->doRun() at C:\Users\hetao.vim\plugged\phpactor\vendor\symfony\console\Application.php:147 Symfony\Component\Console\Application->run() at C:\Users\hetao.vim\plugged\phpactor\bin\phpactor:41

I pushed a fix for the AbsolutePathCandidate one https://github.com/phpactor/config-loader/commit/2962044a76d87dd60896bba060b2c0c6b7ece69d

But for the first is more tricky, and without a test setup not sure how to proceed: we expect either a URI file:///path/to/my/thing or a unix path /path/to/my/thing and the parse_uri will interpret windows path with c as the scheme and fail.

So, probably need to introduce some custom logic to detect a window path and canonicalize it (with Webmozart\PathUtil\Path:cannonicalize($path))

The relevant code is here if you want to try and implement it and see if you can get Phpactor working on Windows (I’d hope that this would cover most of the cases … but not sure)

hmm, this looks like a VIM environment problem in Windows, at least from the CLI version. This google search indicates that this might be a problem with your .bat files I guess.

You could also try running the “Linux Subsystem for Windows”.

Unfortunately I don’t have access to a Windows box, so I can’t test this further. Please update if you get any further 😃

VIM - Vi IMproved 8.1 (2018 May 18, compiled May 18 2018 18:36:07) MS-Windows 32-bit GUI version with OLE support Included patches: 1 Compiled by mool@tororo Huge version with GUI. Features included (+) or not (-): +acl +emacs_tags +mouse
+tag_binary +arabic +eval +mouseshape
+tag_old_static +autocmd +ex_extra +multi_byte_ime/dy n -tag_any_white +autoservername +extra_search +multi_lang