Different language server settings per project
asgrim opened this issue · comments
We're using Psalm's language server in PHP for some projects, but across different projects (I have a lot), some don't use Psalm, some even have Psalm in a different, odd, location.
Unfortunately the differing configurations per project means using intellij-lsp
is not an option currently (since there is no support), and AFAIK there's no other option, which means I can't use anything currently, unless I reconfigure every time I open a project 😢
Please add different settings per project.
According to the odd locations, I created a wrapper to start the LS, which looks for the first psalm.xml it finds (excluding vendor):
It's dirty, but it may help:
#!/usr/bin/php -dvariables_order=EGPCS
<?php
$args = $_SERVER['argv'];
$executable = '/path/to/psalm-language-server';
if (!in_array('-r', $args, true)) {
$candidates = new CallbackFilterIterator(
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(getcwd(), RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::LEAVES_ONLY
),
fn (SplFileInfo $file): bool => $file->getFilename() === 'psalm.xml'
&& strpos($file->getPathname(), 'vendor/') === false
);
$candidates->rewind();
if ($candidates->valid()) {
$file = $candidates->current();
assert($file instanceof SplFileInfo);
array_push($args, '-r', $file->getPath());
}
}
array_shift($args);
pcntl_exec($executable, $args, $_ENV);
throw new RuntimeException('Failed to start language server!');