Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge main to main-vs-deps #63237

Merged
merged 10 commits into from
Aug 5, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -5301,8 +5301,6 @@ private protected sealed override ImmutableArray<IImportScope> GetImportScopesCo
if (imports.IsEmpty)
continue;

Debug.Assert(imports.Usings.All(static u => u.UsingDirectiveReference != null));

// Try to create a node corresponding to the imports of the next higher binder scope. Then create the
// node corresponding to this set of imports and chain it to that.
builder.Add(new SimpleImportScope(
Expand Down
8 changes: 6 additions & 2 deletions src/Compilers/Core/Portable/Compilation/IImportScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,15 @@ public readonly struct ImportedNamespaceOrType
{
public INamespaceOrTypeSymbol NamespaceOrType { get; }


#pragma warning disable CA1200 // Avoid using cref tags with a prefix
/// <summary>
/// Location in source where the <c>using</c> directive or <c>Imports</c> clause was declared. Will never be
/// null for C#, may be null for Visual Basic for a project-level import directive.
/// Location in source where the <c>using</c> directive or <c>Imports</c> clause was declared. May be null for
/// Visual Basic for a project-level import directive, or for a C# global using provided directly through <see
/// cref="P:Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions.Usings"/>.
/// </summary>
public SyntaxReference? DeclaringSyntaxReference { get; }
#pragma warning restore CA1200 // Avoid using cref tags with a prefix

internal ImportedNamespaceOrType(INamespaceOrTypeSymbol namespaceOrType, SyntaxReference? declaringSyntaxReference)
{
Expand Down
24 changes: 24 additions & 0 deletions src/Scripting/CSharpTest/InteractiveSessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,30 @@ public async Task CSharp9PatternForms()
Assert.Equal(true, state.ReturnValue);
}

[Fact, WorkItem(63144, "https://github.com/dotnet/roslyn/issues/63144")]
public void InteractiveSession_ImportScopes()
{
var script = CSharpScript.Create(@"
1 + 1", ScriptOptions.Default.WithImports("System"));

var compilation = script.GetCompilation();
var tree = compilation.SyntaxTrees.Single();
var semanticModel = compilation.GetSemanticModel(tree);
var scopes = semanticModel.GetImportScopes(0);
Assert.Single(scopes);

var scope = scopes.Single();
Assert.Empty(scope.Aliases);
Assert.Empty(scope.ExternAliases);
Assert.Empty(scope.XmlNamespaces);

Assert.Single(scope.Imports);
var import = scope.Imports.Single();

Assert.True(import.NamespaceOrType is INamespaceSymbol { Name: "System", ContainingNamespace.IsGlobalNamespace: true });
Assert.Null(import.DeclaringSyntaxReference);
}

#endregion

#region References
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,50 +48,5 @@ public void RegisterUnexpectedExceptionLogger(TraceSource logger)

public void UnregisterUnexpectedExceptionLogger(TraceSource logger)
=> FaultReporter.UnregisterLogger(logger);

public void ReportApiUsage(HashSet<ISymbol> symbols, Guid solutionSessionId, Guid projectGuid)
{
const string EventName = "vs/compilers/api";
const string ApiPropertyName = "vs.compilers.api.pii";
const string ProjectIdPropertyName = "vs.solution.project.projectid";
const string SessionIdPropertyName = "vs.solution.solutionsessionid";

var groupByAssembly = symbols.GroupBy(symbol => symbol.ContainingAssembly);

var apiPerAssembly = groupByAssembly.Select(assemblyGroup => new
{
// mark all string as PII (customer data)
AssemblyName = new TelemetryPiiProperty(assemblyGroup.Key.Identity.Name),
AssemblyVersion = assemblyGroup.Key.Identity.Version.ToString(),
Namespaces = assemblyGroup.GroupBy(symbol => symbol.ContainingNamespace)
.Select(namespaceGroup =>
{
var namespaceName = namespaceGroup.Key?.ToString() ?? string.Empty;

return new
{
Namespace = new TelemetryPiiProperty(namespaceName),
Symbols = namespaceGroup.Select(symbol => symbol.GetDocumentationCommentId())
.Where(id => id != null)
.Select(id => new TelemetryPiiProperty(id))
};
})
});

// use telemetry API directly rather than Logger abstraction for PII data
var telemetryEvent = new TelemetryEvent(EventName);
telemetryEvent.Properties[ApiPropertyName] = new TelemetryComplexProperty(apiPerAssembly);
telemetryEvent.Properties[SessionIdPropertyName] = new TelemetryPiiProperty(solutionSessionId.ToString("B"));
telemetryEvent.Properties[ProjectIdPropertyName] = new TelemetryPiiProperty(projectGuid.ToString("B"));

try
{
CurrentSession?.PostEvent(telemetryEvent);
}
catch
{
// no-op
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void Method()
await TestServices.EditorVerifier.CurrentLineTextAsync(" object.Equals(null, null)$$", assertCaretPosition: true, HangMitigatingCancellationToken);
}

[IdeFact]
[IdeFact(Skip = "https://github.com/dotnet/roslyn/issues/63174")]
public async Task TabTabCompleteNewObject()
{
await SetUpEditorAsync(@"
Expand All @@ -115,7 +115,7 @@ public void Method()
await TestServices.EditorVerifier.CurrentLineTextAsync(" var value = new object()$$", assertCaretPosition: true, HangMitigatingCancellationToken);
}

[IdeFact]
[IdeFact(Skip = "https://github.com/dotnet/roslyn/issues/63174")]
public async Task TabTabBeforeSemicolon()
{
await SetUpEditorAsync(@"
Expand Down Expand Up @@ -143,7 +143,7 @@ public void Method()
await TestServices.EditorVerifier.CurrentLineTextAsync(" f.ToString()$$;", assertCaretPosition: true, HangMitigatingCancellationToken);
}

[IdeFact]
[IdeFact(Skip = "https://github.com/dotnet/roslyn/issues/63174")]
public async Task TabTabCompletionWithArguments()
{
await SetUpEditorAsync(@"
Expand Down Expand Up @@ -193,7 +193,7 @@ public void Method(IFormatProvider provider)
await TestServices.EditorVerifier.CurrentLineTextAsync(" f.ToString(\"format\"$$)", assertCaretPosition: true, HangMitigatingCancellationToken);
}

[IdeFact]
[IdeFact(Skip = "https://github.com/dotnet/roslyn/issues/63174")]
public async Task FullCycle()
{
await SetUpEditorAsync(@"
Expand Down Expand Up @@ -236,7 +236,7 @@ void Test(int x, int y) { }
await TestServices.EditorVerifier.CurrentLineTextAsync(" Test(0$$, 0)", assertCaretPosition: true, HangMitigatingCancellationToken);
}

[IdeFact]
[IdeFact(Skip = "https://github.com/dotnet/roslyn/issues/63174")]
public async Task ImplicitArgumentSwitching()
{
await SetUpEditorAsync(@"
Expand Down Expand Up @@ -273,7 +273,7 @@ void Test(int x, int y) { }
/// <summary>
/// Argument completion with no arguments.
/// </summary>
[IdeFact]
[IdeFact(Skip = "https://github.com/dotnet/roslyn/issues/63174")]
public async Task SemicolonWithTabTabCompletion1()
{
await SetUpEditorAsync(@"
Expand Down Expand Up @@ -338,7 +338,7 @@ public void Method()
/// <summary>
/// Argument completion with exactly one argument.
/// </summary>
[IdeFact]
[IdeFact(Skip = "https://github.com/dotnet/roslyn/issues/63174")]
public async Task SemicolonWithTabTabCompletion3()
{
await SetUpEditorAsync(@"
Expand Down Expand Up @@ -409,7 +409,7 @@ public void Method()
", assertCaretPosition: true, HangMitigatingCancellationToken);
}

[IdeFact]
[IdeFact(Skip = "https://github.com/dotnet/roslyn/issues/63174")]
public async Task SmartBreakLineWithTabTabCompletion2()
{
await SetUpEditorAsync(@"
Expand Down Expand Up @@ -451,7 +451,7 @@ public void Method()
", assertCaretPosition: true, HangMitigatingCancellationToken);
}

[IdeTheory]
[IdeTheory(Skip = "https://github.com/dotnet/roslyn/issues/63174")]
[InlineData("\"<\"", Skip = "https://github.com/dotnet/roslyn/issues/29669")]
[InlineData("\">\"")] // testing things that might break XML
[InlineData("\"&\"")]
Expand Down Expand Up @@ -494,7 +494,7 @@ public void M(string s, int i, int i2)
await TestServices.EditorVerifier.CurrentLineTextAsync(" M(" + parameterText + ", 0, 0)", cancellationToken: HangMitigatingCancellationToken);
}

[IdeFact]
[IdeFact(Skip = "https://github.com/dotnet/roslyn/issues/63174")]
[WorkItem(54038, "https://github.com/dotnet/roslyn/issues/54038")]
public async Task InsertPreprocessorSnippet()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,5 @@ internal interface IWorkspaceTelemetryService : IWorkspaceService
/// Removes a <see cref="TraceSource"/> used to log unexpected exceptions.
/// </summary>
void UnregisterUnexpectedExceptionLogger(TraceSource logger);

/// <summary>
/// Reports telemetry on API usage.
/// </summary>
void ReportApiUsage(HashSet<ISymbol> symbols, Guid solutionSessionId, Guid projectGuid);
}
}
Loading