Skip to content

Commit e64e81c

Browse files
[automated] Merge branch 'main' => 'main-vs-deps' (#77658)
I detected changes in the main branch which have not been merged yet to main-vs-deps. I'm a robot and am configured to help you automatically keep main-vs-deps up to date, so I've opened this PR. This PR merges commits made on main by the following committers: * jjonescz * akhera99 * dotnet-maestro[bot] ## Instructions for merging from UI This PR will not be auto-merged. When pull request checks pass, complete this PR by creating a merge commit, *not* a squash or rebase commit. <img alt="merge button instructions" src="https://i.imgur.com/GepcNJV.png" width="300" /> If this repo does not allow creating merge commits from the GitHub UI, use command line instructions. ## Instructions for merging via command line Run these commands to merge this pull request from the command line. ``` sh git fetch git checkout main git pull --ff-only git checkout main-vs-deps git pull --ff-only git merge --no-ff main # If there are merge conflicts, resolve them and then run git merge --continue to complete the merge # Pushing the changes to the PR branch will re-trigger PR validation. git push https://github.com/dotnet/roslyn HEAD:merge/main-to-main-vs-deps ``` <details> <summary>or if you are using SSH</summary> ``` git push [email protected]:dotnet/roslyn HEAD:merge/main-to-main-vs-deps ``` </details> After PR checks are complete push the branch ``` git push ``` ## Instructions for resolving conflicts :warning: If there are merge conflicts, you will need to resolve them manually before merging. You can do this [using GitHub][resolve-github] or using the [command line][resolve-cli]. [resolve-github]: https://help.github.com/articles/resolving-a-merge-conflict-on-github/ [resolve-cli]: https://help.github.com/articles/resolving-a-merge-conflict-using-the-command-line/ ## Instructions for updating this pull request Contributors to this repo have permission update this pull request by pushing to the branch 'merge/main-to-main-vs-deps'. This can be done to resolve conflicts or make other changes to this pull request before it is merged. The provided examples assume that the remote is named 'origin'. If you have a different remote name, please replace 'origin' with the name of your remote. ``` git fetch git checkout -b merge/main-to-main-vs-deps origin/main-vs-deps git pull https://github.com/dotnet/roslyn merge/main-to-main-vs-deps (make changes) git commit -m "Updated PR with my changes" git push https://github.com/dotnet/roslyn HEAD:merge/main-to-main-vs-deps ``` <details> <summary>or if you are using SSH</summary> ``` git fetch git checkout -b merge/main-to-main-vs-deps origin/main-vs-deps git pull [email protected]:dotnet/roslyn merge/main-to-main-vs-deps (make changes) git commit -m "Updated PR with my changes" git push [email protected]:dotnet/roslyn HEAD:merge/main-to-main-vs-deps ``` </details> Contact .NET Core Engineering (dotnet/dnceng) if you have questions or issues. Also, if this PR was generated incorrectly, help us fix it. See https://github.com/dotnet/arcade/blob/main/.github/workflows/scripts/inter-branch-merge.ps1.
2 parents dfa1641 + a969b14 commit e64e81c

21 files changed

+366
-51
lines changed

.github/workflows/main-merge.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ on:
55
schedule:
66
# Create a merge every 3 hours (works only for merges from `main`, others would need a `push` trigger).
77
- cron: '0 */3 * * *'
8+
push:
9+
branches:
10+
- main-vs-deps
811
workflow_dispatch:
912
inputs:
1013
configuration_file_branch:
@@ -17,17 +20,9 @@ permissions:
1720
pull-requests: write
1821

1922
jobs:
20-
# The config does not support multiple flows from the same source branch,
21-
# so we need to run separately for each duplicate source branch (https://github.com/dotnet/arcade/issues/15586).
2223
merge:
2324
if: github.repository == 'dotnet/roslyn'
2425
uses: dotnet/arcade/.github/workflows/inter-branch-merge-base.yml@main
2526
with:
2627
configuration_file_path: 'eng/config/branch-merge.jsonc'
2728
configuration_file_branch: ${{ inputs.configuration_file_branch || 'main' }}
28-
merge-2:
29-
if: github.repository == 'dotnet/roslyn'
30-
uses: dotnet/arcade/.github/workflows/inter-branch-merge-base.yml@main
31-
with:
32-
configuration_file_path: 'eng/config/branch-merge-2.jsonc'
33-
configuration_file_branch: ${{ inputs.configuration_file_branch || 'main' }}

eng/Version.Details.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<SourceBuild RepoName="source-build-externals" ManagedOnly="true" />
99
</Dependency>
1010
<!-- Intermediate is necessary for source build. -->
11-
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-reference-packages" Version="10.0.616401">
11+
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-reference-packages" Version="10.0.616701">
1212
<Uri>https://github.com/dotnet/source-build-reference-packages</Uri>
13-
<Sha>c3d4c372a15c2de79a2f26fe2b6b3644996d8550</Sha>
13+
<Sha>12b07db19093502e1530df6058699bb43bb9b4ba</Sha>
1414
<SourceBuild RepoName="source-build-reference-packages" ManagedOnly="true" />
1515
</Dependency>
1616
<Dependency Name="System.CommandLine" Version="2.0.0-beta4.24528.1">

eng/config/branch-merge-2.jsonc

Lines changed: 0 additions & 10 deletions
This file was deleted.

eng/config/branch-merge.jsonc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
// Used by .github/workflows/main-merge.yml
22
{
33
"merge-flow-configurations": {
4-
// Merge any main changes to release/dev18.0.
4+
// Merge any main changes to main-vs-deps.
55
"main": {
6+
"MergeToBranch": "main-vs-deps",
7+
"ExtraSwitches": "-QuietComments"
8+
},
9+
// Merge any main-vs-deps changes to release/dev18.0.
10+
"main-vs-deps": {
611
"MergeToBranch": "release/dev18.0",
712
"ExtraSwitches": "-QuietComments"
813
}

src/Compilers/Test/Core/Traits/Traits.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ public static class Features
290290
public const string NetCore = nameof(NetCore);
291291
public const string NormalizeModifiersOrOperators = nameof(NormalizeModifiersOrOperators);
292292
public const string ObjectBrowser = nameof(ObjectBrowser);
293+
public const string OnTheFlyDocs = nameof(OnTheFlyDocs);
293294
public const string Options = nameof(Options);
294295
public const string Organizing = nameof(Organizing);
295296
public const string Outlining = nameof(Outlining);
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using Microsoft.CodeAnalysis.CSharp.QuickInfo;
8+
using Microsoft.CodeAnalysis.CSharp.Syntax;
9+
using Microsoft.CodeAnalysis.Test.Utilities;
10+
using Xunit;
11+
12+
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.OnTheFlyDocs;
13+
14+
[UseExportProvider]
15+
[Trait(Traits.Feature, Traits.Features.OnTheFlyDocs)]
16+
public sealed class OnTheFlyDocsUtilitiesTests
17+
{
18+
[Fact]
19+
public async Task TestAdditionalContextNoContext()
20+
{
21+
var testCode = """
22+
class C
23+
{
24+
void AddMethod(int a, int b)
25+
{
26+
return a + b;
27+
}
28+
}
29+
""";
30+
31+
using var workspace = EditorTestWorkspace.CreateCSharp(testCode);
32+
var solution = workspace.CurrentSolution;
33+
var document = solution.Projects.First().Documents.First();
34+
35+
var syntaxTree = await document.GetSyntaxTreeAsync();
36+
var semanticModel = await document.GetSemanticModelAsync();
37+
38+
var methodDeclaration = syntaxTree!.GetRoot()
39+
.DescendantNodes()
40+
.OfType<MethodDeclarationSyntax>()
41+
.First();
42+
43+
var methodSymbol = semanticModel!.GetDeclaredSymbol(methodDeclaration);
44+
45+
var result = OnTheFlyDocsUtilities.GetAdditionalOnTheFlyDocsContext(solution, methodSymbol!);
46+
Assert.True(result.All(item => item == null));
47+
}
48+
49+
[Fact]
50+
public async Task TestAdditionalContextWithTypeParameters()
51+
{
52+
var testCode = """
53+
class C
54+
{
55+
int AddMethod(A a, int b)
56+
{
57+
return a.x + b;
58+
}
59+
}
60+
61+
class A
62+
{
63+
public int x;
64+
}
65+
""";
66+
67+
using var workspace = EditorTestWorkspace.CreateCSharp(testCode);
68+
var solution = workspace.CurrentSolution;
69+
var document = solution.Projects.First().Documents.First();
70+
71+
var syntaxTree = await document.GetSyntaxTreeAsync();
72+
var semanticModel = await document.GetSemanticModelAsync();
73+
74+
var methodDeclaration = syntaxTree!.GetRoot()
75+
.DescendantNodes()
76+
.OfType<MethodDeclarationSyntax>()
77+
.First();
78+
79+
var methodSymbol = semanticModel!.GetDeclaredSymbol(methodDeclaration);
80+
81+
var result = OnTheFlyDocsUtilities.GetAdditionalOnTheFlyDocsContext(solution, methodSymbol!);
82+
Assert.NotNull(result.First());
83+
Assert.Null(result.Last());
84+
}
85+
86+
[Fact]
87+
public async Task TestAdditionalContextWithTypeArguments()
88+
{
89+
var testCode = """
90+
class C
91+
{
92+
void Method<T, U>(T t, U u) where T : class where U : struct
93+
{
94+
}
95+
96+
void CallMethod()
97+
{
98+
Method<CustomClass, CustomStruct>(new CustomClass(), new CustomStruct());
99+
}
100+
}
101+
102+
class CustomClass
103+
{
104+
public string Name { get; set; }
105+
}
106+
107+
struct CustomStruct
108+
{
109+
public int Value { get; set; }
110+
}
111+
""";
112+
113+
using var workspace = EditorTestWorkspace.CreateCSharp(testCode);
114+
var solution = workspace.CurrentSolution;
115+
var document = solution.Projects.First().Documents.First();
116+
117+
var syntaxTree = await document.GetSyntaxTreeAsync();
118+
var semanticModel = await document.GetSemanticModelAsync();
119+
120+
var methodInvocation = syntaxTree!.GetRoot()
121+
.DescendantNodes()
122+
.OfType<InvocationExpressionSyntax>()
123+
.First();
124+
125+
var methodSymbol = semanticModel!.GetSymbolInfo(methodInvocation).Symbol;
126+
127+
var result = OnTheFlyDocsUtilities.GetAdditionalOnTheFlyDocsContext(solution, methodSymbol!);
128+
Assert.True(result.All(item => item is not null));
129+
}
130+
}

src/EditorFeatures/Core.Wpf/QuickInfo/OnTheFlyDocsView.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ private async Task SetResultTextAsync(ICopilotCodeAnalysisService copilotService
179179

180180
try
181181
{
182-
var (responseString, isQuotaExceeded) = await copilotService.GetOnTheFlyDocsAsync(_onTheFlyDocsInfo.SymbolSignature, _onTheFlyDocsInfo.DeclarationCode, _onTheFlyDocsInfo.Language, cancellationToken).ConfigureAwait(false);
182+
var prompt = await copilotService.GetOnTheFlyDocsPromptAsync(_onTheFlyDocsInfo, cancellationToken).ConfigureAwait(false);
183+
var (responseString, isQuotaExceeded) = await copilotService.GetOnTheFlyDocsResponseAsync(prompt, cancellationToken).ConfigureAwait(false);
183184
var copilotRequestTime = stopwatch.Elapsed;
184185

185186
await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

src/EditorFeatures/Test2/CodeFixes/CodeFixServiceTests.vb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Imports Microsoft.CodeAnalysis.ErrorLogger
1919
Imports Microsoft.CodeAnalysis.FindSymbols
2020
Imports Microsoft.CodeAnalysis.Host
2121
Imports Microsoft.CodeAnalysis.Host.Mef
22+
Imports Microsoft.CodeAnalysis.QuickInfo
2223
Imports Microsoft.CodeAnalysis.Text
2324
Imports Microsoft.CodeAnalysis.UnitTests
2425
Imports Roslyn.Utilities
@@ -359,10 +360,6 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.CodeFixes.UnitTests
359360
Return Task.CompletedTask
360361
End Function
361362

362-
Public Function GetOnTheFlyDocsAsync(symbolSignature As String, declarationCode As ImmutableArray(Of String), language As String, cancellationToken As CancellationToken) As Task(Of (responseString As String, isQuotaExceeded As Boolean)) Implements ICopilotCodeAnalysisService.GetOnTheFlyDocsAsync
363-
Return Task.FromResult(("", False))
364-
End Function
365-
366363
Public Function IsFileExcludedAsync(filePath As String, cancellationToken As CancellationToken) As Task(Of Boolean) Implements ICopilotCodeAnalysisService.IsFileExcludedAsync
367364
Return Task.FromResult(False)
368365
End Function
@@ -371,6 +368,14 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.CodeFixes.UnitTests
371368
Return Task.FromResult((New Dictionary(Of String, String), False))
372369
End Function
373370

371+
Public Function GetOnTheFlyDocsPromptAsync(onTheFlyDocsInfo As OnTheFlyDocsInfo, cancellationToken As CancellationToken) As Task(Of String) Implements ICopilotCodeAnalysisService.GetOnTheFlyDocsPromptAsync
372+
Return Task.FromResult(String.Empty)
373+
End Function
374+
375+
Public Function GetOnTheFlyDocsResponseAsync(prompt As String, cancellationToken As CancellationToken) As Task(Of (responseString As String, isQuotaExceeded As Boolean)) Implements ICopilotCodeAnalysisService.GetOnTheFlyDocsResponseAsync
376+
Return Task.FromResult((String.Empty, False))
377+
End Function
378+
374379
Public Function IsImplementNotImplementedExceptionsAvailableAsync(cancellationToken As CancellationToken) As Task(Of Boolean) Implements ICopilotCodeAnalysisService.IsImplementNotImplementedExceptionsAvailableAsync
375380
Return Task.FromResult(False)
376381
End Function

src/Features/CSharp/Portable/QuickInfo/CSharpSemanticQuickInfoProvider.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,21 @@ protected override NullableFlowState GetNullabilityAnalysis(SemanticModel semant
193193
}
194194
}
195195

196-
var maxLength = 1000;
197-
var symbolStrings = symbol.DeclaringSyntaxReferences.Select(reference =>
196+
var solution = document.Project.Solution;
197+
var declarationCode = symbol.DeclaringSyntaxReferences.Select(reference =>
198198
{
199199
var span = reference.Span;
200-
var sourceText = reference.SyntaxTree.GetText(cancellationToken);
201-
return sourceText.GetSubText(new Text.TextSpan(span.Start, Math.Min(maxLength, span.Length))).ToString();
200+
var syntaxReferenceDocument = solution.GetDocument(reference.SyntaxTree);
201+
if (syntaxReferenceDocument is not null)
202+
{
203+
return new OnTheFlyDocsRelevantFileInfo(syntaxReferenceDocument, span);
204+
}
205+
206+
return null;
202207
}).ToImmutableArray();
203208

204-
return new OnTheFlyDocsInfo(symbol.ToDisplayString(), symbolStrings, symbol.Language, hasContentExcluded);
209+
var additionalContext = OnTheFlyDocsUtilities.GetAdditionalOnTheFlyDocsContext(solution, symbol);
210+
211+
return new OnTheFlyDocsInfo(symbol.ToDisplayString(), declarationCode, symbol.Language, hasContentExcluded, additionalContext);
205212
}
206213
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Collections.Immutable;
6+
using System.Linq;
7+
using Microsoft.CodeAnalysis.QuickInfo;
8+
using Microsoft.CodeAnalysis.Shared.Extensions;
9+
10+
namespace Microsoft.CodeAnalysis.CSharp.QuickInfo;
11+
12+
internal static class OnTheFlyDocsUtilities
13+
{
14+
public static ImmutableArray<OnTheFlyDocsRelevantFileInfo?> GetAdditionalOnTheFlyDocsContext(Solution solution, ISymbol symbol)
15+
{
16+
var parameters = symbol.GetParameters();
17+
var typeArguments = symbol.GetTypeArguments();
18+
19+
var parameterStrings = parameters.Select(parameter =>
20+
{
21+
var typeSymbol = parameter.Type;
22+
return GetOnTheFlyDocsRelevantFileInfo(typeSymbol);
23+
24+
}).ToImmutableArray();
25+
26+
var typeArgumentStrings = typeArguments.Select(typeArgument =>
27+
{
28+
return GetOnTheFlyDocsRelevantFileInfo(typeArgument);
29+
30+
}).ToImmutableArray();
31+
32+
return parameterStrings.AddRange(typeArgumentStrings);
33+
34+
OnTheFlyDocsRelevantFileInfo? GetOnTheFlyDocsRelevantFileInfo(ITypeSymbol typeSymbol)
35+
{
36+
var typeSyntaxReference = typeSymbol.DeclaringSyntaxReferences.FirstOrDefault();
37+
if (typeSyntaxReference is not null)
38+
{
39+
var typeSpan = typeSyntaxReference.Span;
40+
var syntaxReferenceDocument = solution.GetDocument(typeSyntaxReference.SyntaxTree);
41+
if (syntaxReferenceDocument is not null)
42+
{
43+
return new OnTheFlyDocsRelevantFileInfo(syntaxReferenceDocument, typeSpan);
44+
}
45+
}
46+
47+
return null;
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)