提交 beabff70 编写于 作者: K Kevin Halverson

Merge pull request #3667 from KevinH-MS/GlobalStmtDisplayNames

Refine DisplayNames for GlobalStatements...
......@@ -24,7 +24,10 @@ internal static async Task<DebugLocationInfo> GetInfoAsync(Document document, in
var syntaxFactsService = document.Project.LanguageServices.GetService<ISyntaxFactsService>();
var memberDeclaration = syntaxFactsService.GetContainingMemberDeclaration(root, position, useFullSpan: true);
if (memberDeclaration == null)
// It might be reasonable to return an empty Name and a LineOffset from the beginning of the
// file for GlobalStatements. However, the only known caller (Breakpoints Window) doesn't
// appear to consume this information, so we'll just return the simplest thing (no location).
if ((memberDeclaration == null) || (memberDeclaration.Kind() == SyntaxKind.GlobalStatement))
{
return default(DebugLocationInfo);
}
......
......@@ -2,6 +2,7 @@
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.VisualStudio.LanguageServices.CSharp.Debugging;
using Roslyn.Test.Utilities;
......@@ -12,9 +13,9 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Debugging
{
public class LocationInfoGetterTests
{
private void Test(string markup, string expectedName, int expectedLineOffset)
private void Test(string markup, string expectedName, int expectedLineOffset, CSharpParseOptions parseOptions = null)
{
using (var workspace = CSharpWorkspaceFactory.CreateWorkspaceFromLines(markup))
using (var workspace = CSharpWorkspaceFactory.CreateWorkspaceFromLines(new[] { markup }, parseOptions))
{
var testDocument = workspace.Documents.Single();
var position = testDocument.CursorPosition.Value;
......@@ -468,7 +469,7 @@ public void TopLevelField()
{
Test(
@"$$int f1;
", "f1", 0);
", "f1", 0, new CSharpParseOptions(kind: SourceCodeKind.Script));
}
[Fact, Trait(Traits.Feature, Traits.Features.DebuggingLocationName)]
......@@ -478,7 +479,17 @@ public void TopLevelMethod()
@"int M1(int x)
{
$$}
", "M1(int x)", 2);
", "M1(int x)", 2, new CSharpParseOptions(kind: SourceCodeKind.Script));
}
[Fact, Trait(Traits.Feature, Traits.Features.DebuggingLocationName)]
public void TopLevelStatement()
{
Test(
@"
$$System.Console.WriteLine(""Hello"")
", null, 0, new CSharpParseOptions(kind: SourceCodeKind.Interactive));
}
}
}
......@@ -13,11 +13,11 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.UnitTests.Debuggin
Public Class LocationInfoGetterTests
Private Sub Test(text As String, expectedName As String, expectedLineOffset As Integer, Optional rootNamespace As String = Nothing)
Private Sub Test(text As String, expectedName As String, expectedLineOffset As Integer, Optional parseOptions As VisualBasicParseOptions = Nothing, Optional rootNamespace As String = Nothing)
Dim position As Integer
MarkupTestFile.GetPosition(text, text, position)
Dim compilationOptions = If(rootNamespace IsNot Nothing, New VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary, rootNamespace:=rootNamespace), Nothing)
Using workspace = VisualBasicWorkspaceFactory.CreateWorkspaceFromLines(LanguageNames.VisualBasic, compilationOptions, Nothing, text)
Using workspace = VisualBasicWorkspaceFactory.CreateWorkspaceFromLines(LanguageNames.VisualBasic, compilationOptions, parseOptions, text)
Dim locationInfo = LocationInfoGetter.GetInfoAsync(
workspace.CurrentSolution.Projects.Single().Documents.Single(),
position,
......@@ -400,9 +400,10 @@ End Namespace
<Fact, Trait(Traits.Feature, Traits.Features.DebuggingLocationName)>
Public Sub TopLevelField()
' Unlike C#, VB will not report a name for top level fields (consistent with old implementation).
Test(<text>
$$Dim f1 As Integer
</text>.NormalizedValue, Nothing, 0) ' Unlike C#, VB will not report a name for top level fields (consistent with old implementation).
</text>.NormalizedValue, Nothing, 0, New VisualBasicParseOptions(kind:=SourceCodeKind.Script))
End Sub
<Fact, Trait(Traits.Feature, Traits.Features.DebuggingLocationName)>
......@@ -410,7 +411,15 @@ $$Dim f1 As Integer
Test(<text>
Function F1(x As Integer) As Integer
$$End Function
</text>.NormalizedValue, "F1(x As Integer) As Integer", 1)
</text>.NormalizedValue, "F1(x As Integer) As Integer", 1, New VisualBasicParseOptions(kind:=SourceCodeKind.Script))
End Sub
<Fact, Trait(Traits.Feature, Traits.Features.DebuggingLocationName)>
Public Sub TopLevelStatement()
Test(<text>
$$System.Console.WriteLine("Hello")
</text>.NormalizedValue, Nothing, 0, New VisualBasicParseOptions(kind:=SourceCodeKind.Interactive))
End Sub
End Class
......
......@@ -202,10 +202,24 @@ namespace N
VerifyNoBlock("$$", languageName:="NoCompilation")
End Sub
Private Sub VerifyNoBlock(markup As String, languageName As String)
<Fact, Trait(Traits.Feature, Traits.Features.VsLanguageBlock)>
Public Sub GetCurrentBlock_NotInGlobalCode_CS()
VerifyNoBlock("
S$$ystem.Console.WriteLine(""Hello"");
", LanguageNames.CSharp, SourceCodeKind.Script)
End Sub
<Fact, Trait(Traits.Feature, Traits.Features.VsLanguageBlock)>
Public Sub GetCurrentBlock_NotInGlobalCode_VB()
VerifyNoBlock("
S$$ystem.Console.WriteLine(""Hello"")
", LanguageNames.VisualBasic, SourceCodeKind.Script)
End Sub
Private Sub VerifyNoBlock(markup As String, languageName As String, Optional sourceCodeKind As SourceCodeKind = SourceCodeKind.Regular)
Dim xml = <Workspace>
<Project Language=<%= languageName %> CommonReferences="True">
<Document>
<Document Kind=<%= sourceCodeKind %>>
<%= markup %>
</Document>
</Project>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册