1
0
Fork 0
php-language-server/src/Server/Workspace.php

55 lines
1.3 KiB
PHP
Raw Normal View History

<?php
declare(strict_types = 1);
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;
/**
* 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-12-13 00:51:02 +00:00
* @var ProjectIndex
*/
2016-12-13 00:51:02 +00:00
private $index;
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-12-13 00:51:02 +00:00
$this->index = $index;
$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
{
$symbols = [];
2016-12-13 00:51:02 +00:00
foreach ($this->index->getDefinitions() as $fqn => $definition) {
if ($query === '' || stripos($fqn, $query) !== false) {
$symbols[] = $definition->symbolInformation;
}
}
return $symbols;
}
}