提交 9a6f1a5d 编写于 作者: C Cheryl Borley 提交者: GitHub

Merge pull request #22211 from chborl/vbcodesnippetsbug

Don't show snippets in VB comments
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.ComponentModel.Composition.Hosting
Imports System.Composition
Imports System.Threading
Imports System.Threading.Tasks
Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.Completion
......@@ -20,10 +18,10 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Snippets
Using testState
testState.SendTabToCompletion()
Assert.Equal(testState.GetDocumentText(), "a")
Assert.Equal("a", testState.GetDocumentText())
Await testState.WaitForAsynchronousOperationsAsync()
Assert.Equal(testState.CurrentCompletionPresenterSession.SelectedItem.DisplayText, "Shortcut")
Assert.Equal("Shortcut", testState.CurrentCompletionPresenterSession.SelectedItem.DisplayText)
Dim document = testState.Workspace.CurrentSolution.Projects.First().Documents.First()
Dim service = CompletionService.GetService(document)
......@@ -43,17 +41,17 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Snippets
Using testState
testState.SendTabToCompletion()
Await testState.WaitForAsynchronousOperationsAsync()
Assert.Equal(testState.CurrentCompletionPresenterSession.SelectedItem.DisplayText, "Shortcut")
Assert.Equal("Shortcut", testState.CurrentCompletionPresenterSession.SelectedItem.DisplayText)
testState.SendBackspace()
Await testState.WaitForAsynchronousOperationsAsync()
Assert.Equal(testState.CurrentCompletionPresenterSession.SelectedItem.DisplayText, "Shortcut")
Assert.Equal("Shortcut", testState.CurrentCompletionPresenterSession.SelectedItem.DisplayText)
testState.SendTabToCompletion()
Await testState.WaitForAsynchronousOperationsAsync()
Assert.True(testState.SnippetExpansionClient.TryInsertExpansionCalled)
Assert.Equal(testState.GetDocumentText(), "Shortcut")
Assert.Equal("Shortcut", testState.GetDocumentText())
End Using
End Function
......@@ -71,6 +69,59 @@ End Class</File>.Value
Assert.Null(testState.CurrentCompletionPresenterSession)
End Using
End Function
<WorkItem(21801, "https://github.com/dotnet/roslyn/issues/21801")>
<WpfFact, Trait(Traits.Feature, Traits.Features.Snippets)>
Public Async Function SnippetNotOfferedInComments() As Task
Dim markup = <File>
Class C
$$
End Class</File>.Value
Dim testState = SnippetTestState.CreateTestState(markup, LanguageNames.VisualBasic, extraParts:={GetType(MockSnippetInfoService)})
Using testState
testState.Workspace.Options = testState.Workspace.Options.WithChangedOption(
New Options.OptionKey(CompletionOptions.SnippetsBehavior, LanguageNames.VisualBasic), SnippetsRule.AlwaysInclude)
testState.SendTypeChars("'T")
Await testState.WaitForAsynchronousOperationsAsync()
Assert.Null(testState.CurrentCompletionPresenterSession)
End Using
End Function
<WorkItem(21801, "https://github.com/dotnet/roslyn/issues/21801")>
<WpfFact, Trait(Traits.Feature, Traits.Features.Snippets)>
Public Async Function SnippetsNotOfferedInDocComments() As Task
Dim markup = <File>
Class C
$$
End Class</File>.Value
Dim testState = SnippetTestState.CreateTestState(markup, LanguageNames.VisualBasic, extraParts:={GetType(MockSnippetInfoService)})
Using testState
testState.Workspace.Options = testState.Workspace.Options.WithChangedOption(
New Options.OptionKey(CompletionOptions.SnippetsBehavior, LanguageNames.VisualBasic), SnippetsRule.AlwaysInclude)
testState.SendTypeChars("'''T")
Await testState.WaitForAsynchronousOperationsAsync()
Assert.Null(testState.CurrentCompletionPresenterSession)
End Using
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.Snippets)>
Public Async Function SnippetsAlwaysOfferedOutsideComment() As Task
Dim markup = <File>
Class C
$$
End Class</File>.Value
Dim testState = SnippetTestState.CreateTestState(markup, LanguageNames.VisualBasic, extraParts:={GetType(MockSnippetInfoService)})
Using testState
testState.Workspace.Options = testState.Workspace.Options.WithChangedOption(
New Options.OptionKey(CompletionOptions.SnippetsBehavior, LanguageNames.VisualBasic), SnippetsRule.AlwaysInclude)
testState.SendTypeChars("Shortcut")
Await testState.WaitForAsynchronousOperationsAsync()
Assert.Equal("Shortcut", testState.CurrentCompletionPresenterSession.SelectedItem.DisplayText)
End Using
End Function
End Class
<ExportLanguageService(GetType(ISnippetInfoService), LanguageNames.VisualBasic), [Shared]>
......
......@@ -135,6 +135,11 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Snippets
SendEscape(AddressOf SnippetCommandHandler.ExecuteCommand, Function() EditorOperations.InsertText("EscapePassedThrough!"))
End Sub
Public Overloads Sub SendTypeChars(typeChars As String)
Dim handler = DirectCast(_completionCommandHandler, ICommandHandler(Of TypeCharCommandArgs))
MyBase.SendTypeChars(typeChars, AddressOf handler.ExecuteCommand)
End Sub
Private Class MockOrderableContentTypeMetadata
Inherits OrderableContentTypeMetadata
......
......@@ -12,6 +12,7 @@ Imports Microsoft.CodeAnalysis.Shared.Extensions
Imports Microsoft.CodeAnalysis.Snippets
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.Text.Shared.Extensions
Imports Microsoft.CodeAnalysis.VisualBasic.Extensions
Imports Microsoft.VisualStudio.Editor
Imports Microsoft.VisualStudio.Text
Imports Microsoft.VisualStudio.Text.Editor
......@@ -52,6 +53,10 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Snippets
Dim syntaxFacts = document.GetLanguageService(Of ISyntaxFactsService)()
Dim isPossibleTupleContext = syntaxFacts.IsPossibleTupleContext(syntaxTree, position, cancellationToken)
If (IsInNonUserCode(syntaxTree, position, cancellationToken)) Then
Return
End If
context.IsExclusive = ShouldBeExclusive(context.Options)
context.AddItems(CreateCompletionItems(snippets, isPossibleTupleContext))
End Function
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册