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

Don't preload completion providers we don't need. #11413

Merged
merged 7 commits into from
May 19, 2016
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/Rulesets/NonShippingProjectRules.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
<!-- See above comment under CSharp -->
<Rule Id="RS0003" Action="None" />
<Rule Id="RS0007" Action="None" />
<Rule Id="RS0005" Action="None" />
Copy link
Member Author

@CyrusNajmabadi CyrusNajmabadi May 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "Do not use generic CodeAction.Create to create CodeAction" analyzer is crashing when it analyzed BasicEditorServicesTest. The analyzer isn't of any value to the test code*, and we need to unblock this RI issue, so i'm just disabling it from running here.

* The analyzer is about not calling CodeAction.Create directly (and instead creating a subclass of DocumentCodeAction). That not relevant in test code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi @mavasani

</Rules>
</RuleSet>
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// 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 System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Completion;
using Microsoft.CodeAnalysis.Editor.UnitTests.Completion;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Text;
using Xunit;

Expand All @@ -20,6 +20,12 @@ protected AbstractCSharpCompletionProviderTests(CSharpTestWorkspaceFixture works
{
}

internal override CompletionServiceWithProviders CreateCompletionService(
Workspace workspace, ImmutableArray<CompletionProvider> exclusiveProviders)
{
return new CSharpCompletionService(workspace, exclusiveProviders);
}

protected override async Task VerifyWorkerAsync(string code, int position, string expectedItemOrNull, string expectedDescriptionOrNull, SourceCodeKind sourceCodeKind, bool usePreviousCharAsTrigger, bool checkForAbsence, bool experimental, int? glyph)
{
await VerifyAtPositionAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, experimental, glyph);
Expand Down Expand Up @@ -138,14 +144,14 @@ protected async Task VerifySendEnterThroughToEnterAsync(string initialMarkup, st
var document = workspace.CurrentSolution.GetDocument(documentId);
var position = hostDocument.CursorPosition.Value;

var completionList = await GetCompletionListAsync(document, position, CompletionTrigger.Default);
var item = completionList.Items.First(i => i.DisplayText.StartsWith(textTypedSoFar));
workspace.Options = workspace.Options.WithChangedOption(
CSharpCompletionOptions.AddNewLineOnEnterAfterFullyTypedWord, sendThroughEnterEnabled);

var optionService = workspace.Services.GetService<IOptionService>();
var options = optionService.GetOptions().WithChangedOption(CSharpCompletionOptions.AddNewLineOnEnterAfterFullyTypedWord, sendThroughEnterEnabled);
optionService.SetOptions(options);
var service = GetCompletionService(workspace);
var completionList = await GetCompletionListAsync(service, document, position, CompletionTrigger.Default);
var item = completionList.Items.First(i => i.DisplayText.StartsWith(textTypedSoFar));

var completionRules = CompletionHelper.GetHelper(document);
var completionRules = CompletionHelper.GetHelper(document, service);
Assert.Equal(expected, completionRules.SendEnterThroughToEditor(item, textTypedSoFar, workspace.Options));
}
}
Expand All @@ -166,7 +172,8 @@ private async Task VerifyTextualTriggerCharacterWorkerAsync(string markup, bool
var options = workspace.Options.WithChangedOption(CompletionOptions.TriggerOnTypingLetters, LanguageNames.CSharp, triggerOnLetter);
var trigger = CompletionTrigger.CreateInsertionTrigger(text[position]);

var isTextualTriggerCharacterResult = CompletionProvider.ShouldTriggerCompletion(text, position + 1, trigger, options);
var service = GetCompletionService(workspace);
var isTextualTriggerCharacterResult = service.ShouldTriggerCompletion(text, position + 1, trigger, options: options);

if (expectedTriggerCharacter)
{
Expand Down Expand Up @@ -205,10 +212,11 @@ protected async Task VerifyCommitCharactersAsync(string initialMarkup, string te
var document = workspace.CurrentSolution.GetDocument(documentId);
var position = hostDocument.CursorPosition.Value;

var completionList = await GetCompletionListAsync(document, position, CompletionTrigger.Default);
var service = GetCompletionService(workspace);
var completionList = await GetCompletionListAsync(service, document, position, CompletionTrigger.Default);
var item = completionList.Items.First(i => i.DisplayText.StartsWith(textTypedSoFar));

var completionRules = CompletionHelper.GetHelper(document);
var completionRules = CompletionHelper.GetHelper(document, service);

foreach (var ch in validChars)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ class C
var provider = new CrefCompletionProvider();
var hostDocument = workspace.DocumentWithCursor;
var document = workspace.CurrentSolution.GetDocument(hostDocument.Id);
var completionList = await GetCompletionListAsync(provider, document, hostDocument.CursorPosition.Value, CompletionTrigger.Default);
var service = GetCompletionService(workspace);
var completionList = await GetCompletionListAsync(service, document, hostDocument.CursorPosition.Value, CompletionTrigger.Default);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// 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 System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.CSharp.Completion.Providers;
Expand Down Expand Up @@ -576,10 +575,11 @@ void foo()
var document = workspace.CurrentSolution.GetDocument(hostDocument.Id);
var triggerInfo = CompletionTrigger.CreateInsertionTrigger('a');

var completionList = await GetCompletionListAsync(document, position, triggerInfo);
var service = GetCompletionService(workspace);
var completionList = await GetCompletionListAsync(service, document, position, triggerInfo);
var item = completionList.Items.First();

var completionRules = CompletionHelper.GetHelper(document);
var completionRules = CompletionHelper.GetHelper(document, service);

Assert.False(completionRules.SendEnterThroughToEditor(item, string.Empty, workspace.Options), "Expected false from SendEnterThroughToEditor()");
}
Expand Down Expand Up @@ -777,7 +777,8 @@ private async Task VerifyExclusiveAsync(string markup, bool exclusive)
var document = workspace.CurrentSolution.GetDocument(hostDocument.Id);
var triggerInfo = CompletionTrigger.CreateInsertionTrigger('a');

var completionList = await GetCompletionListContextAsync(document, position, triggerInfo);
var service = GetCompletionService(workspace);
var completionList = await GetCompletionListAsync(service, document, position, triggerInfo);

if (completionList != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2126,10 +2126,11 @@ public override void set_Bar(int bay, int value)
var document = solution.GetDocument(documentId);
var triggerInfo = CompletionTrigger.Default;

var completionList = await GetCompletionListAsync(document, position, triggerInfo);
var service = GetCompletionService(testWorkspace);
var completionList = await GetCompletionListAsync(service, document, position, triggerInfo);
var completionItem = completionList.Items.First(i => CompareItems(i.DisplayText, "Bar[int bay]"));

var customCommitCompletionProvider = CompletionProvider as ICustomCommitCompletionProvider;
var customCommitCompletionProvider = service.ExclusiveProviders?[0] as ICustomCommitCompletionProvider;
if (customCommitCompletionProvider != null)
{
var textView = testWorkspace.GetTestDocument(documentId).GetTextView();
Expand Down Expand Up @@ -2385,10 +2386,11 @@ public override bool Equals(object obj)
var document = solution.GetDocument(documentId);
var triggerInfo = CompletionTrigger.Default;

var completionList = await GetCompletionListAsync(document, position, triggerInfo);
var service = GetCompletionService(testWorkspace);
var completionList = await GetCompletionListAsync(service, document, position, triggerInfo);
var completionItem = completionList.Items.First(i => CompareItems(i.DisplayText, "Equals(object obj)"));

var customCommitCompletionProvider = CompletionProvider as ICustomCommitCompletionProvider;
var customCommitCompletionProvider = service.ExclusiveProviders?[0] as ICustomCommitCompletionProvider;
if (customCommitCompletionProvider != null)
{
var textView = testWorkspace.GetTestDocument(documentId).GetTextView();
Expand Down Expand Up @@ -2443,10 +2445,11 @@ public override bool Equals(object obj)
var document = solution.GetDocument(documentId);
var triggerInfo = CompletionTrigger.Default;

var completionList = await GetCompletionListAsync(document, cursorPosition, triggerInfo);
var service = GetCompletionService(testWorkspace);
var completionList = await GetCompletionListAsync(service, document, cursorPosition, triggerInfo);
var completionItem = completionList.Items.First(i => CompareItems(i.DisplayText, "Equals(object obj)"));

var customCommitCompletionProvider = CompletionProvider as ICustomCommitCompletionProvider;
var customCommitCompletionProvider = service.ExclusiveProviders?[0] as ICustomCommitCompletionProvider;
if (customCommitCompletionProvider != null)
{
var textView = testWorkspace.GetTestDocument(documentId).GetTextView();
Expand Down Expand Up @@ -2541,20 +2544,24 @@ static void Main(string[] args)
override $$
}
}";
var workspace = await TestWorkspace.CreateAsync(LanguageNames.CSharp, new CSharpCompilationOptions(OutputKind.ConsoleApplication), new CSharpParseOptions(), text);
var provider = new OverrideCompletionProvider();
var testDocument = workspace.Documents.Single();
var document = workspace.CurrentSolution.GetDocument(testDocument.Id);
var completionList = await GetCompletionListAsync(provider, document, testDocument.CursorPosition.Value, CompletionTrigger.Default);
using (var workspace = await TestWorkspace.CreateAsync(LanguageNames.CSharp, new CSharpCompilationOptions(OutputKind.ConsoleApplication), new CSharpParseOptions(), text))
{
var provider = new OverrideCompletionProvider();
var testDocument = workspace.Documents.Single();
var document = workspace.CurrentSolution.GetDocument(testDocument.Id);

var service = GetCompletionService(workspace);
var completionList = await GetCompletionListAsync(service, document, testDocument.CursorPosition.Value, CompletionTrigger.Default);

var oldTree = await document.GetSyntaxTreeAsync();
var oldTree = await document.GetSyntaxTreeAsync();

var commit = await provider.GetChangeAsync(document, completionList.Items.First(i => i.DisplayText == "ToString()"), ' ');
var changes = commit.TextChanges;
var commit = await provider.GetChangeAsync(document, completionList.Items.First(i => i.DisplayText == "ToString()"), ' ');
var changes = commit.TextChanges;

// If we left the trailing trivia of the close curly of Main alone,
// there should only be one change: the replacement of "override " with a method.
Assert.Equal(changes.Single().Span, TextSpan.FromBounds(136, 145));
// If we left the trailing trivia of the close curly of Main alone,
// there should only be one change: the replacement of "override " with a method.
Assert.Equal(changes.Single().Span, TextSpan.FromBounds(136, 145));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,10 @@ private async Task VerifyWorkerAsync(string markup, bool isBuilder)
private async Task CheckResultsAsync(Document document, int position, bool isBuilder)
{
var triggerInfo = CompletionTrigger.CreateInsertionTrigger('a');
var completionList = await GetCompletionListAsync(document, position, triggerInfo);
var service = GetCompletionService(document.Project.Solution.Workspace);
var completionList = await service.GetContextAsync(
service.ExclusiveProviders?[0], document, position, triggerInfo,
options: null, cancellationToken: CancellationToken.None);

if (isBuilder)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ protected CompletionHelper(CompletionService completionService)
_rules = CompletionService.GetRules();
}

public static CompletionHelper GetHelper(Workspace workspace, string language)
public static CompletionHelper GetHelper(
Workspace workspace, string language, CompletionService completionService)
{
var ls = workspace.Services.GetLanguageServices(language);
if (ls != null)
{
var factory = ls.GetService<CompletionHelperFactory>();
if (factory != null)
{
return factory.CreateCompletionHelper();
return factory.CreateCompletionHelper(completionService);
}

var completionService = ls.GetService<CompletionService>();
if (completionService != null)
{
return new CompletionHelper(completionService);
Expand All @@ -50,9 +50,9 @@ public static CompletionHelper GetHelper(Workspace workspace, string language)
return null;
}

public static CompletionHelper GetHelper(Document document)
public static CompletionHelper GetHelper(Document document, CompletionService service)
{
return GetHelper(document.Project.Solution.Workspace, document.Project.Language);
return GetHelper(document.Project.Solution.Workspace, document.Project.Language, service);
}

public IReadOnlyList<TextSpan> GetHighlightedSpans(CompletionItem completionItem, string filterText)
Expand Down Expand Up @@ -446,9 +446,10 @@ protected bool IsObjectCreationItem(CompletionItem item)
return item.Tags.Contains(CompletionTags.ObjectCreation);
}

public static async Task<TextChange> GetTextChangeAsync(Document document, CompletionItem item, char? commitKey = null, CancellationToken cancellationToken = default(CancellationToken))
public static async Task<TextChange> GetTextChangeAsync(
CompletionService service, Document document, CompletionItem item,
char? commitKey = null, CancellationToken cancellationToken = default(CancellationToken))
{
var service = CompletionService.GetService(document);
var change = await service.GetChangeAsync(document, item, commitKey, cancellationToken).ConfigureAwait(false);

// normally the items that produce multiple changes are not expecting to trigger the behaviors that rely on looking at the text
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// 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 System;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.Host;

namespace Microsoft.CodeAnalysis.Editor
{
internal abstract class CompletionHelperFactory : ILanguageService
{
public abstract CompletionHelper CreateCompletionHelper();
public abstract CompletionHelper CreateCompletionHelper(CompletionService completionService);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// 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 System;
using System.Threading;
using Microsoft.CodeAnalysis.Editor.Commands;
using Microsoft.CodeAnalysis.Text;

namespace Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.Completion
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.VisualStudio.Text;
using Roslyn.Utilities;
using System.Threading;
using Microsoft.CodeAnalysis.Shared.Extensions;

namespace Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.Completion
{
Expand Down Expand Up @@ -273,7 +274,8 @@ private CompletionHelper GetCompletionHelper()
var document = this.SubjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document != null)
{
return CompletionHelper.GetHelper(document);
return CompletionHelper.GetHelper(
document, document.GetLanguageService<CompletionService>());
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override async Task<CompletionDescription> GetDescriptionAsync(Document d
var description = await this.CompletionService.GetDescriptionAsync(document, this.Item, cancellationToken).ConfigureAwait(false);
var parts = description.TaggedParts;

var change = await CompletionHelper.GetTextChangeAsync(document, this.Item, '\t').ConfigureAwait(false);
var change = await CompletionHelper.GetTextChangeAsync(this.CompletionService, document, this.Item, '\t').ConfigureAwait(false);
var insertionText = change.NewText;

var note = string.Empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using VSCompletion = Microsoft.VisualStudio.Language.Intellisense.Completion;
using Microsoft.CodeAnalysis.Snippets;

namespace Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.Completion.Presentation
{
Expand Down Expand Up @@ -205,7 +204,8 @@ private CompletionHelper GetCompletionHelper()
var document = _subjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document != null)
{
_completionHelper = CompletionHelper.GetHelper(document);
_completionHelper = CompletionHelper.GetHelper(document,
document.Project.LanguageServices.GetService<CompletionService>());
}
}

Expand Down
Loading