-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Implementation of new editor completion API #25770
Conversation
8f88f2f
to
0edd0b8
Compare
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.
Looks good :) I left a few comments but I haven't looked in depth at committing and handling non-roslyn items.
[ContentType(ContentTypeNames.RoslynContentType)] | ||
internal class CompletionItemSourceProvider : IAsyncCompletionCommitManagerProvider | ||
{ | ||
IAsyncCompletionCommitManager _instance; |
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.
Consider cleaning up when the Roslyn workspace is unloaded
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.
@AmadeusW Why? We have no sane unload operation.
internal const string TriggerBuffer = nameof(TriggerBuffer); | ||
internal const string MatchPriority = nameof(MatchPriority); | ||
internal const string SelectionBehavior = nameof(SelectionBehavior); | ||
internal const string InsertionText = "InsertionText"; |
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.
nameof
return false; | ||
} | ||
|
||
// TODO: TypeChar of 0 means Invoke or InvokeAndCommitIfUnique. An API update will make this better. |
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.
How would you like the API to look like?
I'd make the comment explicitly state that we have to provide a span in Invoke or InvokeAndCommitIfUnique scenarios
[ContentType(ContentTypeNames.RoslynContentType)] | ||
internal class CompletionSourceProvider : IAsyncCompletionSourceProvider | ||
{ | ||
IAsyncCompletionSource _instance; |
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.
cleanup when workspace is unloaded
|
||
private static bool IsAllPunctuation(string filterText) | ||
{ | ||
foreach (var ch in filterText) |
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.
for loop will reduce allocations
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.
This is not correct. Neither form will result in allocations. The generated code is not quite identical in debug builds but for all practical purposes it's the same. With optimizations enabled the generated IL is equal.
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.
That's good to know, thanks!
|
||
if (usePreviousCharAsTrigger) | ||
{ | ||
trigger = CompletionTrigger.CreateInsertionTrigger(insertedCharacter: code.ElementAt(position - 1)); | ||
trigger = RoslynCompletion.CompletionTrigger.CreateInsertionTrigger(insertedCharacter: code.ElementAt(position - 1)); |
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.
is there a potential error when document is empty or position is otherwise 0?
@@ -21,6 +21,7 @@ namespace Microsoft.VisualStudio.LanguageServices.CSharp.Snippets | |||
[Name("CSharp Snippets")] | |||
[Order(After = CodeAnalysis.Editor.PredefinedCommandHandlerNames.Completion)] | |||
[Order(After = CodeAnalysis.Editor.PredefinedCommandHandlerNames.IntelliSense)] | |||
[Order(After = "CompletionCommandHandlers")] |
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.
PredefinedCompletionNames.CompletionCommandHandlers
public bool IsCaretOnScreen() | ||
=> _editorInProc.IsCaretOnScreen(); | ||
//public bool IsCaretOnScreen() | ||
// => _editorInProc.IsCaretOnScreen(); |
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.
did completion affect this, or is this unrelated?
This fixes a signing regression caused be #25751. That changed us to directly call the SWIX build props / targets vs. getting them implicitly from the microbuild props / targets. One of the behaviors that the microbuild props / targets had that wasn't accounted for was the signing of the VSIX after they are constructed. Hence this lead to signing errors on insertion. This PR fixes that by making the following changes: 1. Adds SWIX VSIX to SignToolData.json so they are accounted for during normal batch signing. 1. Moves the SWIX build to the pre-sign portion of our build. 1. Removes the references from VSMAN -> SWIX. These references are there only to enforce ordering which is unnecessary. Having them remain risks that building the VSMAN will cause the SWIX to be re-built which could possibly invalidate signing.
7136c48
to
8b9ac6b
Compare
@dotnet-bot retest |
commitCharacter, | ||
token).WaitAndGetResult(token); | ||
|
||
edit.Replace(change.TextChange.Span.ToSpan(), change.TextChange.NewText); |
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.
token).WaitAndGetResult(token); | ||
|
||
edit.Replace(change.TextChange.Span.ToSpan(), change.TextChange.NewText); | ||
edit.Apply(); |
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.
char commitCharacter, | ||
CancellationToken token) | ||
{ | ||
var document = buffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges(); |
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.
} | ||
|
||
var completionService = document.GetLanguageService<CompletionService>(); | ||
if (!item.Properties.TryGetProperty<RoslynCompletionItem>(CompletionItemSource.RoslynItem, out var roslynItem)) |
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.
Yes, such as Razor items.
var completionList = await completionService.GetCompletionsAsync( | ||
document, | ||
triggerLocation, | ||
GetRoslynTrigger(trigger)).ConfigureAwait(false); |
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.
@@ -26,7 +26,7 @@ internal abstract class AbstractCommandHandlerTestState : IDisposable | |||
public readonly TestWorkspace Workspace; | |||
public readonly IEditorOperations EditorOperations; | |||
public readonly ITextUndoHistoryRegistry UndoHistoryRegistry; | |||
private readonly ITextView _textView; | |||
protected readonly ITextView _textView; |
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.
Done
namespace Microsoft.CodeAnalysis.Test.Utilities.ExperimentationService | ||
{ | ||
[Export(typeof(IExperimentationServiceInternal)), Shared] | ||
internal class TestExperimentationServiceInternal : IExperimentationServiceInternal |
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.
@ivanbasov Do we need to be able to set this up differently for old/new unit tests?
namespace Microsoft.CodeAnalysis.Test.Utilities.ExperimentationService | ||
{ | ||
[Export(typeof(IExperimentationServiceInternal)), Shared] | ||
internal class TestExperimentationServiceInternal : IExperimentationServiceInternal |
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.
attributeImages = ImmutableArray.Create( | ||
new ImageElement( | ||
warningImage, | ||
"Temporary Automation Name")); // TODO: Get automation names, here and below |
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.
ImmutableArray<EditorCompletion.CompletionFilter> activeFilters, | ||
bool mustSetSelection) | ||
{ | ||
// TODO: DismissIfEmpty? |
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.
retest this please |
Previous review: #25537
TODOs: https://github.com/dotnet/roslyn/projects/38
Ask Mode template not completed
Customer scenario
What does the customer do to get into this situation, and why do we think this
is common enough to address for this release. (Granted, sometimes this will be
obvious "Open project, VS crashes" but in general, I need to understand how
common a scenario is)
Bugs this fixes
(either VSO or GitHub links)
Workarounds, if any
Also, why we think they are insufficient for RC vs. RC2, RC3, or RTW
Risk
This is generally a measure our how central the affected code is to adjacent
scenarios and thus how likely your fix is to destabilize a broader area of code
Performance impact
(with a brief justification for that assessment (e.g. "Low perf impact because no extra allocations/no complexity changes" vs. "Low")
Is this a regression from a previous update?
Root cause analysis
How did we miss it? What tests are we adding to guard against it in the future?
How was the bug found?
(E.g. customer reported it vs. ad hoc testing)
Test documentation updated?
If this is a new non-compiler feature or a significant improvement to an existing feature, update https://github.com/dotnet/roslyn/wiki/Manual-Testing once you know which release it is targeting.