-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow configurable file extension for indexing #308
base: master
Are you sure you want to change the base?
Changes from 30 commits
cdb5b56
5f096c4
7dc4477
f7175bc
9433694
39cfbda
3c33e7f
d2e5048
b9d0d1b
9067b44
1e319c7
58c82e6
44a942e
940eb97
5b1b6bf
707c97f
1e73d08
1f90b4e
ca225ff
c4568bf
5308e7a
a06057b
23a40f0
f4f1067
9cc2736
09fbec2
a5417cd
e317e8c
a1c3845
a1e5654
a81bed9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
namespace LanguageServer\Client; | ||
|
||
use LanguageServer\ClientHandler; | ||
use LanguageServer\Protocol\ConfigurationItem; | ||
use LanguageServer\Protocol\TextDocumentIdentifier; | ||
use Sabre\Event\Promise; | ||
use JsonMapper; | ||
|
@@ -44,4 +45,24 @@ public function xfiles(string $base = null): Promise | |
return $this->mapper->mapArray($textDocuments, [], TextDocumentIdentifier::class); | ||
}); | ||
} | ||
|
||
/** | ||
* The workspace/configuration request is sent from the server to the | ||
* client to fetch configuration settings from the client. | ||
* | ||
* The request can fetch n configuration settings in one roundtrip. | ||
* The order of the returned configuration settings correspond to the order | ||
* of the passed ConfigurationItems (e.g. the first item in the response is | ||
* the result for the first configuration item in the params). | ||
* | ||
* @param ConfigurationItem[] $items | ||
* @return Promise | ||
*/ | ||
public function configuration(array $items): Promise | ||
{ | ||
return $this->handler->request( | ||
'workspace/configuration', | ||
['items' => $items] | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be mapped to a class? |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,11 @@ class Indexer | |
*/ | ||
private $documentLoader; | ||
|
||
/** | ||
* @var Options | ||
*/ | ||
private $options; | ||
|
||
/** | ||
* @var \stdClasss | ||
*/ | ||
|
@@ -63,6 +68,16 @@ class Indexer | |
*/ | ||
private $composerJson; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $hasCancellationSignal; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $isIndexing; | ||
|
||
/** | ||
* @param FilesFinder $filesFinder | ||
* @param string $rootPath | ||
|
@@ -93,6 +108,22 @@ public function __construct( | |
$this->documentLoader = $documentLoader; | ||
$this->composerLock = $composerLock; | ||
$this->composerJson = $composerJson; | ||
$this->hasCancellationSignal = false; | ||
$this->isIndexing = false; | ||
$this->options = new Options(); | ||
} | ||
|
||
/** | ||
* @param Options $options | ||
*/ | ||
public function setOptions(Options $options) | ||
{ | ||
$this->options = $options; | ||
} | ||
|
||
public function getOptions(): Options | ||
{ | ||
return $this->options; | ||
} | ||
|
||
/** | ||
|
@@ -103,13 +134,14 @@ public function __construct( | |
public function index(): Promise | ||
{ | ||
return coroutine(function () { | ||
|
||
$pattern = Path::makeAbsolute('**/*.php', $this->rootPath); | ||
$fileTypes = implode(',', $this->options->fileTypes); | ||
$pattern = Path::makeAbsolute('**/*{' . $fileTypes . '}', $this->rootPath); | ||
felixfbecker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$uris = yield $this->filesFinder->find($pattern); | ||
|
||
$count = count($uris); | ||
$startTime = microtime(true); | ||
$this->client->window->logMessage(MessageType::INFO, "$count files total"); | ||
$this->isIndexing = true; | ||
|
||
/** @var string[] */ | ||
$source = []; | ||
|
@@ -135,6 +167,7 @@ public function index(): Promise | |
$this->client->window->logMessage(MessageType::INFO, 'Indexing project for definitions and static references'); | ||
yield $this->indexFiles($source); | ||
$this->sourceIndex->setStaticComplete(); | ||
|
||
// Dynamic references | ||
$this->client->window->logMessage(MessageType::INFO, 'Indexing project for dynamic references'); | ||
yield $this->indexFiles($source); | ||
|
@@ -187,6 +220,7 @@ public function index(): Promise | |
} | ||
} | ||
|
||
$this->isIndexing = false; | ||
$duration = (int)(microtime(true) - $startTime); | ||
$mem = (int)(memory_get_usage(true) / (1024 * 1024)); | ||
$this->client->window->logMessage( | ||
|
@@ -196,6 +230,35 @@ public function index(): Promise | |
}); | ||
} | ||
|
||
/** | ||
* Return current indexing state | ||
* | ||
* @return bool | ||
*/ | ||
public function isIndexing(): bool | ||
{ | ||
return $this->isIndexing; | ||
} | ||
|
||
/** | ||
* Cancel all running indexing processes | ||
* | ||
* @return Promise | ||
*/ | ||
public function cancel(): Promise | ||
{ | ||
return coroutine(function () { | ||
$this->hasCancellationSignal = true; | ||
|
||
while ($this->isIndexing()) { | ||
yield timeout(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not that happy with this "polling" solution - usually cancellation is synchronous and best-effort. I.e. the old indexing would stop eventually but you can already start with the next index run, by just making sure to instantiate new Index objects (maybe even a new Indexer) so that the old run can't accidentally still write to the new index. Does that sound feasible? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't think a new Indexer instance is a good idea, they are used in 2 different places ( And I think creating new Index objects is too much work from what I see. If yes, then the method would need to know about all objects that require the index objects. Or am I wrong here? |
||
|
||
$this->hasCancellationSignal = false; | ||
$this->client->window->logMessage(MessageType::INFO, 'Indexing project canceled'); | ||
}); | ||
} | ||
|
||
/** | ||
* @param array $files | ||
* @return Promise | ||
|
@@ -204,6 +267,11 @@ private function indexFiles(array $files): Promise | |
{ | ||
return coroutine(function () use ($files) { | ||
foreach ($files as $i => $uri) { | ||
// abort current running indexing | ||
if ($this->hasCancellationSignal) { | ||
return; | ||
} | ||
|
||
// Skip open documents | ||
if ($this->documentLoader->isOpen($uri)) { | ||
continue; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the type of the Promise?