Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve LSP #7887

Merged
merged 1 commit into from
Apr 26, 2022
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
5 changes: 0 additions & 5 deletions src/Psalm/Internal/LanguageServer/LanguageServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 3 additions & 22 deletions src/Psalm/Internal/LanguageServer/Server/TextDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Amp\Promise;
use Amp\Success;
use InvalidArgumentException;
use LanguageServerProtocol\CompletionList;
use LanguageServerProtocol\Hover;
use LanguageServerProtocol\Location;
Expand All @@ -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;
Expand Down Expand Up @@ -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
ging-dev marked this conversation as resolved.
Show resolved Hide resolved
{
$file_path = LanguageServer::uriToPath($textDocument->uri);

Expand All @@ -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);
}
Expand All @@ -122,10 +121,6 @@ public function didChange(VersionedTextDocumentIdentifier $textDocument, array $
return;
}

if ($this->project_analyzer->onchange_line_limit === 0) {
return;
}
ging-dev marked this conversation as resolved.
Show resolved Hide resolved

if (count($contentChanges) === 1 && $contentChanges[0]->range === null) {
$new_content = $contentChanges[0]->text;
} else {
Expand Down Expand Up @@ -266,8 +261,6 @@ public function hover(TextDocumentIdentifier $textDocument, Position $position):
*/
public function completion(TextDocumentIdentifier $textDocument, Position $position): Promise
{
$this->server->doAnalysis();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this is fine but because code analysis happens in the listener for group messages it gets hammered. So the analysis calls will still happen quite frequently unless the group analysis listener is removed


$file_path = LanguageServer::uriToPath($textDocument->uri);
if (!$this->codebase->config->isInProjectDirs($file_path)) {
return new Success([]);
Expand Down Expand Up @@ -361,18 +354,6 @@ public function codeAction(TextDocumentIdentifier $textDocument, Range $range):
return new Success(null);
}

$all_file_paths_to_analyze = [$file_path];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that code action can actually be passed the code through context from the issue itself. This is what I did in my own upcoming PR. But this works for now

$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])) {
Expand Down