Chris@0: getAutoCompleter(); Chris@0: foreach ($matchers as $matcher) { Chris@0: if ($matcher instanceof ContextAware) { Chris@0: $matcher->setContext($context); Chris@0: } Chris@0: $tabCompletion->addMatcher($matcher); Chris@0: } Chris@0: Chris@0: $context->setAll(['foo' => 12, 'bar' => new \DOMDocument()]); Chris@0: Chris@0: $code = $tabCompletion->processCallback('', 0, [ Chris@0: 'line_buffer' => $line, Chris@0: 'point' => 0, Chris@4: 'end' => \strlen($line), Chris@0: ]); Chris@0: Chris@0: foreach ($mustContain as $mc) { Chris@0: $this->assertContains($mc, $code); Chris@0: } Chris@0: Chris@0: foreach ($mustNotContain as $mnc) { Chris@0: $this->assertNotContains($mnc, $code); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * TODO Chris@0: * ==== Chris@0: * draft, open to modifications Chris@0: * - [ ] if the variable is an array, return the square bracket for completion Chris@0: * - [ ] if the variable is a constructor or method, reflect to complete as a function call Chris@0: * - [ ] if the preceding token is a variable, call operators or keywords compatible for completion Chris@0: * - [X] a command always should be the second token after php_open_tag Chris@0: * - [X] keywords are never consecutive Chris@0: * - [X] namespacing completion should work just fine Chris@0: * - [X] after a new keyword, should always be a class constructor, never a function call or keyword, constant, Chris@0: * or variable that does not contain a existing class name. Chris@0: * - [X] on a namespaced constructor the completion must show the classes related, not constants. Chris@0: * Chris@0: * @return array Chris@0: */ Chris@0: public function classesInput() Chris@0: { Chris@0: return [ Chris@0: // input, must had, must not had Chris@0: ['T_OPE', ['T_OPEN_TAG'], []], Chris@0: ['st', ['stdClass'], []], Chris@0: ['stdCla', ['stdClass'], []], Chris@0: ['new s', ['stdClass'], []], Chris@0: [ Chris@0: 'new ', Chris@0: ['stdClass', 'Psy\\Context', 'Psy\\Configuration'], Chris@0: ['require', 'array_search', 'T_OPEN_TAG', '$foo'], Chris@0: ], Chris@0: ['new Psy\\C', ['Context'], ['CASE_LOWER']], Chris@0: ['\s', ['stdClass'], []], Chris@0: ['array_', ['array_search', 'array_map', 'array_merge'], []], Chris@0: ['$bar->', ['load'], []], Chris@0: ['$b', ['bar'], []], Chris@0: ['6 + $b', ['bar'], []], Chris@0: ['$f', ['foo'], []], Chris@0: ['l', ['ls'], []], Chris@0: ['ls ', [], ['ls']], Chris@0: ['sho', ['show'], []], Chris@0: ['12 + clone $', ['foo'], []], Chris@0: // array( Chris@0: // '$foo ', Chris@0: // array('+', 'clone'), Chris@0: // array('$foo', 'DOMDocument', 'array_map') Chris@0: // ), requires a operator matcher? Chris@0: ['$', ['foo', 'bar'], ['require', 'array_search', 'T_OPEN_TAG', 'Psy']], Chris@0: [ Chris@0: 'Psy\\', Chris@0: ['Context', 'TabCompletion\\Matcher\\AbstractMatcher'], Chris@0: ['require', 'array_search'], Chris@0: ], Chris@0: [ Chris@0: 'Psy\Test\TabCompletion\StaticSample::CO', Chris@0: ['StaticSample::CONSTANT_VALUE'], Chris@0: [], Chris@0: ], Chris@0: [ Chris@0: 'Psy\Test\TabCompletion\StaticSample::', Chris@0: ['StaticSample::$staticVariable'], Chris@0: [], Chris@0: ], Chris@0: [ Chris@0: 'Psy\Test\TabCompletion\StaticSample::', Chris@0: ['StaticSample::staticFunction'], Chris@0: [], Chris@0: ], Chris@0: ]; Chris@0: } Chris@0: }