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

Pass per-document options when organizing imports or usings #17347

Merged
merged 3 commits into from
Feb 24, 2017

Conversation

jmarolf
Copy link
Contributor

@jmarolf jmarolf commented Feb 24, 2017

fixes #17342

@@ -12,28 +14,31 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Organizing
{
public class OrganizeUsingsTests
{
protected async Task CheckAsync(string initial, string final, bool specialCaseSystem, CSharpParseOptions options = null)
protected async Task CheckAsync(string initial, string final, bool placeSystemNamespaceFirst = false, CSharpParseOptions options = null)
Copy link
Member

Choose a reason for hiding this comment

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

i hate that this is optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can make it required. Just saw a lot of tests passing in random true/false values even when it didn't affect the test. false is the default in VS. It seemed reasonable that only tests that were explicitly testing this behavior should change it. should parse options be non-optional as well?

Copy link
Member

Choose a reason for hiding this comment

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

i'm ok with this being optional now :)

{
using (var workspace = await TestWorkspace.CreateCSharpAsync(initial))
{
var document = workspace.CurrentSolution.GetDocument(workspace.Documents.First().Id);
var newRoot = await (await OrganizeImportsService.OrganizeImportsAsync(document, specialCaseSystem)).GetSyntaxRootAsync();
var workspaceOptions = workspace.Options;
var newOptionSet = workspaceOptions.WithChangedOption(new OptionKey(GenerationOptions.PlaceSystemNamespaceFirst, document.Project.Language), placeSystemNamespaceFirst);
Copy link
Member

Choose a reason for hiding this comment

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

inline both these variables.

cancellationToken As CancellationToken) As Task(Of Document) Implements IOrganizeImportsService.OrganizeImportsAsync
Dim root = Await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(False)
Dim options = Await document.GetOptionsAsync(cancellationToken).ConfigureAwait(False)
Dim placeSystemNamespaceFirst = options.GetOption(GenerationOptions.PlaceSystemNamespaceFirst, document.Project.Language)
Copy link
Member

Choose a reason for hiding this comment

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

isn't passing hte language unnecessary? ti's known in the DocumentOptions that you got from document.GetOptionsAsync.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The option is a PerLanguageOption because it can be set differently for C# or VB if you don't use editorconfig

Copy link
Member

Choose a reason for hiding this comment

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

right. but options.GetOption, when passed a PerLanguageOption, does not need a language passed in as well. Right?

@@ -4,16 +4,18 @@ Imports System.Threading
Imports Microsoft.CodeAnalysis.Host.Mef
Imports Microsoft.CodeAnalysis.OrganizeImports
Imports System.Composition
Imports Microsoft.CodeAnalysis.Editing
Copy link
Member

Choose a reason for hiding this comment

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

SORT

@jmarolf jmarolf merged commit 8d401fd into dotnet:master Feb 24, 2017
Copy link
Member

@Pilchie Pilchie left a comment

Choose a reason for hiding this comment

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

👍

@jmarolf jmarolf deleted the bugfix/have-add-imports-check-option branch January 27, 2020 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ITextBufferExtensions.GetFeatureOnOffOption does not get per-document options.
4 participants