mirror of
https://github.com/danog/psalm.git
synced 2024-12-12 01:09:38 +01:00
ability to debounce onchange events for large projects
This commit is contained in:
parent
ceb7b95169
commit
e509aad263
@ -85,6 +85,7 @@ final class LanguageServer
|
|||||||
'enable-provide-signature-help::',
|
'enable-provide-signature-help::',
|
||||||
'enable-provide-definition::',
|
'enable-provide-definition::',
|
||||||
'show-diagnostic-warnings::',
|
'show-diagnostic-warnings::',
|
||||||
|
'on-change-debounce-ms::',
|
||||||
'use-extended-diagnostic-codes',
|
'use-extended-diagnostic-codes',
|
||||||
'verbose'
|
'verbose'
|
||||||
];
|
];
|
||||||
@ -209,6 +210,9 @@ Options:
|
|||||||
--use-extended-diagnostic-codes (DEPRECATED)
|
--use-extended-diagnostic-codes (DEPRECATED)
|
||||||
Enables sending help uri links with the code in diagnostic messages.
|
Enables sending help uri links with the code in diagnostic messages.
|
||||||
|
|
||||||
|
--on-change-debounce-ms=[INT]
|
||||||
|
The number of milliseconds to debounce onChange events.
|
||||||
|
|
||||||
--verbose
|
--verbose
|
||||||
Will send log messages to the client with information.
|
Will send log messages to the client with information.
|
||||||
|
|
||||||
@ -308,6 +312,10 @@ HELP;
|
|||||||
$clientConfiguration->onchangeLineLimit = (int) $options['disable-on-change'];
|
$clientConfiguration->onchangeLineLimit = (int) $options['disable-on-change'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($options['on-change-debounce-ms'])) {
|
||||||
|
$clientConfiguration->onChangeDebounceMs = (int) $options['on-change-debounce-ms'];
|
||||||
|
}
|
||||||
|
|
||||||
$clientConfiguration->provideDefinition = !isset($options['enable-provide-definition'])
|
$clientConfiguration->provideDefinition = !isset($options['enable-provide-definition'])
|
||||||
|| !is_string($options['enable-provide-definition'])
|
|| !is_string($options['enable-provide-definition'])
|
||||||
|| strtolower($options['enable-provide-definition']) !== 'false';
|
|| strtolower($options['enable-provide-definition']) !== 'false';
|
||||||
|
@ -106,6 +106,29 @@ class ClientConfiguration
|
|||||||
*/
|
*/
|
||||||
public $onchangeLineLimit;
|
public $onchangeLineLimit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Debounce time in milliseconds for onChange events
|
||||||
|
*
|
||||||
|
* @var int|null
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public $onChangeDebounceMs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @param boolean $hideWarnings
|
||||||
|
* @param boolean|null $provideCompletion
|
||||||
|
* @param boolean|null $provideDefinition
|
||||||
|
* @param boolean|null $provideHover
|
||||||
|
* @param boolean|null $provideSignatureHelp
|
||||||
|
* @param boolean|null $provideCodeActions
|
||||||
|
* @param boolean|null $provideDiagnostics
|
||||||
|
* @param boolean|null $findUnusedVariables
|
||||||
|
* @param 'always'|'auto'|null $findUnusedCode
|
||||||
|
* @param integer|null $logLevel
|
||||||
|
* @param integer|null $onchangeLineLimit
|
||||||
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
bool $hideWarnings = true,
|
bool $hideWarnings = true,
|
||||||
bool $provideCompletion = null,
|
bool $provideCompletion = null,
|
||||||
@ -113,6 +136,11 @@ class ClientConfiguration
|
|||||||
bool $provideHover = null,
|
bool $provideHover = null,
|
||||||
bool $provideSignatureHelp = null,
|
bool $provideSignatureHelp = null,
|
||||||
bool $provideCodeActions = null,
|
bool $provideCodeActions = null,
|
||||||
|
bool $provideDiagnostics = null,
|
||||||
|
bool $findUnusedVariables = null,
|
||||||
|
string $findUnusedCode = null,
|
||||||
|
int $logLevel = null,
|
||||||
|
int $onchangeLineLimit = null,
|
||||||
) {
|
) {
|
||||||
$this->hideWarnings = $hideWarnings;
|
$this->hideWarnings = $hideWarnings;
|
||||||
$this->provideCompletion = $provideCompletion;
|
$this->provideCompletion = $provideCompletion;
|
||||||
@ -120,5 +148,10 @@ class ClientConfiguration
|
|||||||
$this->provideHover = $provideHover;
|
$this->provideHover = $provideHover;
|
||||||
$this->provideSignatureHelp = $provideSignatureHelp;
|
$this->provideSignatureHelp = $provideSignatureHelp;
|
||||||
$this->provideCodeActions = $provideCodeActions;
|
$this->provideCodeActions = $provideCodeActions;
|
||||||
|
$this->provideDiagnostics = $provideDiagnostics;
|
||||||
|
$this->findUnusedVariables = $findUnusedVariables;
|
||||||
|
$this->findUnusedCode = $findUnusedCode;
|
||||||
|
$this->logLevel = $logLevel;
|
||||||
|
$this->onchangeLineLimit = $onchangeLineLimit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,6 +141,12 @@ class LanguageServer extends Dispatcher
|
|||||||
*/
|
*/
|
||||||
protected $codebase;
|
protected $codebase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The AMP Delay token
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $versionedAnalysisDelayToken = '';
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
ProtocolReader $reader,
|
ProtocolReader $reader,
|
||||||
ProtocolWriter $writer,
|
ProtocolWriter $writer,
|
||||||
@ -627,7 +633,7 @@ class LanguageServer extends Dispatcher
|
|||||||
*/
|
*/
|
||||||
public function queueChangeFileAnalysis(string $file_path, string $uri, ?int $version = null): void
|
public function queueChangeFileAnalysis(string $file_path, string $uri, ?int $version = null): void
|
||||||
{
|
{
|
||||||
$this->doVersionedAnalysis([$file_path => $uri], $version);
|
$this->doVersionedAnalysisDebounce([$file_path => $uri], $version);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -681,6 +687,25 @@ class LanguageServer extends Dispatcher
|
|||||||
$this->doVersionedAnalysis($opened);
|
$this->doVersionedAnalysis($opened);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Debounced Queue File Analysis with optional version
|
||||||
|
*
|
||||||
|
* @param array<string, string> $files
|
||||||
|
* @param int|null $version
|
||||||
|
*/
|
||||||
|
public function doVersionedAnalysisDebounce(array $files, ?int $version = null): void
|
||||||
|
{
|
||||||
|
Loop::cancel($this->versionedAnalysisDelayToken);
|
||||||
|
if ($this->client->clientConfiguration->onChangeDebounceMs === null) {
|
||||||
|
$this->doVersionedAnalysis($files, $version);
|
||||||
|
} else {
|
||||||
|
$this->versionedAnalysisDelayToken = Loop::delay(
|
||||||
|
$this->client->clientConfiguration->onChangeDebounceMs,
|
||||||
|
fn() => $this->doVersionedAnalysis($files, $version)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queue File Analysis with optional version
|
* Queue File Analysis with optional version
|
||||||
*
|
*
|
||||||
@ -689,13 +714,9 @@ class LanguageServer extends Dispatcher
|
|||||||
*/
|
*/
|
||||||
public function doVersionedAnalysis(array $files, ?int $version = null): void
|
public function doVersionedAnalysis(array $files, ?int $version = null): void
|
||||||
{
|
{
|
||||||
|
Loop::cancel($this->versionedAnalysisDelayToken);
|
||||||
try {
|
try {
|
||||||
if (empty($files)) {
|
$this->logDebug("Doing Analysis from version: $version");
|
||||||
$this->logWarning("No versioned analysis to do.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->logDebug("Reloading Files");
|
|
||||||
$this->codebase->reloadFiles(
|
$this->codebase->reloadFiles(
|
||||||
$this->project_analyzer,
|
$this->project_analyzer,
|
||||||
array_keys($files)
|
array_keys($files)
|
||||||
@ -705,7 +726,7 @@ class LanguageServer extends Dispatcher
|
|||||||
array_combine(array_keys($files), array_keys($files))
|
array_combine(array_keys($files), array_keys($files))
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->logDebug("Analyze Files");
|
$this->logDebug("Reloading Files");
|
||||||
$this->codebase->analyzer->analyzeFiles($this->project_analyzer, 1, false);
|
$this->codebase->analyzer->analyzeFiles($this->project_analyzer, 1, false);
|
||||||
|
|
||||||
$this->emitVersionedIssues($files, $version);
|
$this->emitVersionedIssues($files, $version);
|
||||||
|
Loading…
Reference in New Issue
Block a user