1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 12:55:26 +01:00

Merge pull request #6010 from tm1000/feature/6008

This commit is contained in:
Bruce Weirdan 2021-06-29 04:40:00 +03:00 committed by GitHub
commit 5ea98d6324
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 10 deletions

View File

@ -12,6 +12,7 @@ use LanguageServerProtocol\DiagnosticSeverity;
use LanguageServerProtocol\InitializeResult;
use LanguageServerProtocol\Position;
use LanguageServerProtocol\Range;
use LanguageServerProtocol\SaveOptions;
use LanguageServerProtocol\ServerCapabilities;
use LanguageServerProtocol\SignatureHelpOptions;
use LanguageServerProtocol\TextDocumentSyncKind;
@ -225,6 +226,12 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
$textDocumentSyncOptions = new TextDocumentSyncOptions();
$textDocumentSyncOptions->openClose = true;
$saveOptions = new SaveOptions();
$saveOptions->includeText = true;
$textDocumentSyncOptions->save = $saveOptions;
if ($this->project_analyzer->onchange_line_limit === 0) {
$textDocumentSyncOptions->change = TextDocumentSyncKind::NONE;
} else {
@ -432,7 +439,7 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
* - 3 = Info
* - 4 = Log
*/
private function verboseLog(string $message, int $type = 4): void
public function verboseLog(string $message, int $type = 4): void
{
if ($this->project_analyzer->language_server_verbose) {
try {

View File

@ -51,18 +51,21 @@ class TextDocument
/**
* The document open notification is sent from the client to the server to signal newly opened text documents. The
* document's truth is now managed by the client and the server must not try to read the document's truth using the
* document's uri.
* documents content is now managed by the client and the server must not try to read the documents content using
* the documents Uri. Open in this sense means it is managed by the client. It doesnt necessarily mean that its
* content is presented in an editor. An open notification must not be sent more than once without a corresponding
* close notification send before. This means open and close notification must be balanced and the max open count
* for a particular textDocument is one. Note that a servers ability to fulfill requests is independent of whether
* a text document is open or closed.
*
* @param \LanguageServerProtocol\TextDocumentItem $textDocument the document that was opened
* @param TextDocumentItem $textDocument the document that was opened
*/
public function didOpen(TextDocumentItem $textDocument): void
{
$file_path = LanguageServer::uriToPath($textDocument->uri);
if (!$this->codebase->config->isInProjectDirs($file_path)) {
error_log($file_path . ' is not in project');
$this->server->verboseLog($file_path . ' is not in project');
return;
}
@ -71,11 +74,17 @@ class TextDocument
$this->server->queueFileAnalysis($file_path, $textDocument->uri);
}
/**
* 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
*/
public function didSave(TextDocumentItem $textDocument): void
{
$file_path = LanguageServer::uriToPath($textDocument->uri);
if (!$this->codebase->config->isInProjectDirs($file_path)) {
$this->server->verboseLog($file_path . ' is not in project');
return;
}
@ -94,9 +103,10 @@ class TextDocument
*/
public function didChange(VersionedTextDocumentIdentifier $textDocument, array $contentChanges): void
{
$file_path = \Psalm\Internal\LanguageServer\LanguageServer::uriToPath($textDocument->uri);
$file_path = LanguageServer::uriToPath($textDocument->uri);
if (!$this->codebase->config->isInProjectDirs($file_path)) {
$this->server->verboseLog($file_path . ' is not in project');
return;
}
@ -122,10 +132,13 @@ class TextDocument
/**
* The document close notification is sent from the client to the server when the document got closed in the client.
* The document's truth now exists where the document's uri points to (e.g. if the document's uri is a file uri the
* truth now exists on disk).
* The documents master now exists where the documents Uri points to (e.g. if the documents Uri is a file Uri the
* master now exists on disk). As with the open notification the close notification is about managing the documents
* content. Receiving a close notification doesnt mean that the document was open in an editor before. A close
* notification requires a previous open notification to be sent. Note that a servers ability to fulfill requests
* is independent of whether a text document is open or closed.
*
* @param \LanguageServerProtocol\TextDocumentIdentifier $textDocument The document that was closed
* @param TextDocumentIdentifier $textDocument The document that was closed
*
*/
public function didClose(TextDocumentIdentifier $textDocument): void
@ -286,6 +299,10 @@ class TextDocument
return new Success(new CompletionList($completion_items, false));
}
/**
* The signature help request is sent from the client to the server to request signature
* information at a given cursor position.
*/
public function signatureHelp(TextDocumentIdentifier $textDocument, Position $position): Promise
{
$file_path = LanguageServer::uriToPath($textDocument->uri);