Improve inline documentation and code style
parent
c962f81924
commit
6cb916e28d
|
@ -11,14 +11,52 @@ use PhpParser\NodeVisitor\NameResolver;
|
||||||
|
|
||||||
class PhpDocument
|
class PhpDocument
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* The LanguageClient instance (to report errors etc)
|
||||||
|
*
|
||||||
|
* @var LanguageClient
|
||||||
|
*/
|
||||||
private $client;
|
private $client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Project this document belongs to (to register definitions etc)
|
||||||
|
*
|
||||||
|
* @var Project
|
||||||
|
*/
|
||||||
private $project;
|
private $project;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The PHPParser instance
|
||||||
|
*
|
||||||
|
* @var Parser
|
||||||
|
*/
|
||||||
private $parser;
|
private $parser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The URI of the document
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
private $uri;
|
private $uri;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The content of the document
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
private $content;
|
private $content;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var SymbolInformation[]
|
||||||
|
*/
|
||||||
private $symbols = [];
|
private $symbols = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $uri The URI of the document
|
||||||
|
* @param Project $project The Project this document belongs to (to register definitions etc)
|
||||||
|
* @param LanguageClient $client The LanguageClient instance (to report errors etc)
|
||||||
|
* @param Parser $parser The PHPParser instance
|
||||||
|
*/
|
||||||
public function __construct(string $uri, Project $project, LanguageClient $client, Parser $parser)
|
public function __construct(string $uri, Project $project, LanguageClient $client, Parser $parser)
|
||||||
{
|
{
|
||||||
$this->uri = $uri;
|
$this->uri = $uri;
|
||||||
|
@ -54,6 +92,7 @@ class PhpDocument
|
||||||
* Updates the content on this document.
|
* Updates the content on this document.
|
||||||
*
|
*
|
||||||
* @param string $content
|
* @param string $content
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function updateContent(string $content)
|
public function updateContent(string $content)
|
||||||
{
|
{
|
||||||
|
@ -73,7 +112,7 @@ class PhpDocument
|
||||||
$errors = [];
|
$errors = [];
|
||||||
try {
|
try {
|
||||||
$stmts = $this->parser->parse($this->content);
|
$stmts = $this->parser->parse($this->content);
|
||||||
} catch(\PhpParser\Error $e) {
|
} catch (\PhpParser\Error $e) {
|
||||||
// Lexer can throw errors. e.g for unterminated comments
|
// Lexer can throw errors. e.g for unterminated comments
|
||||||
// unfortunately we don't get a location back
|
// unfortunately we don't get a location back
|
||||||
$errors[] = $e;
|
$errors[] = $e;
|
||||||
|
|
|
@ -13,7 +13,7 @@ class Project
|
||||||
* An associative array [string => PhpDocument]
|
* An associative array [string => PhpDocument]
|
||||||
* that maps URIs to loaded PhpDocuments
|
* that maps URIs to loaded PhpDocuments
|
||||||
*
|
*
|
||||||
* @var array
|
* @var PhpDocument[]
|
||||||
*/
|
*/
|
||||||
private $documents;
|
private $documents;
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ class Project
|
||||||
public function findSymbols(string $query)
|
public function findSymbols(string $query)
|
||||||
{
|
{
|
||||||
$queryResult = [];
|
$queryResult = [];
|
||||||
foreach($this->documents as $uri => $document) {
|
foreach ($this->documents as $uri => $document) {
|
||||||
$queryResult = array_merge($queryResult, $document->findSymbols($query));
|
$queryResult = array_merge($queryResult, $document->findSymbols($query));
|
||||||
}
|
}
|
||||||
return $queryResult;
|
return $queryResult;
|
||||||
|
|
|
@ -28,6 +28,9 @@ class TextDocument
|
||||||
*/
|
*/
|
||||||
private $client;
|
private $client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Project
|
||||||
|
*/
|
||||||
private $project;
|
private $project;
|
||||||
|
|
||||||
public function __construct(Project $project, LanguageClient $client)
|
public function __construct(Project $project, LanguageClient $client)
|
||||||
|
|
Loading…
Reference in New Issue