1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

pass progress higher up

This commit is contained in:
Andrew Nagy 2022-02-04 04:14:48 +00:00
parent 81d37311d5
commit a697c79a37
2 changed files with 32 additions and 12 deletions

View File

@ -140,10 +140,13 @@ class LanguageServer extends Dispatcher
ProtocolReader $reader, ProtocolReader $reader,
ProtocolWriter $writer, ProtocolWriter $writer,
ProjectAnalyzer $project_analyzer, ProjectAnalyzer $project_analyzer,
ClientConfiguration $clientConfiguration ClientConfiguration $clientConfiguration,
Progress $progress
) { ) {
parent::__construct($this, '/'); parent::__construct($this, '/');
$progress->setServer($this);
$this->project_analyzer = $project_analyzer; $this->project_analyzer = $project_analyzer;
$this->protocolWriter = $writer; $this->protocolWriter = $writer;
@ -229,8 +232,6 @@ class LanguageServer extends Dispatcher
$this->client = new LanguageClient($reader, $writer, $this, $clientConfiguration); $this->client = new LanguageClient($reader, $writer, $this, $clientConfiguration);
$this->project_analyzer->progress = new Progress($this);
$this->logInfo("Psalm Language Server ".PSALM_VERSION." has started."); $this->logInfo("Psalm Language Server ".PSALM_VERSION." has started.");
} }
@ -239,6 +240,7 @@ class LanguageServer extends Dispatcher
*/ */
public static function run(Config $config, ClientConfiguration $clientConfiguration, string $base_dir): void public static function run(Config $config, ClientConfiguration $clientConfiguration, string $base_dir): void
{ {
$progress = new Progress();
//no-cache mode does not work in the LSP //no-cache mode does not work in the LSP
$providers = new Providers( $providers = new Providers(
new FileProvider, new FileProvider,
@ -251,7 +253,11 @@ class LanguageServer extends Dispatcher
$project_analyzer = new ProjectAnalyzer( $project_analyzer = new ProjectAnalyzer(
$config, $config,
$providers $providers,
null,
[],
1,
$progress
); );
if ($config->find_unused_variables) { if ($config->find_unused_variables) {
@ -283,7 +289,8 @@ class LanguageServer extends Dispatcher
new ProtocolStreamReader($socket), new ProtocolStreamReader($socket),
new ProtocolStreamWriter($socket), new ProtocolStreamWriter($socket),
$project_analyzer, $project_analyzer,
$clientConfiguration $clientConfiguration,
$progress
); );
Loop::run(); Loop::run();
} elseif ($clientConfiguration->TCPServerMode && $clientConfiguration->TCPServerAddress) { } elseif ($clientConfiguration->TCPServerMode && $clientConfiguration->TCPServerAddress) {
@ -336,7 +343,8 @@ class LanguageServer extends Dispatcher
$reader, $reader,
new ProtocolStreamWriter($socket), new ProtocolStreamWriter($socket),
$project_analyzer, $project_analyzer,
$clientConfiguration $clientConfiguration,
$progress
); );
// Just for safety // Just for safety
exit(0); exit(0);
@ -348,7 +356,8 @@ class LanguageServer extends Dispatcher
new ProtocolStreamReader($socket), new ProtocolStreamReader($socket),
new ProtocolStreamWriter($socket), new ProtocolStreamWriter($socket),
$project_analyzer, $project_analyzer,
$clientConfiguration $clientConfiguration,
$progress
); );
Loop::run(); Loop::run();
} }
@ -360,7 +369,8 @@ class LanguageServer extends Dispatcher
new ProtocolStreamReader(STDIN), new ProtocolStreamReader(STDIN),
new ProtocolStreamWriter(STDOUT), new ProtocolStreamWriter(STDOUT),
$project_analyzer, $project_analyzer,
$clientConfiguration $clientConfiguration,
$progress
); );
Loop::run(); Loop::run();
} }

View File

@ -3,6 +3,7 @@
namespace Psalm\Internal\LanguageServer; namespace Psalm\Internal\LanguageServer;
use Psalm\Progress\Progress as Base; use Psalm\Progress\Progress as Base;
use function str_replace;
/** /**
* @internal * @internal
@ -11,22 +12,31 @@ class Progress extends Base
{ {
/** /**
* @var LanguageServer * @var LanguageServer|null
*/ */
private $server; private $server;
public function __construct(LanguageServer $server) public function __construct()
{
}
public function setServer(LanguageServer $server): void
{ {
$this->server = $server; $this->server = $server;
} }
public function debug(string $message): void public function debug(string $message): void
{ {
$this->server->logDebug($message); if ($this->server) {
$this->server->logDebug(str_replace("\n", "", $message));
}
} }
public function write(string $message): void public function write(string $message): void
{ {
$this->server->logInfo($message); if ($this->server) {
$this->server->logInfo(str_replace("\n", "", $message));
}
} }
} }