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