提交 774fbec3 编写于 作者: P Pilchie

Make C# snippet completion obey the "SendEnterThroughToEditor" option

Use the standard logic to determine whether to send enter through to the
editor, which requires using CSharpCompletionItems.

Fixes internal bug #1140893.
上级 0eaa1dd9
......@@ -116,6 +116,17 @@ class C
VerifyItemInLinkedFiles(markup, MockSnippetInfoService.SnippetShortcut, null);
}
[WorkItem(1140893)]
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public void CommitWithEnterObeysOption()
{
VerifySendEnterThroughToEnter("try", "tr", sendThroughEnterEnabled: true, expected: false);
VerifySendEnterThroughToEnter("try", "try", sendThroughEnterEnabled: true, expected: true);
VerifySendEnterThroughToEnter("try", "tr", sendThroughEnterEnabled: false, expected: false);
VerifySendEnterThroughToEnter("try", "try", sendThroughEnterEnabled: false, expected: false);
}
private class MockSnippetInfoService : ISnippetInfoService
{
internal const string SnippetShortcut = "SnippetShortcut";
......
......@@ -47,7 +47,7 @@ public override bool IsCommitCharacter(CompletionItem completionItem, char ch, s
public override bool SendEnterThroughToEditor(CompletionItem completionItem, string textTypedSoFar)
{
return false;
return CompletionUtilities.SendEnterThroughToEditor(completionItem, textTypedSoFar);
}
protected override async Task<IEnumerable<CompletionItem>> GetItemsWorkerAsync(Document document, int position, CompletionTriggerInfo triggerInfo, CancellationToken cancellationToken)
......@@ -138,11 +138,12 @@ private async Task<IEnumerable<CompletionItem>> GetSnippetCompletionItemsAsync(W
}
var text = await semanticModel.SyntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false);
return snippets.Select(snippet => new CompletionItem(
return snippets.Select(snippet => new CSharpCompletionItem(
workspace,
this,
displayText: isPreProcessorContext ? snippet.Shortcut.Substring(1) : snippet.Shortcut,
sortText: isPreProcessorContext ? snippet.Shortcut.Substring(1) : snippet.Shortcut,
description: (snippet.Title + Environment.NewLine + snippet.Description).ToSymbolDisplayParts(),
descriptionFactory: c => Task.FromResult((snippet.Title + Environment.NewLine + snippet.Description).ToSymbolDisplayParts()),
filterSpan: CompletionUtilities.GetTextChangeSpan(text, position),
glyph: Glyph.Snippet,
shouldFormatOnCommit: service.ShouldFormatSnippet(snippet)));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册