Skip to content

Commit a8f60c9

Browse files
jens1ofelixfbecker
authored andcommitted
fix(completion): do not propose <?php if completion context is not given (#593)
fixes #372
1 parent d9bc0b0 commit a8f60c9

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/CompletionProvider.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,12 @@ public function provideCompletion(PhpDocument $doc, Position $pos, CompletionCon
162162
|| (
163163
$node instanceof Node\Statement\InlineHtml
164164
&& (
165-
$context === null
165+
$context !== null
166166
// Make sure to not suggest on the > trigger character in HTML
167-
|| $context->triggerKind === CompletionTriggerKind::INVOKED
168-
|| $context->triggerCharacter === '<'
167+
&& (
168+
$context->triggerKind === CompletionTriggerKind::INVOKED
169+
|| $context->triggerCharacter === '<'
170+
)
169171
)
170172
)
171173
|| $pos == new Position(0, 0)

tests/Server/TextDocument/CompletionTest.php

+16-2
Original file line numberDiff line numberDiff line change
@@ -444,15 +444,29 @@ public function testHtmlWithoutPrefix()
444444
], true), $items);
445445
}
446446

447-
public function testHtmlWithPrefix()
447+
public function testHtmlWontBeProposedWithoutCompletionContext()
448448
{
449449
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/html_with_prefix.php');
450450
$this->loader->open($completionUri, file_get_contents($completionUri));
451451
$items = $this->textDocument->completion(
452452
new TextDocumentIdentifier($completionUri),
453453
new Position(0, 1)
454454
)->wait();
455-
$this->assertCompletionsListSubset(new CompletionList([
455+
456+
$this->assertEquals(new CompletionList([], true), $items);
457+
}
458+
459+
public function testHtmlWontBeProposedWithPrefixWithCompletionContext()
460+
{
461+
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/html_with_prefix.php');
462+
$this->loader->open($completionUri, file_get_contents($completionUri));
463+
$items = $this->textDocument->completion(
464+
new TextDocumentIdentifier($completionUri),
465+
new Position(0, 1),
466+
new CompletionContext(CompletionTriggerKind::TRIGGER_CHARACTER, '<')
467+
)->wait();
468+
469+
$this->assertEquals(new CompletionList([
456470
new CompletionItem(
457471
'<?php',
458472
CompletionItemKind::KEYWORD,

0 commit comments

Comments
 (0)