Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions autoload/health/phpactor.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
function! s:check_info(status) abort
call health#report_start('Info')

call health#report_info('Phpactor version: '. a:status.phpactor_version)
call health#report_info('PHP version: '. a:status.php_version)
call health#report_info('Filesystems'. join(a:status.filesystems, ', '))
call health#report_info('Working directory'. a:status.cwd)
endfunction

function! s:check_diagnostics(diagnostics) abort
call health#report_start('Diagnostics')

for [l:diagnostic, l:isOk] in items(a:diagnostics)
if l:isOk
call health#report_ok(l:diagnostic)
else
call health#report_warn(l:diagnostic)
endif
endfor
endfunction

function! s:check_config_files(configFiles) abort
call health#report_start('Config files (missing is not bad)')

for [l:configFile, l:isOk] in items(a:configFiles)
if l:isOk
call health#report_ok(l:configFile)
else
call health#report_warn(l:configFile)
endif
endfor
endfunction

function! health#phpactor#check() abort
let l:status = phpactor#rpc('status', {'type': 'detailed'})

call s:check_info(l:status)
call s:check_diagnostics(l:status.diagnostics)
call s:check_config_files(l:status.config_files)
endfunction
12 changes: 11 additions & 1 deletion autoload/phpactor.vim
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,17 @@ function! phpactor#CacheClear()
endfunction

function! phpactor#Status()
call phpactor#rpc("status", {})
if exists(':terminal')
if has('nvim')
split term://phpactor\ status
" Press any key to leave
normal i
else
terminal phpactor status
endif
else
call phpactor#rpc("status", {'type': 'formatted'})
endif
endfunction

function! phpactor#Config()
Expand Down
73 changes: 54 additions & 19 deletions lib/Extension/Core/Rpc/StatusHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,28 @@

use Phpactor\ConfigLoader\Core\PathCandidate;
use Phpactor\ConfigLoader\Core\PathCandidates;
use Phpactor\Extension\Rpc\Response\ReturnResponse;
use Phpactor\MapResolver\Resolver;
use Phpactor\Extension\Rpc\Handler;
use Phpactor\Extension\Core\Application\Status;
use Phpactor\Extension\Rpc\Response\EchoResponse;
use Phpactor\Config\Paths;

class StatusHandler implements Handler
{
const NAME = 'status';

const PARAM_TYPE = 'type';

const TYPE_FORMATTED = 'formatted';
const TYPE_DETAILED = 'detailed';

/**
* @var Status
*/
private $status;

/**
* @var Paths
* @var PathCandidates
*/
private $paths;

Expand All @@ -37,28 +42,58 @@ public function name(): string

public function configure(Resolver $resolver)
{
$resolver->setDefaults([
self::PARAM_TYPE => self::TYPE_FORMATTED,
]);
}

public function handle(array $arguments)
{
$diagnostics = $this->status->check();
return EchoResponse::fromMessage(implode(
PHP_EOL,
[
'Info',
'----',
'Version: ' . $diagnostics['phpactor_version'],
'PHP: ' . sprintf('%s (supporting %s)', phpversion(), $diagnostics['php_version']),
'Phpactor dir: ' . realpath(__DIR__ . '/../../../../'),
'Work dir: ' . $diagnostics['cwd'] . PHP_EOL,
'Diagnostics',
'-----------',
$this->buildSupportMessage($diagnostics),
'Config files',
'------------',
$this->buildConfigFileMessage(),
]
));

switch ($arguments[self::PARAM_TYPE]) {
case self::TYPE_FORMATTED:
$response = $this->handleFormattedType($diagnostics);
break;

case self::TYPE_DETAILED:
default:
$response = $this->handleDetailedType($diagnostics);
break;
}

return $response;
}

private function handleDetailedType(array $status): ReturnResponse
{
$status['diagnostics'] = \array_merge(
\array_fill_keys($status['good'], true),
\array_fill_keys($status['bad'], false),
);

unset($status['good']);
unset($status['bad']);

return ReturnResponse::fromValue($status);
}

private function handleFormattedType(array $diagnostics): EchoResponse
{
return EchoResponse::fromMessage(implode(PHP_EOL, [
'Info',
'----',
'Version: ' . $diagnostics['phpactor_version'],
'PHP: ' . sprintf('%s (supporting %s)', phpversion(), $diagnostics['php_version']),
'Phpactor dir: ' . realpath(__DIR__ . '/../../../../'),
'Work dir: ' . $diagnostics['cwd'] . PHP_EOL,
'Diagnostics',
'-----------',
$this->buildSupportMessage($diagnostics),
'Config files',
'------------',
$this->buildConfigFileMessage(),
]));
}

private function buildSupportMessage(array $diagnostics)
Expand Down
38 changes: 37 additions & 1 deletion tests/Unit/Extension/Core/Rpc/StatusHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Phpactor\ConfigLoader\Adapter\PathCandidate\AbsolutePathCandidate;
use Phpactor\ConfigLoader\Core\PathCandidates;
use Phpactor\Extension\Rpc\Response\ReturnResponse;
use Phpactor\Tests\Unit\Extension\Rpc\HandlerTestCase;
use Phpactor\Extension\Rpc\Handler;
use Phpactor\Extension\Core\Application\Status;
Expand Down Expand Up @@ -37,7 +38,7 @@ public function createHandler(): Handler
);
}

public function testStatus()
public function testMessageStatus()
{
$this->status->check()->willReturn([
'php_version' => '7.1',
Expand All @@ -54,4 +55,39 @@ public function testStatus()
$response = $this->handle('status', []);
$this->assertInstanceOf(EchoResponse::class, $response);
}

public function testDetailStatus(): void
{
$this->status->check()->willReturn([
'php_version' => '7.1',
'phpactor_version' => 'version one',
'cwd' => '/path/to/here',
'good' => ['i am good'],
'bad' => ['i am bad'],
'config_files' => [
'/config/file1.yml' => true,
'/config/file2.yml' => false,
],
'filesystems' => ['git', 'simple'],
]);

$expected = [
'php_version' => '7.1',
'phpactor_version' => 'version one',
'cwd' => '/path/to/here',
'config_files' => [
'/config/file1.yml' => true,
'/config/file2.yml' => false,
],
'filesystems' => ['git', 'simple'],
'diagnostics' => [
'i am good' => true,
'i am bad' => false,
],
];

$response = $this->handle('status', ['type' => 'detailed']);
$this->assertInstanceOf(ReturnResponse::class, $response);
$this->assertEquals($expected, $response->value());
}
}