Add support to index multiple file extensions
Will take the options sent by the client. Option: php.intellisense.fileTypes = [".php"]pull/668/head
parent
cbfd70d398
commit
cdb5b56613
|
@ -65,14 +65,20 @@ class Indexer
|
|||
private $composerJson;
|
||||
|
||||
/**
|
||||
* @param FilesFinder $filesFinder
|
||||
* @param string $rootPath
|
||||
* @param LanguageClient $client
|
||||
* @param Cache $cache
|
||||
* @param DependenciesIndex $dependenciesIndex
|
||||
* @param Index $sourceIndex
|
||||
* @param PhpDocumentLoader $documentLoader
|
||||
* @param \stdClass|null $composerLock
|
||||
* @var Options
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* @param FilesFinder $filesFinder
|
||||
* @param string $rootPath
|
||||
* @param LanguageClient $client
|
||||
* @param Cache $cache
|
||||
* @param DependenciesIndex $dependenciesIndex
|
||||
* @param Index $sourceIndex
|
||||
* @param PhpDocumentLoader $documentLoader
|
||||
* @param \stdClass|null $composerLock
|
||||
* @param IndexerOptions|null $options
|
||||
*/
|
||||
public function __construct(
|
||||
FilesFinder $filesFinder,
|
||||
|
@ -83,7 +89,8 @@ class Indexer
|
|||
Index $sourceIndex,
|
||||
PhpDocumentLoader $documentLoader,
|
||||
\stdClass $composerLock = null,
|
||||
\stdClass $composerJson = null
|
||||
\stdClass $composerJson = null,
|
||||
Options $options = null
|
||||
) {
|
||||
$this->filesFinder = $filesFinder;
|
||||
$this->rootPath = $rootPath;
|
||||
|
@ -94,6 +101,7 @@ class Indexer
|
|||
$this->documentLoader = $documentLoader;
|
||||
$this->composerLock = $composerLock;
|
||||
$this->composerJson = $composerJson;
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -104,8 +112,8 @@ class Indexer
|
|||
public function index(): Promise
|
||||
{
|
||||
return coroutine(function () {
|
||||
|
||||
$pattern = Path::makeAbsolute('**/*.php', $this->rootPath);
|
||||
$fileTypes = implode(',', $this->options->fileTypes);
|
||||
$pattern = Path::makeAbsolute('**/*{' . $fileTypes . '}', $this->rootPath);
|
||||
$uris = yield $this->filesFinder->find($pattern);
|
||||
|
||||
$count = count($uris);
|
||||
|
|
|
@ -167,11 +167,12 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
|
|||
* @param ClientCapabilities $capabilities The capabilities provided by the client (editor)
|
||||
* @param string|null $rootPath The rootPath of the workspace. Is null if no folder is open.
|
||||
* @param int|null $processId The process Id of the parent process that started the server. Is null if the process has not been started by another process. If the parent process is not alive then the server should exit (see exit notification) its process.
|
||||
* @param mixed $initializationOptions The options send from client to initialize the server
|
||||
* @return Promise <InitializeResult>
|
||||
*/
|
||||
public function initialize(ClientCapabilities $capabilities, string $rootPath = null, int $processId = null): Promise
|
||||
public function initialize(ClientCapabilities $capabilities, string $rootPath = null, int $processId = null, $initializationOptions = null): Promise
|
||||
{
|
||||
return coroutine(function () use ($capabilities, $rootPath, $processId) {
|
||||
return coroutine(function () use ($capabilities, $rootPath, $processId, $initializationOptions) {
|
||||
|
||||
if ($capabilities->xfilesProvider) {
|
||||
$this->filesFinder = new ClientFilesFinder($this->client);
|
||||
|
@ -190,6 +191,7 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
|
|||
$this->projectIndex = new ProjectIndex($sourceIndex, $dependenciesIndex, $this->composerJson);
|
||||
$stubsIndex = StubsIndex::read();
|
||||
$this->globalIndex = new GlobalIndex($stubsIndex, $this->projectIndex);
|
||||
$options = new Options($initializationOptions);
|
||||
|
||||
// The DefinitionResolver should look in stubs, the project source and dependencies
|
||||
$this->definitionResolver = new DefinitionResolver($this->globalIndex);
|
||||
|
@ -235,7 +237,8 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
|
|||
$sourceIndex,
|
||||
$this->documentLoader,
|
||||
$this->composerLock,
|
||||
$this->composerJson
|
||||
$this->composerJson,
|
||||
$options
|
||||
);
|
||||
$indexer->index()->otherwise('\\LanguageServer\\crash');
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace LanguageServer;
|
||||
|
||||
class Options
|
||||
{
|
||||
/**
|
||||
* Filetypes the indexer should process
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $fileTypes = [".php"];
|
||||
|
||||
/**
|
||||
* @param \stdClass|null $options
|
||||
*/
|
||||
public function __construct(\stdClass $options = null)
|
||||
{
|
||||
// Do nothing when the $options parameter is not an object
|
||||
if (!is_object($options)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->fileTypes = $options->fileTypes ?? $this->normalizeFileTypes($this->fileTypes);
|
||||
}
|
||||
|
||||
private function normalizeFileTypes(array $fileTypes): array
|
||||
{
|
||||
return array_map(function (string $fileType) {
|
||||
if (substr($fileType, 0, 1) !== '.') {
|
||||
$fileType = '.' . $fileType;
|
||||
}
|
||||
|
||||
return $fileType;
|
||||
}, $fileTypes);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue