From cdb5b566136dd65e51d5061a272cdd908207cd4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Steitz?= Date: Sat, 18 Feb 2017 01:18:16 +0100 Subject: [PATCH] Add support to index multiple file extensions Will take the options sent by the client. Option: php.intellisense.fileTypes = [".php"] --- src/Indexer.php | 30 +++++++++++++++++++----------- src/LanguageServer.php | 9 ++++++--- src/Options.php | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 14 deletions(-) create mode 100644 src/Options.php diff --git a/src/Indexer.php b/src/Indexer.php index 34ad618..3529e19 100644 --- a/src/Indexer.php +++ b/src/Indexer.php @@ -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); diff --git a/src/LanguageServer.php b/src/LanguageServer.php index 3c999f2..12ee173 100644 --- a/src/LanguageServer.php +++ b/src/LanguageServer.php @@ -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 */ - 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'); } diff --git a/src/Options.php b/src/Options.php new file mode 100644 index 0000000..3a4842e --- /dev/null +++ b/src/Options.php @@ -0,0 +1,37 @@ +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); + } +}