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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"scripts": {
"post-install-cmd": "bin/phpactor extension:update",
"integrate": [
"vendor/bin/phpstan analyse --level=1",
"vendor/bin/phpstan analyse",
"vendor/bin/phpunit",
"vendor/bin/php-cs-fixer fix",
"config/travis/testdeps",
Expand Down
49 changes: 42 additions & 7 deletions lib/Extension/Core/Application/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,25 @@ class Status
*/
private $phpVersionResolver;

/**
* @var bool
*/
private $warnOnDevelop;

public function __construct(
FilesystemRegistry $registry,
PathCandidates $paths,
string $workingDirectory,
PhpVersionResolver $phpVersionResolver,
ExecutableFinder $executableFinder = null
ExecutableFinder $executableFinder = null,
bool $warnOnDevelop = true
) {
$this->registry = $registry;
$this->executableFinder = $executableFinder ?: new ExecutableFinder();
$this->paths = $paths;
$this->workingDirectory = $workingDirectory;
$this->phpVersionResolver = $phpVersionResolver;
$this->warnOnDevelop = $warnOnDevelop;
}

public function check(): array
Expand Down Expand Up @@ -85,15 +92,43 @@ public function check(): array
}

if ($path = $this->executableFinder->find('git')) {
$process = new Process('git log -1 --pretty=format:"%h (%ad) %f" --date=relative', __DIR__ . '/../../../..');
$process = new Process(
[
'git',
'log',
'-1',
'--pretty=format:"%h (%ad) %f REF(%D)REF',
'--date=relative'
],
__DIR__ . '/../../../..'
);
$process->run();
if ($process->getExitCode() === 0) {
$diagnostics['phpactor_version'] = $process->getOutput();
} else {
$diagnostics['phpactor_version'] = 'ERROR: ' . $process->getErrorOutput();
}
$diagnostics = array_merge($diagnostics, $this->versionInfo($process));
}

return $diagnostics;
}

private function versionInfo(Process $process): array
{
if ($process->getExitCode() !== 0) {
return [
'phpactor_version' => 'ERROR: ' . $process->getErrorOutput(),
'phpactor_is_develop' => false,
];
}

if (!preg_match('{^(.*)REF(.*?)REF}', $process->getOutput(), $matches)) {
return [
'phpactor_version' => $process->getOutput(),
'phpactor_is_develop' => false,
];
}

return [
'phpactor_version' => $matches[1],
'phpactor_is_develop' => $this->warnOnDevelop && (false !== strpos($matches[2], 'develop'))
];

}
}
10 changes: 10 additions & 0 deletions lib/Extension/Core/Command/StatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$diagnostics = $this->status->check();

if ($diagnostics['phpactor_is_develop']) {
$output->writeln("<error> </>");
$output->writeln("<error> You are using the develop </>");
$output->writeln("<error> </>");
$output->write("\n");
$output->writeln('The develop branch is no longer updated!');
$output->writeln('Switch to master or use the latest tagged version');
$output->writeln('');
}

$output->writeln('<info>Version:</info> ' . $diagnostics['phpactor_version']);
$output->writeln(sprintf(
'<info>Filesystems:</info> %s',
Expand Down
8 changes: 7 additions & 1 deletion lib/Extension/Core/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Phpactor\FilePathResolver\Expander\ValueExpander;
use Phpactor\MapResolver\Resolver;
use Phpactor\Container\ContainerBuilder;
use Symfony\Component\Process\ExecutableFinder;

class CoreExtension implements Extension
{
Expand All @@ -36,18 +37,21 @@ class CoreExtension implements Extension
const PARAM_DUMPER = 'console_dumper_default';
const PARAM_XDEBUG_DISABLE = 'xdebug_disable';
const PARAM_COMMAND = 'command';
const PARAM_WARN_ON_DEVELOP = 'core.warn_on_develop';

public function configure(Resolver $schema): void
{
$schema->setDefaults([
self::PARAM_DUMPER => 'indented',
self::PARAM_XDEBUG_DISABLE => true,
self::PARAM_COMMAND => null,
self::PARAM_WARN_ON_DEVELOP => false,
]);
$schema->setDescriptions([
self::PARAM_XDEBUG_DISABLE => 'If XDebug should be automatically disabled',
self::PARAM_COMMAND => 'Internal use only - name of the command which was executed',
self::PARAM_DUMPER => 'Name of the "dumper" (renderer) to use for some CLI commands',
self::PARAM_WARN_ON_DEVELOP => 'Internal use only: if an warning will be issed when on develop, may be removed in the future',
]);
}

Expand Down Expand Up @@ -134,7 +138,9 @@ private function registerApplicationServices(ContainerBuilder $container): void
$container->get('source_code_filesystem.registry'),
$container->get('config_loader.candidates'),
$container->get(FilePathResolverExtension::SERVICE_FILE_PATH_RESOLVER)->resolve('%project_root%'),
$container->get(PhpVersionResolver::class)
$container->get(PhpVersionResolver::class),
null,
$container->getParameter(self::PARAM_WARN_ON_DEVELOP)
);
});
}
Expand Down
13 changes: 11 additions & 2 deletions lib/Extension/Core/Rpc/StatusHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Phpactor\ConfigLoader\Core\PathCandidate;
use Phpactor\ConfigLoader\Core\PathCandidates;
use Phpactor\Extension\Rpc\Response\Input\ConfirmInput;
use Phpactor\Extension\Rpc\Response\ReturnResponse;
use Phpactor\MapResolver\Resolver;
use Phpactor\Extension\Rpc\Handler;
Expand Down Expand Up @@ -80,7 +81,7 @@ private function handleDetailedType(array $status): ReturnResponse

private function handleFormattedType(array $diagnostics): EchoResponse
{
return EchoResponse::fromMessage(implode(PHP_EOL, [
$info = [
'Info',
'----',
'Version: ' . $diagnostics['phpactor_version'],
Expand All @@ -93,7 +94,15 @@ private function handleFormattedType(array $diagnostics): EchoResponse
'Config files',
'------------',
$this->buildConfigFileMessage(),
]));
];
if ($diagnostics['phpactor_is_develop']) {
$info[] = '';
$info[] = 'WARNING';
$info[] = '-------';
$info[] = 'You are using the develop branch which is no longer maintained';
$info[] = 'Switch to master or use the latest tagged version of Phpactor';
}
return EchoResponse::fromMessage(implode(PHP_EOL, $info));
}

private function buildSupportMessage(array $diagnostics)
Expand Down
36 changes: 36 additions & 0 deletions lib/Extension/LanguageServer/LanguageServerExtraExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Phpactor\Extension\LanguageServer;

use Phpactor\Container\Container;
use Phpactor\Container\ContainerBuilder;
use Phpactor\Container\Extension;
use Phpactor\Extension\Core\CoreExtension;
use Phpactor\LanguageServer\Core\Server\ClientApi;
use Phpactor\MapResolver\Resolver;
use Phpactor\Extension\LanguageServer\Service\OnDevelopWarningService;

class LanguageServerExtraExtension implements Extension
{
/**
* {@inheritDoc}
*/
public function load(ContainerBuilder $container): void
{
$container->register(OnDevelopWarningService::class, function (Container $container) {
return new OnDevelopWarningService(
$container->get(ClientApi::class),
$container->getParameter(CoreExtension::PARAM_WARN_ON_DEVELOP)
);
}, [
LanguageServerExtension::TAG_SERVICE_PROVIDER => []
]);
}

/**
* {@inheritDoc}
*/
public function configure(Resolver $schema): void
{
}
}
56 changes: 56 additions & 0 deletions lib/Extension/LanguageServer/Service/OnDevelopWarningService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Phpactor\Extension\LanguageServer\Service;

use Amp\Promise;
use Phpactor\LanguageServer\Core\Server\ClientApi;
use Phpactor\LanguageServer\Core\Service\ServiceProvider;
use function Amp\call;
use function Amp\delay;

class OnDevelopWarningService implements ServiceProvider
{
/**
* @var ClientApi
*/
private $client;

/**
* @var bool
*/
private $warnOnDevelop;

public function __construct(ClientApi $client, bool $warnOnDevelop)
{
$this->client = $client;
$this->warnOnDevelop = $warnOnDevelop;
}

/**
* {@inheritDoc}
*/
public function services(): array
{
if (false === $this->warnOnDevelop) {
return [];
}

return [
'serviceAnnouncements',
];
}

public function serviceAnnouncements(): Promise
{
return call(function () {
$this->client->window()->showMessage()->warning(<<<'EOT'

Welcome to Phpactor!

You are using the develop branch which is no longer maintained
Switch to master or use the latest tagged version of Phpactor
EOT
);
});
}
}
2 changes: 2 additions & 0 deletions lib/Phpactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Phpactor\Extension\LanguageServerSelectionRange\LanguageServerSelectionRangeExtension;
use Phpactor\Extension\LanguageServerWorseReflection\LanguageServerWorseReflectionExtension;
use Phpactor\Extension\LanguageServer\LanguageServerExtension;
use Phpactor\Extension\LanguageServer\LanguageServerExtraExtension;
use Phpactor\Indexer\Extension\IndexerExtension;
use RuntimeException;
use Webmozart\PathUtil\Path;
Expand Down Expand Up @@ -132,6 +133,7 @@ public static function boot(InputInterface $input, string $vendorDir): Container
LanguageServerCodeTransformExtension::class,
LanguageServerSymbolProviderExtension::class,
LanguageServerSelectionRangeExtension::class,
LanguageServerExtraExtension::class,
IndexerExtension::class,
];

Expand Down
Loading