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