Make Descriptors minimal
SymbolDescriptor and PackageDescriptor should only contain the minumum amount of properties neededpull/424/head
parent
fced1d5af6
commit
37afb4e4a8
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace LanguageServer\Protocol;
|
||||
|
||||
/**
|
||||
* Uniquely identifies a Composer package
|
||||
*/
|
||||
class PackageDescriptor
|
||||
{
|
||||
/**
|
||||
* The package name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @param string $name The package name
|
||||
*/
|
||||
public function __construct(string $name = null)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
}
|
|
@ -3,7 +3,10 @@ declare(strict_types = 1);
|
|||
|
||||
namespace LanguageServer\Protocol;
|
||||
|
||||
class SymbolDescriptor extends SymbolInformation
|
||||
/**
|
||||
* Uniquely identifies a symbol
|
||||
*/
|
||||
class SymbolDescriptor
|
||||
{
|
||||
/**
|
||||
* The fully qualified structural element name, a globally unique identifier for the symbol.
|
||||
|
@ -13,19 +16,17 @@ class SymbolDescriptor extends SymbolInformation
|
|||
public $fqsen;
|
||||
|
||||
/**
|
||||
* A package from the composer.lock file or the contents of the composer.json
|
||||
* Example: https://github.com/composer/composer/blob/master/composer.lock#L10
|
||||
* Available fields may differ
|
||||
* Identifies the Composer package the symbol is defined in (if any)
|
||||
*
|
||||
* @var object|null
|
||||
* @var PackageDescriptor|null
|
||||
*/
|
||||
public $package;
|
||||
|
||||
/**
|
||||
* @param string $fqsen The fully qualified structural element name, a globally unique identifier for the symbol.
|
||||
* @param object $package A package from the composer.lock file or the contents of the composer.json
|
||||
* @param PackageDescriptor $package Identifies the Composer package the symbol is defined in
|
||||
*/
|
||||
public function __construct(string $fqsen = null, $package = null)
|
||||
public function __construct(string $fqsen = null, PackageDescriptor $package = null)
|
||||
{
|
||||
$this->fqsen = $fqsen;
|
||||
$this->package = $package;
|
||||
|
|
|
@ -8,7 +8,19 @@ use LanguageServer\{
|
|||
};
|
||||
use LanguageServer\Index\ReadableIndex;
|
||||
use LanguageServer\Protocol\{
|
||||
FormattingOptions, Hover, Location, MarkedString, Position, Range, ReferenceContext, SymbolDescriptor, SymbolLocationInformation, TextDocumentIdentifier, TextDocumentItem, VersionedTextDocumentIdentifier
|
||||
FormattingOptions,
|
||||
Hover,
|
||||
Location,
|
||||
MarkedString,
|
||||
Position,
|
||||
Range,
|
||||
ReferenceContext,
|
||||
SymbolDescriptor,
|
||||
PackageDescriptor,
|
||||
SymbolLocationInformation,
|
||||
TextDocumentIdentifier,
|
||||
TextDocumentItem,
|
||||
VersionedTextDocumentIdentifier
|
||||
};
|
||||
use Microsoft\PhpParser;
|
||||
use Microsoft\PhpParser\Node;
|
||||
|
@ -384,29 +396,17 @@ class TextDocument
|
|||
}
|
||||
if (
|
||||
$def === null
|
||||
|| $def->symbolInformation === null
|
||||
|| Uri\parse($def->symbolInformation->location->uri)['scheme'] === 'phpstubs'
|
||||
|| ($def->symbolInformation !== null && Uri\parse($def->symbolInformation->location->uri)['scheme'] === 'phpstubs')
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
$symbol = new SymbolDescriptor;
|
||||
foreach (get_object_vars($def->symbolInformation) as $prop => $val) {
|
||||
$symbol->$prop = $val;
|
||||
}
|
||||
$symbol->fqsen = $def->fqn;
|
||||
// if Definition is inside a dependency, use the package name
|
||||
$packageName = getPackageName($def->symbolInformation->location->uri, $this->composerJson);
|
||||
if ($packageName && $this->composerLock !== null) {
|
||||
// Definition is inside a dependency
|
||||
foreach (array_merge($this->composerLock->packages, $this->composerLock->{'packages-dev'}) as $package) {
|
||||
if ($package->name === $packageName) {
|
||||
$symbol->package = $package;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if ($this->composerJson !== null) {
|
||||
// Definition belongs to a root package
|
||||
$symbol->package = $this->composerJson;
|
||||
// else use the package name of the root package (if exists)
|
||||
if (!$packageName && $this->composerJson !== null) {
|
||||
$packageName = $this->composerJson->name;
|
||||
}
|
||||
$symbol = new SymbolDescriptor($def->fqn, new PackageDescriptor($packageName));
|
||||
return [new SymbolLocationInformation($symbol, $symbol->location)];
|
||||
});
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ use LanguageServer\Protocol\{
|
|||
FileEvent,
|
||||
SymbolInformation,
|
||||
SymbolDescriptor,
|
||||
PackageDescriptor,
|
||||
ReferenceInformation,
|
||||
DependencyReference,
|
||||
Location
|
||||
|
@ -147,19 +148,10 @@ class Workspace
|
|||
foreach ($refs as $uri => $fqns) {
|
||||
foreach ($fqns as $fqn) {
|
||||
$def = $this->dependenciesIndex->getDefinition($fqn);
|
||||
$symbol = new SymbolDescriptor;
|
||||
$symbol->fqsen = $fqn;
|
||||
foreach (get_object_vars($def->symbolInformation) as $prop => $val) {
|
||||
$symbol->$prop = $val;
|
||||
}
|
||||
// Find out package name
|
||||
$packageName = getPackageName($def->symbolInformation->location->uri, $this->composerJson);
|
||||
foreach (array_merge($this->composerLock->packages, $this->composerLock->{'packages-dev'}) as $package) {
|
||||
if ($package->name === $packageName) {
|
||||
$symbol->package = $package;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$symbol = new SymbolDescriptor($fqn, new PackageDescriptor($packageName));
|
||||
// If there was no FQSEN provided, check if query attributes match
|
||||
if (!isset($query->fqsen)) {
|
||||
$matches = true;
|
||||
|
|
Loading…
Reference in New Issue