mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
add command to fix all and analyize single file
This commit is contained in:
parent
de9d626571
commit
55c65573ce
@ -186,7 +186,7 @@ Options:
|
||||
--enable-autocomplete[=BOOL]
|
||||
Enables or disables autocomplete on methods and properties. Default is true.
|
||||
|
||||
--use-extended-diagnostic-codes
|
||||
--use-extended-diagnostic-codes (DEPRECATED)
|
||||
Enables sending help uri links with the code in diagnostic messages.
|
||||
|
||||
--verbose
|
||||
@ -325,10 +325,6 @@ HELP;
|
||||
$project_analyzer->getCodebase()->reportUnusedCode($find_unused_code);
|
||||
}
|
||||
|
||||
if (isset($options['use-extended-diagnostic-codes'])) {
|
||||
$clientConfiguration->VSCodeExtendedDiagnosticCodes = true;
|
||||
}
|
||||
|
||||
if (isset($options['verbose'])) {
|
||||
$clientConfiguration->logLevel = $options['verbose'] ? MessageType::LOG : MessageType::INFO;
|
||||
}
|
||||
|
@ -60,16 +60,6 @@ class ClientConfiguration
|
||||
*/
|
||||
public $logLevel;
|
||||
|
||||
/**
|
||||
* Added in VSCode 1.43.0 and will be part of the LSP 3.16.0 standard.
|
||||
* Since this new functionality is not backwards compatible, we use a
|
||||
* configuration option so the end user must opt in to it using the cli argument.
|
||||
*
|
||||
* @var bool|null
|
||||
* @see https://github.com/microsoft/vscode/blob/1.43.0/src/vs/vscode.d.ts#L4688-L4699
|
||||
*/
|
||||
public $VSCodeExtendedDiagnosticCodes;
|
||||
|
||||
public function __construct(
|
||||
bool $hideWarnings = null,
|
||||
bool $provideCompletion = null
|
||||
|
@ -17,11 +17,13 @@ use Generator;
|
||||
use InvalidArgumentException;
|
||||
use LanguageServerProtocol\ClientCapabilities;
|
||||
use LanguageServerProtocol\ClientInfo;
|
||||
use LanguageServerProtocol\CodeDescription;
|
||||
use LanguageServerProtocol\CompletionOptions;
|
||||
use LanguageServerProtocol\Diagnostic;
|
||||
use LanguageServerProtocol\DiagnosticSeverity;
|
||||
use LanguageServerProtocol\ExecuteCommandOptions;
|
||||
use LanguageServerProtocol\InitializeResult;
|
||||
use LanguageServerProtocol\InitializeResultServerInfo;
|
||||
use LanguageServerProtocol\LogMessage;
|
||||
use LanguageServerProtocol\MessageType;
|
||||
use LanguageServerProtocol\Position;
|
||||
@ -345,7 +347,10 @@ class LanguageServer extends Dispatcher
|
||||
|
||||
$this->logInfo("Initializing: Complete.");
|
||||
$this->clientStatus('initialized');
|
||||
return new InitializeResult($serverCapabilities);
|
||||
|
||||
$initializeResultServerInfo = new InitializeResultServerInfo('Psalm Language Server', PSALM_VERSION);
|
||||
|
||||
return new InitializeResult($serverCapabilities, $initializeResultServerInfo);
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -429,6 +434,10 @@ class LanguageServer extends Dispatcher
|
||||
}
|
||||
|
||||
public function emitVersionedIssues(array $files, ?int $version = null): void {
|
||||
$this->logDebug("Perform Analysis",[
|
||||
'files' => array_keys($files),
|
||||
'version' => $version
|
||||
]);
|
||||
$data = IssueBuffer::clear();
|
||||
$this->current_issues = $data;
|
||||
|
||||
@ -472,20 +481,13 @@ class LanguageServer extends Dispatcher
|
||||
'line_to' => $issue_data->line_to
|
||||
];
|
||||
|
||||
//$code = 'PS' . \str_pad((string) $issue_data->shortcode, 3, "0", \STR_PAD_LEFT);
|
||||
$code = $issue_data->link;
|
||||
$diagnostic->code = $issue_data->shortcode;
|
||||
|
||||
if ($this->client->clientConfiguration->VSCodeExtendedDiagnosticCodes) {
|
||||
//This is a Vscode violation of the spec
|
||||
/** @psalm-suppress InvalidPropertyAssignmentValue */
|
||||
$diagnostic->code = [
|
||||
"value" => $code,
|
||||
"target" => $issue_data->link,
|
||||
];
|
||||
} else {
|
||||
// the Diagnostic constructor only takes `int` for the code, but the property can be
|
||||
// `int` or `string`, so we set the property directly because we want to use a `string`
|
||||
$diagnostic->code = $code;
|
||||
if ($this->clientCapabilities->textDocument &&
|
||||
$this->clientCapabilities->textDocument->publishDiagnostics &&
|
||||
$this->clientCapabilities->textDocument->publishDiagnostics->codeDescriptionSupport
|
||||
) {
|
||||
$diagnostic->codeDescription = new CodeDescription($issue_data->link);
|
||||
}
|
||||
|
||||
return $diagnostic;
|
||||
|
@ -446,7 +446,14 @@ class TextDocument
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
new Command("Test","test",['one'])
|
||||
new Command(
|
||||
"Fix All",
|
||||
"psalm.fixall",
|
||||
[
|
||||
'uri' => $textDocument->uri,
|
||||
'type' => $diagnostic->data->type
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Psalm\Internal\LanguageServer\Server;
|
||||
|
||||
use Amp\Success;
|
||||
use LanguageServerProtocol\FileChangeType;
|
||||
use LanguageServerProtocol\FileEvent;
|
||||
use Psalm\Codebase;
|
||||
@ -92,4 +93,42 @@ class Workspace
|
||||
);
|
||||
$this->server->client->refreshConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
* The workspace/executeCommand request is sent from the client to the server to
|
||||
* trigger command execution on the server.
|
||||
*
|
||||
* @param string $command
|
||||
* @param mixed $arguments
|
||||
* @psalm-suppress PossiblyUnusedMethod
|
||||
*/
|
||||
public function executeCommand($command, $arguments) {
|
||||
$this->server->logDebug(
|
||||
'workspace/executeCommand',
|
||||
[
|
||||
'command' => $command,
|
||||
'arguments' => $arguments,
|
||||
]
|
||||
);
|
||||
|
||||
switch($command) {
|
||||
case 'psalm.analyze.uri':
|
||||
$file = LanguageServer::uriToPath($arguments->uri);
|
||||
$codebase = $this->project_analyzer->getCodebase();
|
||||
$codebase->reloadFiles(
|
||||
$this->project_analyzer,
|
||||
[$file]
|
||||
);
|
||||
|
||||
$codebase->analyzer->addFilesToAnalyze(
|
||||
[$file => $file]
|
||||
);
|
||||
$codebase->analyzer->analyzeFiles($this->project_analyzer, 1, false);
|
||||
|
||||
$this->server->emitVersionedIssues([$file]);
|
||||
break;
|
||||
}
|
||||
|
||||
return new Success(null);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user