-
Notifications
You must be signed in to change notification settings - Fork 187
Allow configurable file extension for indexing #308
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
base: master
Are you sure you want to change the base?
Changes from 4 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 |
|---|---|---|
|
|
@@ -167,11 +167,12 @@ public function __construct(ProtocolReader $reader, ProtocolWriter $writer) | |
| * @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 | ||
|
Owner
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 didn't know vscode sends the settings as
Author
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. Microsoft has a list with all methods and params: https://github.com/Microsoft/language-server-protocol/blob/master/versions/protocol-2-x.md#initialize You only have to pass them from vscode as a property of ClientOptions According to the Docs it can have any type.
Owner
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 can't force every client to do this. This needs to happen through
Author
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. The actual options are taken from the configuration and are just passed with the initialize method. felixfbecker/vscode-php-intellisense@59e6f2c So you want to move the indexing to
Owner
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. Tricky. A client might never send
Author
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 would open a new issue to discuss this part because it affects the indexing for many option combinations. And maybe delay it until we have implemented some of them. For now it is okay, when the user has to reload to reindex with the changed options.
Owner
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 would want at least an implementation of
Owner
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. But feel free to discuss in an issue |
||
| { | ||
| 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 @@ public function initialize(ClientCapabilities $capabilities, string $rootPath = | |
| $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 @@ public function initialize(ClientCapabilities $capabilities, string $rootPath = | |
| $sourceIndex, | ||
| $this->documentLoader, | ||
| $this->composerLock, | ||
| $this->composerJson | ||
| $this->composerJson, | ||
| $options | ||
| ); | ||
| $indexer->index()->otherwise('\\LanguageServer\\crash'); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| <?php | ||
|
|
||
| namespace LanguageServer; | ||
|
|
||
| class Options | ||
| { | ||
| /** | ||
| * Filetypes the indexer should process | ||
| * | ||
| * @var array | ||
| */ | ||
| private $fileTypes = [".php"]; | ||
|
|
||
| /** | ||
| * @param \Traversable|\stdClass|array|null $options | ||
| */ | ||
| public function __construct($options = null) | ||
| { | ||
| // Do nothing when the $options parameter is not an object | ||
| if (!is_object($options) && !is_array($options) && (!$options instanceof \Traversable)) { | ||
|
Contributor
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. that won't work, you need to do it like this:
Author
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'll add tests for the Option class when I'm back
Owner
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. @jens1o actually
Contributor
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. ah, thanks. Didn't knew that. |
||
| return; | ||
| } | ||
|
|
||
| foreach ($options as $option => $value) { | ||
| $method = 'set' . ucfirst($option); | ||
|
|
||
| call_user_func([$this, $method], $value); | ||
|
Contributor
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. Check first wether the method exists?
Author
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. thx will do it later when I'm back home again
Owner
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 would rather not use setter methods at all and let
Author
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. @felixfbecker How would you validate/filter the option? Calling them extra or using
Owner
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 wouldn't. In the LS code I just don't assign invalid values and JSONMapper will throw if the
Author
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. Will it notify the client about the invalid value type? Since the options are coming from the client we should validate/filter them
Owner
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. Sure, the exception can be caught and propagated to the client. |
||
| } | ||
|
Owner
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 would rather let |
||
| } | ||
|
|
||
| /** | ||
| * Validate and set options for file types | ||
| * | ||
| * @param array $fileTypes List of file types | ||
| */ | ||
| public function setFileTypes(array $fileTypes) | ||
|
Owner
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. These functions are not needed if you let JsonMapper take care of validation |
||
| { | ||
| $fileTypes = filter_var_array($fileTypes, FILTER_SANITIZE_STRING); | ||
| $fileTypes = filter_var($fileTypes, FILTER_CALLBACK, ['options' => [$this, 'filterFileTypes']]); | ||
|
Contributor
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 think it may be possible that you'll pass false into this method. Also, you've inserted a double space
Author
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. Yeah, did a manual test before I used it, will be tested later |
||
| $fileTypes = array_filter($fileTypes); | ||
|
Contributor
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. You need to provide a callback for
Author
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. With no callback it will remove all that are false, but I can add one
Contributor
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. https://secure.php.net/manual/en/function.array-filter.php says, that the second parameter must be provided. But you could use
Author
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. Weird for me it says it is optional :/
|
||
|
|
||
| $this->fileTypes = !empty($fileTypes) ? $fileTypes : $this->fileTypes; | ||
| } | ||
|
|
||
| /** | ||
| * Get list of registered file types | ||
| * | ||
| * @return array | ||
| */ | ||
| public function getFileTypes(): array | ||
| { | ||
| return $this->fileTypes; | ||
| } | ||
|
|
||
| /** | ||
| * Filter valid file type | ||
| * | ||
| * @param string $fileType The file type to filter | ||
| * @return string|bool If valid it returns the file type, otherwise false | ||
| */ | ||
| private function filterFileTypes(string $fileType) | ||
| { | ||
| $fileType = trim($fileType); | ||
|
|
||
| if (empty($fileType)) { | ||
| return $fileType; | ||
| } | ||
|
|
||
| if (substr($fileType, 0, 1) !== '.') { | ||
| return false; | ||
| } | ||
|
|
||
| return $fileType; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.