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;
|
|
|
|
|
2016-10-11 13:28:53 +00:00
|
|
|
use LanguageServer\{LanguageClient, Project};
|
|
|
|
use LanguageServer\Protocol\SymbolInformation;
|
2016-09-30 09:30:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
}
|
|
|
|
}
|