Skip to content
Permalink
Browse files

Fix #1618 - conditionally enable autocompletion for methods and prope…

…rties
  • Loading branch information...
muglug committed May 9, 2019
1 parent 24dbc34 commit 33d488822898beec8e359a3086dd5f22e1480763
@@ -122,6 +122,11 @@ class ProjectAnalyzer
*/
public $onchange_line_limit;
/**
* @var bool
*/
public $provide_completion = false;
/**
* @var array<string,string>
*/
@@ -218,11 +218,11 @@ function () use ($capabilities, $rootPath, $processId) {
$serverCapabilities->hoverProvider = true;
// Support "Completion"
/**
$serverCapabilities->completionProvider = new CompletionOptions;
$serverCapabilities->completionProvider->resolveProvider = false;
$serverCapabilities->completionProvider->triggerCharacters = ['$', '>', ':'];
*/
if ($this->project_analyzer->provide_completion) {
$serverCapabilities->completionProvider = new CompletionOptions;
$serverCapabilities->completionProvider->resolveProvider = false;
$serverCapabilities->completionProvider->triggerCharacters = ['$', '>', ':'];
}
/*
$serverCapabilities->signatureHelpProvider = new SignatureHelpOptions();
@@ -169,16 +169,19 @@ public function enterNode(PhpParser\Node $node, &$traverseChildren = true)
return PhpParser\NodeTraverser::STOP_TRAVERSAL;
}
// changes "): {" to ") {"
$hacky_class_fix = preg_replace('/(\)[\s]*):([\s]*\{)/', '$1 $2', $fake_class);

This comment has been minimized.

Copy link
@nikic

nikic May 12, 2019

Is this still necessary? I think PHP-Parser should recover from that one.

This comment has been minimized.

Copy link
@muglug

muglug May 13, 2019

Author Member

It's necessary at least for the minimum version of PHP Parser that Psalm allows

This comment has been minimized.

Copy link
@muglug

muglug May 13, 2019

Author Member

But I suppose I could enforce that Psalm will only support completion for the latest version of PHP Parser

// allows autocompletion
$hacky_class_fix = str_replace(["->\n", "::\n"], "~;\n", $hacky_class_fix);
/** @var array<PhpParser\Node\Stmt> */
$replacement_stmts = $this->parser->parse(
$hacky_class_fix,
$error_handler
) ?: [];
$hacky_class_fix = preg_replace('/(->|::)(\n\s*if\s*\()/', '~;$2', $hacky_class_fix);
if ($hacky_class_fix !== $fake_class) {
/** @var array<PhpParser\Node\Stmt> */
$replacement_stmts = $this->parser->parse(
$hacky_class_fix,
$error_handler
) ?: [];
}
if (!$replacement_stmts
|| !$replacement_stmts[0] instanceof PhpParser\Node\Stmt\ClassLike
@@ -26,7 +26,8 @@
'version',
'tcp:',
'tcp-server',
'disable-on-change::'
'disable-on-change::',
'enable-autocomplete',
];
$args = array_slice($argv, 1);
@@ -53,6 +54,7 @@ function ($arg) use ($valid_long_options, $valid_short_options) {
) {
echo 'Unrecognised argument "--' . $arg_name . '"' . PHP_EOL
. 'Type --help to see a list of supported arguments'. PHP_EOL;
error_log('Bad argument');
exit(1);
}
} elseif (substr($arg, 0, 2) === '-' && $arg !== '-' && $arg !== '--') {
@@ -61,6 +63,7 @@ function ($arg) use ($valid_long_options, $valid_short_options) {
if (!in_array($arg_name, $valid_short_options) && !in_array($arg_name . ':', $valid_short_options)) {
echo 'Unrecognised argument "-' . $arg_name . '"' . PHP_EOL
. 'Type --help to see a list of supported arguments'. PHP_EOL;
error_log('Bad argument');
exit(1);
}
}
@@ -130,6 +133,9 @@ function ($arg) use ($valid_long_options, $valid_short_options) {
--disable-on-change[=line-number-threshold]
If added, the language server will not respond to onChange events.
You can also specify a line count over which Psalm will not run on-change events.
--enable-autocomplete
EXPERIMENTAL: Turns on autocompletion for methods and properties
HELP;
exit;
@@ -236,6 +242,10 @@ function ($arg) use ($valid_long_options, $valid_short_options) {
$project_analyzer->onchange_line_limit = (int) $options['disable-on-change'];
}
if (isset($options['enable-autocomplete'])) {
$project_analyzer->provide_completion = true;
}
$config->visitComposerAutoloadFiles($project_analyzer);
if ($find_dead_code) {

0 comments on commit 33d4888

Please sign in to comment.
You can’t perform that action at this time.