From cb10e845e0975e4c7904fcbd1fee06e8bdf449c2 Mon Sep 17 00:00:00 2001 From: ging-dev Date: Mon, 25 Apr 2022 17:43:23 +0700 Subject: [PATCH] improve LSP --- .../LanguageServer/LanguageServer.php | 5 ---- .../LanguageServer/Server/TextDocument.php | 25 +++---------------- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/src/Psalm/Internal/LanguageServer/LanguageServer.php b/src/Psalm/Internal/LanguageServer/LanguageServer.php index b78e41d3a30..3a049a62040 100644 --- a/src/Psalm/Internal/LanguageServer/LanguageServer.php +++ b/src/Psalm/Internal/LanguageServer/LanguageServer.php @@ -142,11 +142,6 @@ function (Message $msg): Generator { return; } - /** @psalm-suppress UndefinedPropertyFetch */ - if ($msg->body->method === 'textDocument/signatureHelp') { - $this->doAnalysis(); - } - $result = null; $error = null; try { diff --git a/src/Psalm/Internal/LanguageServer/Server/TextDocument.php b/src/Psalm/Internal/LanguageServer/Server/TextDocument.php index d495090e242..e4b4d1b941f 100644 --- a/src/Psalm/Internal/LanguageServer/Server/TextDocument.php +++ b/src/Psalm/Internal/LanguageServer/Server/TextDocument.php @@ -6,7 +6,6 @@ use Amp\Promise; use Amp\Success; -use InvalidArgumentException; use LanguageServerProtocol\CompletionList; use LanguageServerProtocol\Hover; use LanguageServerProtocol\Location; @@ -27,7 +26,6 @@ use Psalm\Internal\LanguageServer\LanguageServer; use UnexpectedValueException; -use function array_combine; use function array_values; use function count; use function error_log; @@ -92,8 +90,9 @@ public function didOpen(TextDocumentItem $textDocument): void * The document save notification is sent from the client to the server when the document was saved in the client * * @param TextDocumentItem $textDocument the document that was opened + * @param ?string $text the content when saved */ - public function didSave(TextDocumentItem $textDocument): void + public function didSave(TextDocumentItem $textDocument, ?string $text): void { $file_path = LanguageServer::uriToPath($textDocument->uri); @@ -103,7 +102,7 @@ public function didSave(TextDocumentItem $textDocument): void // reopen file $this->codebase->removeTemporaryFileChanges($file_path); - $this->codebase->file_provider->setOpenContents($file_path, $textDocument->text); + $this->codebase->file_provider->setOpenContents($file_path, (string) $text); $this->server->queueFileAnalysis($file_path, $textDocument->uri); } @@ -122,10 +121,6 @@ public function didChange(VersionedTextDocumentIdentifier $textDocument, array $ return; } - if ($this->project_analyzer->onchange_line_limit === 0) { - return; - } - if (count($contentChanges) === 1 && $contentChanges[0]->range === null) { $new_content = $contentChanges[0]->text; } else { @@ -266,8 +261,6 @@ public function hover(TextDocumentIdentifier $textDocument, Position $position): */ public function completion(TextDocumentIdentifier $textDocument, Position $position): Promise { - $this->server->doAnalysis(); - $file_path = LanguageServer::uriToPath($textDocument->uri); if (!$this->codebase->config->isInProjectDirs($file_path)) { return new Success([]); @@ -361,18 +354,6 @@ public function codeAction(TextDocumentIdentifier $textDocument, Range $range): return new Success(null); } - $all_file_paths_to_analyze = [$file_path]; - $this->codebase->analyzer->addFilesToAnalyze( - array_combine($all_file_paths_to_analyze, $all_file_paths_to_analyze) - ); - - try { - $this->codebase->analyzer->analyzeFiles($this->project_analyzer, 1, false); - } catch (UnexpectedValueException | InvalidArgumentException $e) { - error_log('codeAction errored on file ' . $file_path. ', Reason: '.$e->getMessage()); - return new Success(null); - } - $issues = $this->server->getCurrentIssues(); if (empty($issues[$file_path])) {