2016-09-30 09:30:08 +00:00
|
|
|
<?php
|
2016-09-30 09:54:49 +00:00
|
|
|
declare(strict_types = 1);
|
2016-09-30 09:30:08 +00:00
|
|
|
|
|
|
|
namespace LanguageServer\Server;
|
|
|
|
|
|
|
|
use PhpParser\{Error, Comment, Node, ParserFactory, NodeTraverser, Lexer};
|
|
|
|
use PhpParser\PrettyPrinter\Standard as PrettyPrinter;
|
|
|
|
use PhpParser\NodeVisitor\NameResolver;
|
2016-10-08 17:08:44 +00:00
|
|
|
use LanguageServer\{LanguageClient, ColumnCalculator, Project};
|
2016-09-30 09:30:08 +00:00
|
|
|
use LanguageServer\Protocol\{
|
|
|
|
TextDocumentItem,
|
|
|
|
TextDocumentIdentifier,
|
|
|
|
VersionedTextDocumentIdentifier,
|
|
|
|
Diagnostic,
|
|
|
|
DiagnosticSeverity,
|
|
|
|
Range,
|
|
|
|
Position,
|
|
|
|
FormattingOptions,
|
|
|
|
TextEdit,
|
|
|
|
SymbolInformation
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides method handlers for all workspace/* methods
|
|
|
|
*/
|
|
|
|
class Workspace
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The lanugage client object to call methods on the client
|
|
|
|
*
|
|
|
|
* @var \LanguageServer\LanguageClient
|
|
|
|
*/
|
|
|
|
private $client;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current project database
|
|
|
|
*
|
|
|
|
* @var Project
|
|
|
|
*/
|
|
|
|
private $project;
|
|
|
|
|
|
|
|
public function __construct(Project $project, LanguageClient $client)
|
|
|
|
{
|
|
|
|
$this->project = $project;
|
|
|
|
$this->client = $client;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The workspace symbol request is sent from the client to the server to list project-wide symbols matching the query string.
|
|
|
|
*
|
|
|
|
* @param string $query
|
|
|
|
* @return SymbolInformation[]
|
|
|
|
*/
|
|
|
|
public function symbol(string $query): array
|
|
|
|
{
|
2016-10-11 12:42:56 +00:00
|
|
|
$symbols = [];
|
|
|
|
foreach ($this->project->getDefinitionUris() as $fqn => $uri) {
|
|
|
|
if ($query === '' || stripos($fqn, $query) !== false) {
|
|
|
|
$symbols[] = SymbolInformation::fromNode($this->project->getDocument($uri)->getDefinitionByFqn($fqn), $fqn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $symbols;
|
2016-09-30 09:30:08 +00:00
|
|
|
}
|
|
|
|
}
|