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};
|
2016-12-13 00:51:02 +00:00
|
|
|
use LanguageServer\Index\ProjectIndex;
|
2016-10-11 13:28:53 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
2016-12-13 00:51:02 +00:00
|
|
|
* The symbol index for the workspace
|
2016-09-30 09:30:08 +00:00
|
|
|
*
|
2016-12-13 00:51:02 +00:00
|
|
|
* @var ProjectIndex
|
2016-09-30 09:30:08 +00:00
|
|
|
*/
|
2016-12-13 00:51:02 +00:00
|
|
|
private $index;
|
2016-09-30 09:30:08 +00:00
|
|
|
|
2016-12-13 00:51:02 +00:00
|
|
|
/**
|
|
|
|
* @param ProjectIndex $index Index that is searched on a workspace/symbol request
|
|
|
|
*/
|
|
|
|
public function __construct(ProjectIndex $index, LanguageClient $client)
|
2016-09-30 09:30:08 +00:00
|
|
|
{
|
2016-12-13 00:51:02 +00:00
|
|
|
$this->index = $index;
|
2016-09-30 09:30:08 +00:00
|
|
|
$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 = [];
|
2016-12-13 00:51:02 +00:00
|
|
|
foreach ($this->index->getDefinitions() as $fqn => $definition) {
|
2016-11-18 14:22:24 +00:00
|
|
|
if ($query === '' || stripos($fqn, $query) !== false) {
|
|
|
|
$symbols[] = $definition->symbolInformation;
|
2016-10-11 12:42:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $symbols;
|
2016-09-30 09:30:08 +00:00
|
|
|
}
|
|
|
|
}
|