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

51 lines
1.2 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};
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;
/**
* 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
{
$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;
}
}