提交 34a7e3f4 编写于 作者: R Ravi Chande 提交者: GitHub

Merge pull request #14251 from rchande/myFormsCompletion

My forms completion
......@@ -79,8 +79,8 @@ internal static CompletionHelper GetCompletionHelper(Document document)
return service.GetCompletionsAsync(document, position, triggerInfo, options: options);
}
private async Task CheckResultsAsync(
Document document, int position, string expectedItemOrNull, string expectedDescriptionOrNull, bool usePreviousCharAsTrigger, bool checkForAbsence, Glyph? glyph, int? matchPriority)
protected async Task CheckResultsAsync(
Document document, int position, string expectedItemOrNull, string expectedDescriptionOrNull, bool usePreviousCharAsTrigger, bool checkForAbsence, int? glyph, int? matchPriority)
{
var code = (await document.GetTextAsync()).ToString();
......@@ -124,7 +124,7 @@ internal static CompletionHelper GetCompletionHelper(Document document)
{
AssertEx.Any(items, c => CompareItems(c.DisplayText, expectedItemOrNull)
&& (expectedDescriptionOrNull != null ? completionService.GetDescriptionAsync(document, c).Result.Text == expectedDescriptionOrNull : true)
&& (glyph.HasValue ? c.Tags.SequenceEqual(GlyphTags.GetTags(glyph.Value)) : true)
&& (glyph.HasValue ? c.Tags.SequenceEqual(GlyphTags.GetTags((Glyph)glyph.Value)) : true)
&& (matchPriority.HasValue ? (int)c.Rules.MatchPriority == matchPriority.Value : true ));
}
}
......@@ -269,12 +269,12 @@ protected async Task VerifyNoItemsExistAsync(string markup, SourceCodeKind? sour
}
var document1 = await WorkspaceFixture.UpdateDocumentAsync(code, sourceCodeKind);
await CheckResultsAsync(document1, position, expectedItemOrNull, expectedDescriptionOrNull, usePreviousCharAsTrigger, checkForAbsence, expectedGlyph, matchPriority);
await CheckResultsAsync(document1, position, expectedItemOrNull, expectedDescriptionOrNull, usePreviousCharAsTrigger, checkForAbsence, glyph, matchPriority);
if (await CanUseSpeculativeSemanticModelAsync(document1, position))
{
var document2 = await WorkspaceFixture.UpdateDocumentAsync(code, sourceCodeKind, cleanBeforeUpdate: false);
await CheckResultsAsync(document2, position, expectedItemOrNull, expectedDescriptionOrNull, usePreviousCharAsTrigger, checkForAbsence, expectedGlyph, matchPriority);
await CheckResultsAsync(document2, position, expectedItemOrNull, expectedDescriptionOrNull, usePreviousCharAsTrigger, checkForAbsence, glyph, matchPriority);
}
}
......
......@@ -291,8 +291,8 @@ public static Task<TestWorkspace> CreateAsync(string xmlDefinition, bool complet
var contentTypeRegistryService = exportProvider.GetExportedValue<IContentTypeRegistryService>();
var languageServices = workspace.Services.GetLanguageServices(language);
var compilationOptions = CreateCompilationOptions(workspace, projectElement, language);
var parseOptions = GetParseOptions(projectElement, language, languageServices);
var compilationOptions = CreateCompilationOptions(workspace, projectElement, language, parseOptions);
var references = CreateReferenceList(workspace, projectElement);
var analyzers = CreateAnalyzerList(workspace, projectElement);
......@@ -454,15 +454,16 @@ private static string GetLanguage(TestWorkspace workspace, XElement projectEleme
private static CompilationOptions CreateCompilationOptions(
TestWorkspace workspace,
XElement projectElement,
string language)
string language,
ParseOptions parseOptions)
{
var compilationOptionsElement = projectElement.Element(CompilationOptionsElementName);
return language == LanguageNames.CSharp || language == LanguageNames.VisualBasic
? CreateCompilationOptions(workspace, language, compilationOptionsElement)
? CreateCompilationOptions(workspace, language, compilationOptionsElement, parseOptions)
: null;
}
private static CompilationOptions CreateCompilationOptions(TestWorkspace workspace, string language, XElement compilationOptionsElement)
private static CompilationOptions CreateCompilationOptions(TestWorkspace workspace, string language, XElement compilationOptionsElement, ParseOptions parseOptions)
{
var rootNamespace = new VisualBasicCompilationOptions(OutputKind.ConsoleApplication).RootNamespace;
var globalImports = new List<GlobalImport>();
......@@ -493,9 +494,11 @@ private static CompilationOptions CreateCompilationOptions(TestWorkspace workspa
rootNamespace = new VisualBasicCompilationOptions(OutputKind.WindowsRuntimeMetadata).RootNamespace;
}
// VB needs Compilation.ParseOptions set (we do the same at the VS layer)
return language == LanguageNames.CSharp
? (CompilationOptions)new CSharpCompilationOptions(OutputKind.WindowsRuntimeMetadata)
: new VisualBasicCompilationOptions(OutputKind.WindowsRuntimeMetadata).WithGlobalImports(globalImports).WithRootNamespace(rootNamespace);
: new VisualBasicCompilationOptions(OutputKind.WindowsRuntimeMetadata).WithGlobalImports(globalImports).WithRootNamespace(rootNamespace)
.WithParseOptions((VisualBasicParseOptions)parseOptions ?? VisualBasicParseOptions.Default);
}
}
else
......@@ -519,8 +522,11 @@ private static CompilationOptions CreateCompilationOptions(TestWorkspace workspa
if (language == LanguageNames.VisualBasic)
{
// VB needs Compilation.ParseOptions set (we do the same at the VS layer)
compilationOptions = ((VisualBasicCompilationOptions)compilationOptions).WithRootNamespace(rootNamespace)
.WithGlobalImports(globalImports);
.WithGlobalImports(globalImports)
.WithParseOptions((VisualBasicParseOptions)parseOptions ??
VisualBasicParseOptions.Default);
}
return compilationOptions;
......
......@@ -402,7 +402,7 @@ End Class</a>
End Using
End Function
Private Async Function CheckResultsAsync(document As Document, position As Integer, isBuilder As Boolean, triggerInfo As CompletionTrigger?, options As OptionSet) As Task
Private Overloads Async Function CheckResultsAsync(document As Document, position As Integer, isBuilder As Boolean, triggerInfo As CompletionTrigger?, options As OptionSet) As Task
triggerInfo = If(triggerInfo, CompletionTrigger.CreateInsertionTrigger("a"c))
Dim service = GetCompletionService(document.Project.Solution.Workspace)
......
......@@ -7583,5 +7583,71 @@ End Namespace
Await VerifyItemIsAbsentAsync(text, "Rest")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.Completion)>
Public Async Function WinformsInstanceMembers() As Task
' Setting the the preprocessor symbol _MyType=WindowsForms will cause the
' compiler to automatically generate the My Template. See
' GroupClassTests.vb for the compiler layer equivalent of these tests.
Dim input =
<Workspace>
<Project Language="Visual Basic" CommonReferences="true" PreprocessorSymbols="_MyType=WindowsForms">
<Document name="Form.vb">
<![CDATA[
Namespace Global.System.Windows.Forms
Public Class Form
Implements IDisposable
Public Sub InstanceMethod()
End Sub
Public Shared Sub SharedMethod()
End Sub
Public Sub Dispose() Implements IDisposable.Dispose
End Sub
Public ReadOnly Property IsDisposed As Boolean
Get
Return False
End Get
End Property
End Class
End Namespace
]]></Document>
<Document name="types.vb"><![CDATA[
Imports System
Namespace Global.WindowsApplication1
Public Class Form2
Inherits System.Windows.Forms.Form
End Class
End Namespace
Namespace Global.WindowsApplication1
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub Foo()
Form2.$$
End Sub
End Class
End Namespace
]]></Document>
</Project>
</Workspace>
Using workspace = Await TestWorkspace.CreateAsync(input)
Dim document = workspace.CurrentSolution.GetDocument(workspace.DocumentWithCursor.Id)
Dim position = workspace.DocumentWithCursor.CursorPosition.Value
Await CheckResultsAsync(document, position, "InstanceMethod", expectedDescriptionOrNull:=Nothing, usePreviousCharAsTrigger:=False, checkForAbsence:=False,
glyph:=Nothing, matchPriority:=Nothing)
Await CheckResultsAsync(document, position, "SharedMethod", expectedDescriptionOrNull:=Nothing, usePreviousCharAsTrigger:=False, checkForAbsence:=False,
glyph:=Nothing, matchPriority:=Nothing)
End Using
End Function
End Class
End Namespace
......@@ -247,6 +247,16 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Recommendations
Dim leftHandTypeInfo = context.SemanticModel.GetTypeInfo(leftExpression, cancellationToken)
Dim leftHandSymbolInfo = context.SemanticModel.GetSymbolInfo(leftExpression, cancellationToken)
' https://github.com/dotnet/roslyn/issues/9087: Try to speculatively bind a type as an expression for My namespace
' We'll get a type contained in the My Namespace if this is successful
If leftHandTypeInfo.Type IsNot Nothing AndAlso leftHandTypeInfo.Type.Equals(leftHandSymbolInfo.Symbol) Then
Dim leftHandSpeculativeBinding = context.SemanticModel.GetSpeculativeSymbolInfo(context.Position, leftExpression, SpeculativeBindingOption.BindAsExpression)
If leftHandSpeculativeBinding.Symbol IsNot Nothing AndAlso
leftHandSpeculativeBinding.Symbol.ContainingNamespace?.IsMyNamespace(context.SemanticModel.Compilation) Then
leftHandSymbolInfo = leftHandSpeculativeBinding
End If
End If
Dim excludeInstance = False
Dim excludeShared = True ' do not show shared members by default
Dim useBaseReferenceAccessibility = False
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册