php-language-server/ langserver does not work if not in git directory
Information
VIM version
NVIM v0.3.1 Build type: Release
Operating System: macOS
What went wrong
Opening php files in a non-git directory with php-langserver already installed doesn't trigger php-langserver (as seen shown :ALEInfo).
This is easily remedied by making the current directory a git directory by running git init.
Reproducing the bug
Create a new directory with a blank index.php:
$ mkdir test
$ cd test
$ touch index.php
minimal vimrc:
call plug#begin('~/.vim/plugged')
Plug 'w0rp/ale'
call plug#end()
Installing php-langserver:
$ echo "{
"minimum-stability": "dev",
"prefer-stable": true
}" > composer.json
$ composer require felixfbecker/language-server
Open index.php and check :ALEInfo:
$ vim index.php
:ALEInfo<CR>
ALEInfo
Current Filetype: php
Available Linters: ['langserver', 'phan', 'php', 'phpcs', 'phpmd', 'phpstan', 'psalm']
Enabled Linters: ['langserver', 'phan', 'php', 'phpcs', 'phpmd', 'phpstan', 'psalm']
...
Command History:
(executable check - failure) phan
(executable check - success) php
(finished - exit code 0) ['/bin/zsh', '-c', '''php'' -l -d error_reporting=E_ALL -d display_errors=1 -d log_errors=0 -- < ''/var/folders/l1/vlhwp4js4kg3s7d38dtccw8h0000gn/T/nvimWJ8j
um/2/index.php''']
<<<OUTPUT STARTS>>>
No syntax errors detected in -
<<<OUTPUT ENDS>>>
(executable check - failure) phpcs
(executable check - failure) phpmd
(executable check - failure) phpstan
(executable check - failure) phan
(finished - exit code 0) ['/bin/zsh', '-c', '''php'' -l -d error_reporting=E_ALL -d display_errors=1 -d log_errors=0 -- < ''/var/folders/l1/vlhwp4js4kg3s7d38dtccw8h0000gn/T/nvimWJ8j
um/3/index.php''']
<<<OUTPUT STARTS>>>
No syntax errors detected in -
<<<OUTPUT ENDS>>>
(executable check - failure) phpcs
(executable check - failure) phpmd
(executable check - failure) phpstan
Then initialize git, open index.php and check :ALEInfo again:
$ git init
$ vim index.php
:ALEInfo<CR>
ALEInfo
Current Filetype: php
Available Linters: ['langserver', 'phan', 'php', 'phpcs', 'phpmd', 'phpstan', 'psalm']
Enabled Linters: ['langserver', 'phan', 'php', 'phpcs', 'phpmd', 'phpstan', 'psalm']
...
Command History:
(started) ['/bin/zsh', '-c', 'php ''/Users/bokwoon/Sites/test/vendor/bin/php-language-server.php''']
(executable check - failure) phan
(executable check - success) php
(finished - exit code 0) ['/bin/zsh', '-c', '''php'' -l -d error_reporting=E_ALL -d display_errors=1 -d log_errors=0 -- < ''/var/folders/l1/vlhwp4js4kg3s7d38dtccw8h0000gn/T/nvimKq3I
6q/2/index.php''']
<<<OUTPUT STARTS>>>
No syntax errors detected in -
<<<OUTPUT ENDS>>>
(executable check - failure) phpcs
(executable check - failure) phpmd
(executable check - failure) phpstan
(executable check - failure) phan
(finished - exit code 0) ['/bin/zsh', '-c', '''php'' -l -d error_reporting=E_ALL -d display_errors=1 -d log_errors=0 -- < ''/var/folders/l1/vlhwp4js4kg3s7d38dtccw8h0000gn/T/nvimKq3I
6q/3/index.php''']
<<<OUTPUT STARTS>>>
No syntax errors detected in -
<<<OUTPUT ENDS>>>
(executable check - failure) phpcs
(executable check - failure) phpmd
(executable check - failure) phpstan
Notice the extra line indicating that php-language-server.php has been run:
Command History:
(started) ['/bin/zsh', '-c', 'php ''/Users/bokwoon/Sites/test/vendor/bin/php-language-server.php''']
This seems to only be an issue with php-language-server, as eslint started normally with or without being in a git directory.
I don't think this is particularly significant since not being in a git directory is a rare use case, and I'm also not sure if it's an issue with ALE or with php-language-server so I'll just close this issue.
Hi, @bokwoon95. You're correct in that currently PHP projects are not correctly detected without a .git folder. PR #2062 is currently open to address this, but is missing documentation and tests. I'd suggest taking a look at the PR, if you'd like to offer input on (or even help with) the improved approach.
It might be worth mentioning that #2391 added detection of composer based projects, but that's not really enough to fully resolve this issue.