Skip to content

Commit

Permalink
fix(completion): do not propose <?php if completion context is not gi…
Browse files Browse the repository at this point in the history
…ven (#593)

fixes #372
  • Loading branch information
jens1o authored and felixfbecker committed Feb 7, 2018
1 parent d9bc0b0 commit a8f60c9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/CompletionProvider.php
Expand Up @@ -162,10 +162,12 @@ public function provideCompletion(PhpDocument $doc, Position $pos, CompletionCon
|| (
$node instanceof Node\Statement\InlineHtml
&& (
$context === null
$context !== null
// Make sure to not suggest on the > trigger character in HTML
|| $context->triggerKind === CompletionTriggerKind::INVOKED
|| $context->triggerCharacter === '<'
&& (
$context->triggerKind === CompletionTriggerKind::INVOKED
|| $context->triggerCharacter === '<'
)
)
)
|| $pos == new Position(0, 0)
Expand Down
18 changes: 16 additions & 2 deletions tests/Server/TextDocument/CompletionTest.php
Expand Up @@ -444,15 +444,29 @@ public function testHtmlWithoutPrefix()
], true), $items);
}

public function testHtmlWithPrefix()
public function testHtmlWontBeProposedWithoutCompletionContext()
{
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/html_with_prefix.php');
$this->loader->open($completionUri, file_get_contents($completionUri));
$items = $this->textDocument->completion(
new TextDocumentIdentifier($completionUri),
new Position(0, 1)
)->wait();
$this->assertCompletionsListSubset(new CompletionList([

$this->assertEquals(new CompletionList([], true), $items);
}

public function testHtmlWontBeProposedWithPrefixWithCompletionContext()
{
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/html_with_prefix.php');
$this->loader->open($completionUri, file_get_contents($completionUri));
$items = $this->textDocument->completion(
new TextDocumentIdentifier($completionUri),
new Position(0, 1),
new CompletionContext(CompletionTriggerKind::TRIGGER_CHARACTER, '<')
)->wait();

$this->assertEquals(new CompletionList([
new CompletionItem(
'<?php',
CompletionItemKind::KEYWORD,
Expand Down

0 comments on commit a8f60c9

Please sign in to comment.