initialize tolerant-php-parser
parent
56bd465bf8
commit
13241a7be9
|
@ -5,3 +5,4 @@ vendor/
|
||||||
.phpls/
|
.phpls/
|
||||||
composer.lock
|
composer.lock
|
||||||
stubs
|
stubs
|
||||||
|
*.ast
|
|
@ -38,9 +38,16 @@
|
||||||
"webmozart/glob": "^4.1",
|
"webmozart/glob": "^4.1",
|
||||||
"sabre/uri": "^2.0",
|
"sabre/uri": "^2.0",
|
||||||
"jetbrains/phpstorm-stubs": "dev-master",
|
"jetbrains/phpstorm-stubs": "dev-master",
|
||||||
"composer/composer": "^1.3"
|
"composer/composer": "^1.3",
|
||||||
|
"Microsoft/tolerant-php-parser": "master"
|
||||||
},
|
},
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
|
"repositories": [
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/Microsoft/tolerant-php-parser.git"
|
||||||
|
}
|
||||||
|
],
|
||||||
"prefer-stable": true,
|
"prefer-stable": true,
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|
|
@ -121,6 +121,7 @@ class CompletionProvider
|
||||||
*/
|
*/
|
||||||
public function provideCompletion(PhpDocument $doc, Position $pos): CompletionList
|
public function provideCompletion(PhpDocument $doc, Position $pos): CompletionList
|
||||||
{
|
{
|
||||||
|
// This can be made much more performant if the tree follows specific invariants.
|
||||||
$node = $doc->getNodeAtPosition($pos);
|
$node = $doc->getNodeAtPosition($pos);
|
||||||
|
|
||||||
if ($node instanceof Node\Expr\Error) {
|
if ($node instanceof Node\Expr\Error) {
|
||||||
|
|
|
@ -10,6 +10,7 @@ use phpDocumentor\Reflection\DocBlockFactory;
|
||||||
use Webmozart\PathUtil\Path;
|
use Webmozart\PathUtil\Path;
|
||||||
use Sabre\Uri;
|
use Sabre\Uri;
|
||||||
use function Sabre\Event\coroutine;
|
use function Sabre\Event\coroutine;
|
||||||
|
use Microsoft\PhpParser as Tolerant;
|
||||||
|
|
||||||
foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../autoload.php', __DIR__ . '/../vendor/autoload.php'] as $file) {
|
foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../autoload.php', __DIR__ . '/../vendor/autoload.php'] as $file) {
|
||||||
if (file_exists($file)) {
|
if (file_exists($file)) {
|
||||||
|
@ -30,6 +31,7 @@ class ComposerScripts
|
||||||
$contentRetriever = new FileSystemContentRetriever;
|
$contentRetriever = new FileSystemContentRetriever;
|
||||||
$docBlockFactory = DocBlockFactory::createInstance();
|
$docBlockFactory = DocBlockFactory::createInstance();
|
||||||
$parser = new Parser;
|
$parser = new Parser;
|
||||||
|
$tolerantParser = new Tolerant\Parser();
|
||||||
$definitionResolver = new DefinitionResolver($index);
|
$definitionResolver = new DefinitionResolver($index);
|
||||||
|
|
||||||
$stubsLocation = null;
|
$stubsLocation = null;
|
||||||
|
@ -55,7 +57,7 @@ class ComposerScripts
|
||||||
$parts['scheme'] = 'phpstubs';
|
$parts['scheme'] = 'phpstubs';
|
||||||
$uri = Uri\build($parts);
|
$uri = Uri\build($parts);
|
||||||
|
|
||||||
$document = new PhpDocument($uri, $content, $index, $parser, $docBlockFactory, $definitionResolver);
|
$document = new PhpDocument($uri, $content, $index, $parser, $tolerantParser, $docBlockFactory, $definitionResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
$index->setComplete();
|
$index->setComplete();
|
||||||
|
|
|
@ -17,6 +17,7 @@ use PhpParser\{Error, ErrorHandler, Node, NodeTraverser};
|
||||||
use PhpParser\NodeVisitor\NameResolver;
|
use PhpParser\NodeVisitor\NameResolver;
|
||||||
use phpDocumentor\Reflection\DocBlockFactory;
|
use phpDocumentor\Reflection\DocBlockFactory;
|
||||||
use Sabre\Uri;
|
use Sabre\Uri;
|
||||||
|
use Microsoft\PhpParser as Tolerant;
|
||||||
|
|
||||||
class PhpDocument
|
class PhpDocument
|
||||||
{
|
{
|
||||||
|
@ -108,12 +109,14 @@ class PhpDocument
|
||||||
string $content,
|
string $content,
|
||||||
Index $index,
|
Index $index,
|
||||||
Parser $parser,
|
Parser $parser,
|
||||||
|
Tolerant\Parser $tolerantParser,
|
||||||
DocBlockFactory $docBlockFactory,
|
DocBlockFactory $docBlockFactory,
|
||||||
DefinitionResolver $definitionResolver
|
DefinitionResolver $definitionResolver
|
||||||
) {
|
) {
|
||||||
$this->uri = $uri;
|
$this->uri = $uri;
|
||||||
$this->index = $index;
|
$this->index = $index;
|
||||||
$this->parser = $parser;
|
$this->parser = $parser;
|
||||||
|
$this->tolerantParser = $tolerantParser;
|
||||||
$this->docBlockFactory = $docBlockFactory;
|
$this->docBlockFactory = $docBlockFactory;
|
||||||
$this->definitionResolver = $definitionResolver;
|
$this->definitionResolver = $definitionResolver;
|
||||||
$this->updateContent($content);
|
$this->updateContent($content);
|
||||||
|
@ -133,7 +136,7 @@ class PhpDocument
|
||||||
/**
|
/**
|
||||||
* Updates the content on this document.
|
* Updates the content on this document.
|
||||||
* Re-parses a source file, updates symbols and reports parsing errors
|
* Re-parses a source file, updates symbols and reports parsing errors
|
||||||
* that may have occured as diagnostics.
|
* that may have occurred as diagnostics.
|
||||||
*
|
*
|
||||||
* @param string $content
|
* @param string $content
|
||||||
* @return void
|
* @return void
|
||||||
|
@ -168,7 +171,7 @@ class PhpDocument
|
||||||
$this->diagnostics[] = Diagnostic::fromError($error, $this->content, DiagnosticSeverity::ERROR, 'php');
|
$this->diagnostics[] = Diagnostic::fromError($error, $this->content, DiagnosticSeverity::ERROR, 'php');
|
||||||
}
|
}
|
||||||
|
|
||||||
// $stmts can be null in case of a fatal parsing error
|
// $stmts can be null in case of a fatal parsing error <- Interesting. When do fatal parsing errors occur?
|
||||||
if ($stmts) {
|
if ($stmts) {
|
||||||
$traverser = new NodeTraverser;
|
$traverser = new NodeTraverser;
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ use LanguageServer\Index\ProjectIndex;
|
||||||
use phpDocumentor\Reflection\DocBlockFactory;
|
use phpDocumentor\Reflection\DocBlockFactory;
|
||||||
use Sabre\Event\Promise;
|
use Sabre\Event\Promise;
|
||||||
use function Sabre\Event\coroutine;
|
use function Sabre\Event\coroutine;
|
||||||
|
use Microsoft\PhpParser as Tolerant;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes care of loading documents and managing "open" documents
|
* Takes care of loading documents and managing "open" documents
|
||||||
|
@ -36,6 +37,11 @@ class PhpDocumentLoader
|
||||||
*/
|
*/
|
||||||
private $parser;
|
private $parser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Tolerant\Parser
|
||||||
|
*/
|
||||||
|
private $tolerantParser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var DocBlockFactory
|
* @var DocBlockFactory
|
||||||
*/
|
*/
|
||||||
|
@ -60,6 +66,7 @@ class PhpDocumentLoader
|
||||||
$this->projectIndex = $projectIndex;
|
$this->projectIndex = $projectIndex;
|
||||||
$this->definitionResolver = $definitionResolver;
|
$this->definitionResolver = $definitionResolver;
|
||||||
$this->parser = new Parser;
|
$this->parser = new Parser;
|
||||||
|
$this->tolerantParser = new Tolerant\Parser();
|
||||||
$this->docBlockFactory = DocBlockFactory::createInstance();
|
$this->docBlockFactory = DocBlockFactory::createInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,6 +137,7 @@ class PhpDocumentLoader
|
||||||
$content,
|
$content,
|
||||||
$this->projectIndex->getIndexForUri($uri),
|
$this->projectIndex->getIndexForUri($uri),
|
||||||
$this->parser,
|
$this->parser,
|
||||||
|
$this->tolerantParser,
|
||||||
$this->docBlockFactory,
|
$this->docBlockFactory,
|
||||||
$this->definitionResolver
|
$this->definitionResolver
|
||||||
);
|
);
|
||||||
|
|
|
@ -3,7 +3,6 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Server;
|
namespace LanguageServer\Server;
|
||||||
|
|
||||||
use PhpParser\PrettyPrinter\Standard as PrettyPrinter;
|
|
||||||
use PhpParser\{Node, NodeTraverser};
|
use PhpParser\{Node, NodeTraverser};
|
||||||
use LanguageServer\{LanguageClient, PhpDocumentLoader, PhpDocument, DefinitionResolver, CompletionProvider};
|
use LanguageServer\{LanguageClient, PhpDocumentLoader, PhpDocument, DefinitionResolver, CompletionProvider};
|
||||||
use LanguageServer\NodeVisitor\VariableReferencesCollector;
|
use LanguageServer\NodeVisitor\VariableReferencesCollector;
|
||||||
|
@ -49,11 +48,6 @@ class TextDocument
|
||||||
*/
|
*/
|
||||||
protected $project;
|
protected $project;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var PrettyPrinter
|
|
||||||
*/
|
|
||||||
protected $prettyPrinter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var DefinitionResolver
|
* @var DefinitionResolver
|
||||||
*/
|
*/
|
||||||
|
@ -97,7 +91,6 @@ class TextDocument
|
||||||
) {
|
) {
|
||||||
$this->documentLoader = $documentLoader;
|
$this->documentLoader = $documentLoader;
|
||||||
$this->client = $client;
|
$this->client = $client;
|
||||||
$this->prettyPrinter = new PrettyPrinter();
|
|
||||||
$this->definitionResolver = $definitionResolver;
|
$this->definitionResolver = $definitionResolver;
|
||||||
$this->completionProvider = new CompletionProvider($this->definitionResolver, $index);
|
$this->completionProvider = new CompletionProvider($this->definitionResolver, $index);
|
||||||
$this->index = $index;
|
$this->index = $index;
|
||||||
|
|
|
@ -14,6 +14,7 @@ use LanguageServer\Index\{ProjectIndex, Index, DependenciesIndex};
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
use LanguageServer\Tests\MockProtocolStream;
|
||||||
use LanguageServer\NodeVisitor\{ReferencesAdder, DefinitionCollector};
|
use LanguageServer\NodeVisitor\{ReferencesAdder, DefinitionCollector};
|
||||||
use function LanguageServer\pathToUri;
|
use function LanguageServer\pathToUri;
|
||||||
|
use Microsoft\PhpParser as Tolerant;
|
||||||
|
|
||||||
class DefinitionCollectorTest extends TestCase
|
class DefinitionCollectorTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -22,11 +23,12 @@ class DefinitionCollectorTest extends TestCase
|
||||||
$path = realpath(__DIR__ . '/../../fixtures/symbols.php');
|
$path = realpath(__DIR__ . '/../../fixtures/symbols.php');
|
||||||
$uri = pathToUri($path);
|
$uri = pathToUri($path);
|
||||||
$parser = new Parser;
|
$parser = new Parser;
|
||||||
|
$tolerantParser = new Tolerant\Parser();
|
||||||
$docBlockFactory = DocBlockFactory::createInstance();
|
$docBlockFactory = DocBlockFactory::createInstance();
|
||||||
$index = new Index;
|
$index = new Index;
|
||||||
$definitionResolver = new DefinitionResolver($index);
|
$definitionResolver = new DefinitionResolver($index);
|
||||||
$content = file_get_contents($path);
|
$content = file_get_contents($path);
|
||||||
$document = new PhpDocument($uri, $content, $index, $parser, $docBlockFactory, $definitionResolver);
|
$document = new PhpDocument($uri, $content, $index, $parser, $tolerantParser, $docBlockFactory, $definitionResolver);
|
||||||
$stmts = $parser->parse($content);
|
$stmts = $parser->parse($content);
|
||||||
|
|
||||||
$traverser = new NodeTraverser;
|
$traverser = new NodeTraverser;
|
||||||
|
@ -70,11 +72,12 @@ class DefinitionCollectorTest extends TestCase
|
||||||
$path = realpath(__DIR__ . '/../../fixtures/references.php');
|
$path = realpath(__DIR__ . '/../../fixtures/references.php');
|
||||||
$uri = pathToUri($path);
|
$uri = pathToUri($path);
|
||||||
$parser = new Parser;
|
$parser = new Parser;
|
||||||
|
$tolerantParser = new Tolerant\Parser();
|
||||||
$docBlockFactory = DocBlockFactory::createInstance();
|
$docBlockFactory = DocBlockFactory::createInstance();
|
||||||
$index = new Index;
|
$index = new Index;
|
||||||
$definitionResolver = new DefinitionResolver($index);
|
$definitionResolver = new DefinitionResolver($index);
|
||||||
$content = file_get_contents($path);
|
$content = file_get_contents($path);
|
||||||
$document = new PhpDocument($uri, $content, $index, $parser, $docBlockFactory, $definitionResolver);
|
$document = new PhpDocument($uri, $content, $index, $parser, $tolerantParser, $docBlockFactory, $definitionResolver);
|
||||||
$stmts = $parser->parse($content);
|
$stmts = $parser->parse($content);
|
||||||
|
|
||||||
$traverser = new NodeTraverser;
|
$traverser = new NodeTraverser;
|
||||||
|
|
|
@ -13,16 +13,18 @@ use LanguageServer\Protocol\{SymbolKind, Position, ClientCapabilities};
|
||||||
use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex};
|
use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex};
|
||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use function LanguageServer\isVendored;
|
use function LanguageServer\isVendored;
|
||||||
|
use Microsoft\PhpParser as Tolerant;
|
||||||
|
|
||||||
class PhpDocumentTest extends TestCase
|
class PhpDocumentTest extends TestCase
|
||||||
{
|
{
|
||||||
public function createDocument(string $uri, string $content)
|
public function createDocument(string $uri, string $content)
|
||||||
{
|
{
|
||||||
$parser = new Parser;
|
$parser = new Parser;
|
||||||
|
$tolerantParser = new Tolerant\Parser();
|
||||||
$docBlockFactory = DocBlockFactory::createInstance();
|
$docBlockFactory = DocBlockFactory::createInstance();
|
||||||
$index = new Index;
|
$index = new Index;
|
||||||
$definitionResolver = new DefinitionResolver($index);
|
$definitionResolver = new DefinitionResolver($index);
|
||||||
return new PhpDocument($uri, $content, $index, $parser, $docBlockFactory, $definitionResolver);
|
return new PhpDocument($uri, $content, $index, $parser, $tolerantParser, $docBlockFactory, $definitionResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testParsesVariableVariables()
|
public function testParsesVariableVariables()
|
||||||
|
|
Loading…
Reference in New Issue