Let JsonMapper intialize the options
To sanitize the file type option, we provide a setter method for the property that will be called by the JsonMapper.pull/668/head
parent
f7175bc195
commit
94336941bd
|
@ -112,7 +112,7 @@ class Indexer
|
|||
public function index(): Promise
|
||||
{
|
||||
return coroutine(function () {
|
||||
$fileTypes = implode(',', $this->options->getFileTypes());
|
||||
$fileTypes = implode(',', $this->options->fileTypes);
|
||||
$pattern = Path::makeAbsolute('**/*{' . $fileTypes . '}', $this->rootPath);
|
||||
$uris = yield $this->filesFinder->find($pattern);
|
||||
|
||||
|
|
|
@ -167,10 +167,10 @@ 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
|
||||
* @param Options $initializationOptions The options send from client to initialize the server
|
||||
* @return Promise <InitializeResult>
|
||||
*/
|
||||
public function initialize(ClientCapabilities $capabilities, string $rootPath = null, int $processId = null, $initializationOptions = null): Promise
|
||||
public function initialize(ClientCapabilities $capabilities, string $rootPath = null, int $processId = null, Options $initializationOptions = null): Promise
|
||||
{
|
||||
return coroutine(function () use ($capabilities, $rootPath, $processId, $initializationOptions) {
|
||||
|
||||
|
@ -191,7 +191,6 @@ 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);
|
||||
|
@ -238,7 +237,7 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
|
|||
$this->documentLoader,
|
||||
$this->composerLock,
|
||||
$this->composerJson,
|
||||
$options
|
||||
$initializationOptions
|
||||
);
|
||||
$indexer->index()->otherwise('\\LanguageServer\\crash');
|
||||
}
|
||||
|
|
|
@ -7,51 +7,25 @@ class Options
|
|||
/**
|
||||
* Filetypes the indexer should process
|
||||
*
|
||||
* @var array
|
||||
* @var string[]
|
||||
*/
|
||||
private $fileTypes = [".php"];
|
||||
public $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)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($options as $option => $value) {
|
||||
$method = 'set' . ucfirst($option);
|
||||
|
||||
call_user_func([$this, $method], $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate and set options for file types
|
||||
* Validate/Filter input and set options for file types
|
||||
*
|
||||
* @param array $fileTypes List of file types
|
||||
*/
|
||||
public function setFileTypes(array $fileTypes)
|
||||
{
|
||||
$fileTypes = filter_var_array($fileTypes, FILTER_SANITIZE_STRING);
|
||||
$fileTypes = filter_var($fileTypes, FILTER_CALLBACK, ['options' => [$this, 'filterFileTypes']]);
|
||||
$fileTypes = array_filter($fileTypes);
|
||||
$fileTypes = filter_var($fileTypes, FILTER_CALLBACK, ['options' => [$this, 'filterFileTypes']]); // validate file type format
|
||||
$fileTypes = array_filter($fileTypes, 'strlen'); // filter empty items
|
||||
$fileTypes = array_values($fileTypes); //rebase indexes
|
||||
|
||||
$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
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue