Skip to content
This repository was archived by the owner on Jul 18, 2018. It is now read-only.

Support Dynamic loading and Autoloading in Php server. #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ComposerScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function parseStubs()
}

$uris = yield $finder->find("$stubsLocation/**/*.php");

$uris = [];
foreach ($uris as $uri) {
echo "Parsing $uri\n";
$content = yield $contentRetriever->retrieve($uri);
Expand Down
6 changes: 6 additions & 0 deletions src/DefinitionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ class DefinitionResolver
*/
private $docBlockFactory;

// autoload supports.
public $autoloadLibraries;
public $autoloadClasses;
public $autoloadModels;
public $autoloadLanguages;

/**
* @param ReadableIndex $index
*/
Expand Down
12 changes: 12 additions & 0 deletions src/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ public function index(): Promise
/** @var string[][] */
$deps = [];

$ending = "application/config/autoload.php";
$endingLength = strlen($ending);
foreach ($uris as $uri) {
$found = (substr($uri, -$endingLength) === $ending);

// if found, put it to the beginning of the list so that it gets analyzed first.
if ($found) {
array_unshift($uris, $uri);
break;
}
}

foreach ($uris as $uri) {
$packageName = getPackageName($uri, $this->composerJson);
if ($this->composerLock !== null && $packageName) {
Expand Down
2 changes: 1 addition & 1 deletion src/LanguageServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function initialize(ClientCapabilities $capabilities, string $rootPath =
$this->composerLock,
$this->composerJson
);
$indexer->index()->otherwise('\\LanguageServer\\crash');
yield $indexer->index()->otherwise('\\LanguageServer\\crash');
}


Expand Down
4 changes: 2 additions & 2 deletions src/PhpDocumentLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class PhpDocumentLoader
*
* @var PhpDocument
*/
private $documents = [];
public $documents = [];

/**
* @var ContentRetriever
Expand Down Expand Up @@ -110,7 +110,7 @@ public function load(string $uri): Promise
$content = yield $this->contentRetriever->retrieve($uri);
$size = strlen($content);
if ($size > $limit) {
throw new ContentTooLargeException($uri, $size, $limit);
return $this->create($uri, "");
}

if (isset($this->documents[$uri])) {
Expand Down
10 changes: 9 additions & 1 deletion src/Server/TextDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,15 @@ public function references(
public function definition(TextDocumentIdentifier $textDocument, Position $position): Promise
{
return coroutine(function () use ($textDocument, $position) {
$document = yield $this->documentLoader->getOrLoad($textDocument->uri);
$documentLoader = $this->documentLoader;//->getOrLoad($textDocument->uri);
$document = null;
if (isset($documentLoader->documents[$textDocument->uri])) {
$document = $documentLoader->documents[$textDocument->uri];
} else {
$document = yield $documentLoader->load($textDocument->uri);
$documentLoader->documents[$textDocument->uri] = $document;
}

$node = $document->getNodeAtPosition($position);
if ($node === null) {
return [];
Expand Down
Loading