1
0
Fork 0

Add support to index multiple file extensions

Will take the options sent by the client.
Option: php.intellisense.fileTypes = [".php"]
pull/668/head
Jürgen Steitz 2017-02-18 01:18:16 +01:00
parent cbfd70d398
commit cdb5b56613
3 changed files with 62 additions and 14 deletions

View File

@ -64,6 +64,11 @@ class Indexer
*/ */
private $composerJson; private $composerJson;
/**
* @var Options
*/
private $options;
/** /**
* @param FilesFinder $filesFinder * @param FilesFinder $filesFinder
* @param string $rootPath * @param string $rootPath
@ -73,6 +78,7 @@ class Indexer
* @param Index $sourceIndex * @param Index $sourceIndex
* @param PhpDocumentLoader $documentLoader * @param PhpDocumentLoader $documentLoader
* @param \stdClass|null $composerLock * @param \stdClass|null $composerLock
* @param IndexerOptions|null $options
*/ */
public function __construct( public function __construct(
FilesFinder $filesFinder, FilesFinder $filesFinder,
@ -83,7 +89,8 @@ class Indexer
Index $sourceIndex, Index $sourceIndex,
PhpDocumentLoader $documentLoader, PhpDocumentLoader $documentLoader,
\stdClass $composerLock = null, \stdClass $composerLock = null,
\stdClass $composerJson = null \stdClass $composerJson = null,
Options $options = null
) { ) {
$this->filesFinder = $filesFinder; $this->filesFinder = $filesFinder;
$this->rootPath = $rootPath; $this->rootPath = $rootPath;
@ -94,6 +101,7 @@ class Indexer
$this->documentLoader = $documentLoader; $this->documentLoader = $documentLoader;
$this->composerLock = $composerLock; $this->composerLock = $composerLock;
$this->composerJson = $composerJson; $this->composerJson = $composerJson;
$this->options = $options;
} }
/** /**
@ -104,8 +112,8 @@ class Indexer
public function index(): Promise public function index(): Promise
{ {
return coroutine(function () { return coroutine(function () {
$fileTypes = implode(',', $this->options->fileTypes);
$pattern = Path::makeAbsolute('**/*.php', $this->rootPath); $pattern = Path::makeAbsolute('**/*{' . $fileTypes . '}', $this->rootPath);
$uris = yield $this->filesFinder->find($pattern); $uris = yield $this->filesFinder->find($pattern);
$count = count($uris); $count = count($uris);

View File

@ -167,11 +167,12 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
* @param ClientCapabilities $capabilities The capabilities provided by the client (editor) * @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 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 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> * @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) { if ($capabilities->xfilesProvider) {
$this->filesFinder = new ClientFilesFinder($this->client); $this->filesFinder = new ClientFilesFinder($this->client);
@ -190,6 +191,7 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
$this->projectIndex = new ProjectIndex($sourceIndex, $dependenciesIndex, $this->composerJson); $this->projectIndex = new ProjectIndex($sourceIndex, $dependenciesIndex, $this->composerJson);
$stubsIndex = StubsIndex::read(); $stubsIndex = StubsIndex::read();
$this->globalIndex = new GlobalIndex($stubsIndex, $this->projectIndex); $this->globalIndex = new GlobalIndex($stubsIndex, $this->projectIndex);
$options = new Options($initializationOptions);
// The DefinitionResolver should look in stubs, the project source and dependencies // The DefinitionResolver should look in stubs, the project source and dependencies
$this->definitionResolver = new DefinitionResolver($this->globalIndex); $this->definitionResolver = new DefinitionResolver($this->globalIndex);
@ -235,7 +237,8 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
$sourceIndex, $sourceIndex,
$this->documentLoader, $this->documentLoader,
$this->composerLock, $this->composerLock,
$this->composerJson $this->composerJson,
$options
); );
$indexer->index()->otherwise('\\LanguageServer\\crash'); $indexer->index()->otherwise('\\LanguageServer\\crash');
} }

37
src/Options.php Normal file
View File

@ -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);
}
}