-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Don't use symbolid in symbol completion #15688
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0598b18
Don't use symbolid in symbl completion
06cd97a
CR feedback
47400de
Various CR feedback:
95eb04f
Satisfy RepoUtil
da54972
Fix tests
0054e90
Line wrapping/copyright headers
50bd970
Pass through correct SemanticModel
df29fa8
Make description computation work in linked files
c1fe0af
Use correct version of ValueTuple
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/Features/Core/Portable/Completion/Providers/AbstractCrefCompletionProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.CodeAnalysis.Options; | ||
using System.Collections.Immutable; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.CodeAnalysis.Completion.Providers | ||
{ | ||
abstract class AbstractCrefCompletionProvider : CommonCompletionProvider | ||
{ | ||
protected const string HideAdvancedMembers = nameof(HideAdvancedMembers); | ||
|
||
protected override async Task<CompletionDescription> GetDescriptionWorkerAsync(Document document, CompletionItem item, CancellationToken cancellationToken) | ||
{ | ||
var position = SymbolCompletionItem.GetContextPosition(item); | ||
|
||
// What EditorBrowsable settings were we previously passed in (if it mattered)? | ||
bool hideAdvancedMembers = false; | ||
if (item.Properties.TryGetValue(HideAdvancedMembers, out var hideAdvancedMembersString)) | ||
{ | ||
bool.TryParse(hideAdvancedMembersString, out hideAdvancedMembers); | ||
} | ||
|
||
var options = document.Project.Solution.Workspace.Options | ||
.WithChangedOption(new OptionKey(CompletionOptions.HideAdvancedMembers, document.Project.Language), hideAdvancedMembers); | ||
|
||
var (token, semanticModel, symbols) = await GetSymbolsAsync(document, position, options, cancellationToken).ConfigureAwait(false); | ||
var name = SymbolCompletionItem.GetSymbolName(item); | ||
var kind = SymbolCompletionItem.GetKind(item); | ||
var bestSymbols = symbols.WhereAsArray(s => s.Kind == kind && s.Name == name); | ||
return await SymbolCompletionItem.GetDescriptionAsync(item, bestSymbols, document, semanticModel, cancellationToken).ConfigureAwait(false); | ||
} | ||
|
||
protected abstract Task<(SyntaxToken, SemanticModel, ImmutableArray<ISymbol>)> GetSymbolsAsync( | ||
Document document, int position, OptionSet options, CancellationToken cancellationToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. copyright. |
||
|
||
using Microsoft.CodeAnalysis.LanguageServices; | ||
using Microsoft.CodeAnalysis.Options; | ||
using Microsoft.CodeAnalysis.Recommendations; | ||
using Microsoft.CodeAnalysis.Shared.Extensions; | ||
using Microsoft.CodeAnalysis.Shared.Extensions.ContextQuery; | ||
using Microsoft.CodeAnalysis.Shared.Utilities; | ||
using Microsoft.CodeAnalysis.Text; | ||
using Roslyn.Utilities; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.CodeAnalysis.Completion.Providers | ||
{ | ||
|
@@ -35,10 +38,10 @@ protected override async Task<ImmutableArray<ISymbol>> GetPreselectedSymbolsWork | |
} | ||
|
||
var symbols = await recommender.GetRecommendedSymbolsAtPositionAsync( | ||
context.Workspace, | ||
context.SemanticModel, | ||
position, | ||
options, | ||
context.Workspace, | ||
context.SemanticModel, | ||
context.Position, | ||
options, | ||
cancellationToken).ConfigureAwait(false); | ||
|
||
// Don't preselect intrinsic type symbols so we can preselect their keywords instead. | ||
|
@@ -64,7 +67,7 @@ protected override CompletionItem CreateItem(string displayText, string insertio | |
rules = rules.WithSelectionBehavior(PreselectedItemSelectionBehavior); | ||
} | ||
|
||
return SymbolCompletionItem.Create( | ||
return SymbolCompletionItem.CreateWithNameAndKind( | ||
displayText: displayText, | ||
insertionText: insertionText, | ||
filterText: GetFilterText(symbols[0], displayText, context), | ||
|
@@ -100,5 +103,26 @@ private static int ComputeSymbolMatchPriority(ISymbol symbol) | |
|
||
return SymbolMatchPriority.PreferType; | ||
} | ||
|
||
protected override async Task<CompletionDescription> GetDescriptionWorkerAsync( | ||
Document document, CompletionItem item, CancellationToken cancellationToken) | ||
{ | ||
var position = SymbolCompletionItem.GetContextPosition(item); | ||
var name = SymbolCompletionItem.GetSymbolName(item); | ||
var kind = SymbolCompletionItem.GetKind(item); | ||
var relatedDocumentIds = document.Project.Solution.GetRelatedDocumentIds(document.Id).Concat(document.Id); | ||
var options = document.Project.Solution.Workspace.Options; | ||
var totalSymbols = await base.GetPerContextSymbols(document, position, options, relatedDocumentIds, preselect: false, cancellationToken: cancellationToken).ConfigureAwait(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why base.? |
||
foreach (var info in totalSymbols) | ||
{ | ||
var bestSymbols = info.Item3.Where(s => kind != null && s.Kind == kind && s.Name == name).ToImmutableArray(); | ||
if (bestSymbols.Any()) | ||
{ | ||
return await SymbolCompletionItem.GetDescriptionAsync(item, bestSymbols, document, info.Item2.SemanticModel, cancellationToken).ConfigureAwait(false); | ||
} | ||
} | ||
|
||
return CompletionDescription.Empty; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we changing options? why are we not just using the option as defined by the user?
Doing this actually overrides the user's choice here.