提交 8a58a8e8 编写于 作者: J Jason Malinowski

Move consumers of Workspace.Options to Solution/Document.Options

上级 14ae44d3
......@@ -58,11 +58,11 @@ public CSharpEditorFormattingService()
public bool SupportsFormattingOnTypedCharacter(Document document, char ch)
{
var options = document.Project.Solution.Workspace.Options;
var smartIndentOn = options.GetOption(FormattingOptions.SmartIndent, document.Project.Language) == FormattingOptions.IndentStyle.Smart;
var options = document.Options;
var smartIndentOn = options.GetOption(FormattingOptions.SmartIndent) == FormattingOptions.IndentStyle.Smart;
if ((ch == '}' && !options.GetOption(FeatureOnOffOptions.AutoFormattingOnCloseBrace, document.Project.Language) && !smartIndentOn) ||
(ch == ';' && !options.GetOption(FeatureOnOffOptions.AutoFormattingOnSemicolon, document.Project.Language)))
if ((ch == '}' && !options.GetOption(FeatureOnOffOptions.AutoFormattingOnCloseBrace) && !smartIndentOn) ||
(ch == ';' && !options.GetOption(FeatureOnOffOptions.AutoFormattingOnSemicolon)))
{
return false;
}
......@@ -182,12 +182,10 @@ public async Task<IList<TextChange>> GetFormattingChangesAsync(Document document
return null;
}
var options = document.Project.Solution.Workspace.Options;
// don't attempt to format on close brace if autoformat on close brace feature is off, instead just smart indent
bool smartIndentOnly =
token.IsKind(SyntaxKind.CloseBraceToken) &&
!options.GetOption(FeatureOnOffOptions.AutoFormattingOnCloseBrace, document.Project.Language);
!document.Options.GetOption(FeatureOnOffOptions.AutoFormattingOnCloseBrace);
if (!smartIndentOnly)
{
......@@ -216,7 +214,7 @@ private static async Task<SyntaxToken> GetTokenBeforeTheCaretAsync(Document docu
private async Task<IList<TextChange>> FormatTokenAsync(Document document, SyntaxToken token, IEnumerable<IFormattingRule> formattingRules, CancellationToken cancellationToken)
{
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var formatter = CreateSmartTokenFormatter(document.Project.Solution.Workspace.Options, formattingRules, root);
var formatter = CreateSmartTokenFormatter(document.Options, formattingRules, root);
var changes = await formatter.FormatTokenAsync(document.Project.Solution.Workspace, token, cancellationToken).ConfigureAwait(false);
return changes;
}
......@@ -247,7 +245,7 @@ private ISmartTokenFormatter CreateSmartTokenFormatter(OptionSet optionSet, IEnu
}
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var formatter = new SmartTokenFormatter(document.Project.Solution.Workspace.Options, formattingRules, (CompilationUnitSyntax)root);
var formatter = new SmartTokenFormatter(document.Options, formattingRules, (CompilationUnitSyntax)root);
var changes = formatter.FormatRange(document.Project.Solution.Workspace, tokenRange.Value.Item1, tokenRange.Value.Item2, cancellationToken);
return changes;
......
......@@ -99,7 +99,7 @@ public Task<IList<TextChange>> FormatTokenAsync(Workspace workspace, SyntaxToken
var smartTokenformattingRules = (new SmartTokenFormattingRule()).Concat(_formattingRules);
var adjustedStartPosition = previousToken.SpanStart;
var indentStyle = workspace.Options.GetOption(FormattingOptions.SmartIndent, LanguageNames.CSharp);
var indentStyle = _optionSet.GetOption(FormattingOptions.SmartIndent, LanguageNames.CSharp);
if (token.IsKind(SyntaxKind.OpenBraceToken) && token.IsFirstTokenOnLine(token.SyntaxTree.GetText()) && indentStyle != FormattingOptions.IndentStyle.Smart)
{
adjustedStartPosition = token.SpanStart;
......
......@@ -111,9 +111,8 @@ protected async Task NotSupported_ExtractMethodAsync(string codeWithMarker)
var document = workspace.CurrentSolution.GetDocument(testDocument.Id);
Assert.NotNull(document);
var options = document.Project.Solution.Workspace.Options
.WithChangedOption(ExtractMethodOptions.AllowMovingDeclaration, document.Project.Language, allowMovingDeclaration)
.WithChangedOption(ExtractMethodOptions.DontPutOutOrRefOnStruct, document.Project.Language, dontPutOutOrRefOnStruct);
var options = document.Options.WithChangedOption(ExtractMethodOptions.AllowMovingDeclaration, document.Project.Language, allowMovingDeclaration)
.WithChangedOption(ExtractMethodOptions.DontPutOutOrRefOnStruct, document.Project.Language, dontPutOutOrRefOnStruct);
var semanticDocument = await SemanticDocument.CreateAsync(document, CancellationToken.None);
var validator = new CSharpSelectionValidator(semanticDocument, testDocument.SelectedSpans.Single(), options);
......@@ -145,8 +144,7 @@ protected async Task TestSelectionAsync(string codeWithMarker, bool expectedFail
var document = workspace.CurrentSolution.GetDocument(testDocument.Id);
Assert.NotNull(document);
var options = document.Project.Solution.Workspace.Options
.WithChangedOption(ExtractMethodOptions.AllowMovingDeclaration, document.Project.Language, true);
var options = document.Options.WithChangedOption(ExtractMethodOptions.AllowMovingDeclaration, document.Project.Language, true);
var semanticDocument = await SemanticDocument.CreateAsync(document, CancellationToken.None);
var validator = new CSharpSelectionValidator(semanticDocument, namedSpans["b"].Single(), options);
......@@ -172,8 +170,7 @@ protected async Task IterateAllAsync(string code)
var root = await document.GetSyntaxRootAsync();
var iterator = root.DescendantNodesAndSelf().Cast<SyntaxNode>();
var options = document.Project.Solution.Workspace.Options
.WithChangedOption(ExtractMethodOptions.AllowMovingDeclaration, document.Project.Language, true);
var options = document.Options.WithChangedOption(ExtractMethodOptions.AllowMovingDeclaration, document.Project.Language, true);
foreach (var node in iterator)
{
......
......@@ -75,7 +75,7 @@ private static async Task TokenFormatWorkerAsync(TestWorkspace workspace, ITextB
var rules = formattingRuleProvider.CreateRule(document, position).Concat(Formatter.GetDefaultFormattingRules(document));
var formatter = new SmartTokenFormatter(workspace.Options, rules, root);
var formatter = new SmartTokenFormatter(document.Options, rules, root);
var changes = await formatter.FormatTokenAsync(workspace, token, CancellationToken.None);
ApplyChanges(buffer, changes);
......
......@@ -1365,7 +1365,7 @@ void Main(object o)
Assert.True(
CSharpIndentationService.ShouldUseSmartTokenFormatterInsteadOfIndenter(
Formatter.GetDefaultFormattingRules(workspace, root.Language),
root, line, workspace.Options, CancellationToken.None));
root, line, document.Options, CancellationToken.None));
var actualIndentation = await GetSmartTokenFormatterIndentationWorkerAsync(workspace, buffer, indentationLine, ch);
Assert.Equal(expectedIndentation.Value, actualIndentation);
......@@ -1392,7 +1392,7 @@ void Main(object o)
Assert.False(
CSharpIndentationService.ShouldUseSmartTokenFormatterInsteadOfIndenter(
Formatter.GetDefaultFormattingRules(workspace, root.Language),
root, line, workspace.Options, CancellationToken.None));
root, line, document.Options, CancellationToken.None));
await TestIndentationAsync(indentationLine, expectedIndentation, workspace);
}
......
......@@ -78,7 +78,7 @@ public void ExecuteCommand(AutomaticLineEnderCommandArgs args, Action nextHandle
}
// feature off
if (!document.Project.Solution.Workspace.Options.GetOption(InternalFeatureOnOffOptions.AutomaticLineEnder))
if (!document.Options.GetOption(InternalFeatureOnOffOptions.AutomaticLineEnder))
{
NextAction(operations, nextHandler);
return;
......
......@@ -102,7 +102,7 @@ public void NavigateTo()
if (document != null)
{
var navigator = _workspace.Services.GetService<IDocumentNavigationService>();
var options = _workspace.Options.WithChangedOption(NavigationOptions.PreferProvisionalTab, true);
var options = document.Options.WithChangedOption(NavigationOptions.PreferProvisionalTab, true);
navigator.TryNavigateToSpan(_workspace, document.Id, _span, options);
}
}
......
......@@ -127,15 +127,14 @@ public void ExecuteCommand(ExtractMethodCommandArgs args, Action nextHandler)
return false;
}
var options = document.Project.Solution.Workspace.Options;
var result = ExtractMethodService.ExtractMethodAsync(
document, spans.Single().Span.ToTextSpan(), options, cancellationToken).WaitAndGetResult(cancellationToken);
document, spans.Single().Span.ToTextSpan(), cancellationToken: cancellationToken).WaitAndGetResult(cancellationToken);
Contract.ThrowIfNull(result);
if (!result.Succeeded && !result.SucceededWithSuggestion)
{
// if it failed due to out/ref parameter in async method, try it with different option
var newResult = TryWithoutMakingValueTypesRef(document, spans, options, result, cancellationToken);
var newResult = TryWithoutMakingValueTypesRef(document, spans, result, cancellationToken);
if (newResult != null)
{
var notificationService = document.Project.Solution.Workspace.Services.GetService<INotificationService>();
......@@ -191,7 +190,7 @@ private bool TryNotifyFailureToUser(Document document, ExtractMethodResult resul
var notificationService = document.Project.Solution.Workspace.Services.GetService<INotificationService>();
// see whether we will allow best effort extraction and if it is possible.
if (!document.Project.Solution.Workspace.Options.GetOption(ExtractMethodOptions.AllowBestEffort, document.Project.Language) ||
if (!document.Options.GetOption(ExtractMethodOptions.AllowBestEffort) ||
!result.Status.HasBestEffort() || result.Document == null)
{
if (notificationService != null)
......@@ -224,8 +223,10 @@ private bool TryNotifyFailureToUser(Document document, ExtractMethodResult resul
}
private static ExtractMethodResult TryWithoutMakingValueTypesRef(
Document document, NormalizedSnapshotSpanCollection spans, OptionSet options, ExtractMethodResult result, CancellationToken cancellationToken)
Document document, NormalizedSnapshotSpanCollection spans, ExtractMethodResult result, CancellationToken cancellationToken)
{
OptionSet options = document.Options;
if (options.GetOption(ExtractMethodOptions.DontPutOutOrRefOnStruct, document.Project.Language) || !result.Reasons.IsSingle())
{
return null;
......
......@@ -45,7 +45,7 @@ internal abstract class AbstractSmartTokenFormatterCommandHandler :
protected bool FormatToken(ITextView view, Document document, SyntaxToken token, IEnumerable<IFormattingRule> formattingRules, CancellationToken cancellationToken)
{
var root = document.GetSyntaxRootAsync(cancellationToken).WaitAndGetResult(cancellationToken);
var formatter = CreateSmartTokenFormatter(document.Project.Solution.Workspace.Options, formattingRules, root);
var formatter = CreateSmartTokenFormatter(document.Options, formattingRules, root);
var changes = formatter.FormatTokenAsync(document.Project.Solution.Workspace, token, cancellationToken).WaitAndGetResult(cancellationToken);
if (changes.Count == 0)
{
......@@ -226,14 +226,14 @@ private static void ReadjustIndentation(ITextView view, ITextBuffer subjectBuffe
return;
}
var options = document.Project.Solution.Workspace.Options;
var options = document.Options;
// and then, insert the text
document.Project.Solution.Workspace.ApplyTextChanges(document.Id,
new TextChange(
new TextSpan(
lineInSubjectBuffer.Start.Position, firstNonWhitespaceIndex),
indentation.CreateIndentationString(options.GetOption(FormattingOptions.UseTabs, document.Project.Language), options.GetOption(FormattingOptions.TabSize, document.Project.Language))),
indentation.CreateIndentationString(options.GetOption(FormattingOptions.UseTabs), options.GetOption(FormattingOptions.TabSize))),
CancellationToken.None);
}
......@@ -296,7 +296,7 @@ private bool TryFormatUsingTokenFormatter(ITextView view, ITextBuffer subjectBuf
var position = view.GetCaretPoint(subjectBuffer).Value;
var line = position.GetContainingLine();
var root = document.GetSyntaxRootAsync(cancellationToken).WaitAndGetResult(cancellationToken);
var options = document.Project.Solution.Workspace.Options;
var options = document.Options;
if (!UseSmartTokenFormatter(root, line, formattingRules, options, cancellationToken))
{
return false;
......
......@@ -64,7 +64,7 @@ internal static class GoToDefinitionHelpers
symbol = ((IMethodSymbol)symbol).PartialImplementationPart ?? symbol;
}
var options = project.Solution.Workspace.Options;
var options = project.Solution.Options;
var preferredSourceLocations = NavigableItemFactory.GetPreferredSourceLocations(solution, symbol).ToArray();
var title = NavigableItemFactory.GetSymbolDisplayString(project, symbol);
......@@ -76,7 +76,7 @@ internal static class GoToDefinitionHelpers
var externalSourceDefinitions = FindExternalDefinitionsAsync(symbol, project, externalDefinitionProviders, cancellationToken).WaitAndGetResult(cancellationToken).ToImmutableArray();
if (externalSourceDefinitions.Length > 0)
{
return TryGoToDefinition(externalSourceDefinitions, title, project.Solution.Workspace.Options, presenters, throwOnHiddenDefinition);
return TryGoToDefinition(externalSourceDefinitions, title, options, presenters, throwOnHiddenDefinition);
}
}
......@@ -93,7 +93,7 @@ internal static class GoToDefinitionHelpers
}
var navigableItems = preferredSourceLocations.Select(location => NavigableItemFactory.GetItemFromSymbolLocation(solution, symbol, location)).ToImmutableArray();
return TryGoToDefinition(navigableItems, title, project.Solution.Workspace.Options, presenters, throwOnHiddenDefinition);
return TryGoToDefinition(navigableItems, title, options, presenters, throwOnHiddenDefinition);
}
private static bool TryGoToDefinition(
......
......@@ -61,8 +61,7 @@ protected override async Task ProduceTagsAsync(TaggerContext<KeywordHighlightTag
return;
}
var options = document.Project.Solution.Workspace.Options;
if (!options.GetOption(FeatureOnOffOptions.KeywordHighlighting, document.Project.Language))
if (!document.Options.GetOption(FeatureOnOffOptions.KeywordHighlighting))
{
return;
}
......
......@@ -54,8 +54,7 @@ protected override async Task ProduceTagsAsync(TaggerContext<LineSeparatorTag> c
return;
}
var options = document.Project.Solution.Workspace.Options;
if (!options.GetOption(FeatureOnOffOptions.LineSeparator, document.Project.Language))
if (!document.Options.GetOption(FeatureOnOffOptions.LineSeparator))
{
return;
}
......
......@@ -49,7 +49,7 @@ protected override Task<IEnumerable<CodeActionOperation>> ComputeOperationsAsync
protected override async Task<IEnumerable<CodeActionOperation>> ComputePreviewOperationsAsync(CancellationToken cancellationToken)
{
if (!_document.Project.Solution.Workspace.Options.GetOption(FeatureOnOffOptions.RenameTrackingPreview, _document.Project.Language) ||
if (!_document.Options.GetOption(FeatureOnOffOptions.RenameTrackingPreview) ||
!TryInitializeRenameTrackingCommitter(cancellationToken))
{
return await SpecializedTasks.EmptyEnumerable<CodeActionOperation>().ConfigureAwait(false);
......
......@@ -42,15 +42,14 @@ private IEnumerable<IFormattingRule> GetFormattingRules(Document document, int p
var lineToBeIndented = textSnapshot.GetLineFromLineNumber(lineNumber);
var formattingRules = GetFormattingRules(document, lineToBeIndented.Start);
var optionSet = document.Project.Solution.Workspace.Options;
// enter on a token case.
if (ShouldUseSmartTokenFormatterInsteadOfIndenter(formattingRules, root, lineToBeIndented, optionSet, cancellationToken))
if (ShouldUseSmartTokenFormatterInsteadOfIndenter(formattingRules, root, lineToBeIndented, document.Options, cancellationToken))
{
return null;
}
var indenter = await GetIndenterAsync(document, lineToBeIndented, formattingRules, optionSet, cancellationToken).ConfigureAwait(false);
var indenter = await GetIndenterAsync(document, lineToBeIndented, formattingRules, document.Options, cancellationToken).ConfigureAwait(false);
return indenter.GetDesiredIndentation();
}
......
......@@ -486,7 +486,7 @@ private static SuggestedActionSetPriority GetSuggestedActionSetPriority(CodeActi
this.AssertIsForeground();
if (workspace.Options.GetOption(EditorComponentOnOffOptions.CodeRefactorings) &&
if (document.Options.GetOption(EditorComponentOnOffOptions.CodeRefactorings) &&
_owner._codeRefactoringService != null &&
supportsFeatureService.SupportsRefactorings(document) &&
requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.Refactoring))
......@@ -622,7 +622,7 @@ public async Task<bool> HasSuggestedActionsAsync(ISuggestedActionCategorySet req
SnapshotSpan range,
CancellationToken cancellationToken)
{
if (document.Project.Solution.Workspace.Options.GetOption(EditorComponentOnOffOptions.CodeRefactorings) &&
if (document.Options.GetOption(EditorComponentOnOffOptions.CodeRefactorings) &&
provider._codeRefactoringService != null &&
supportsFeatureService.SupportsRefactorings(document) &&
requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.Refactoring))
......
......@@ -49,7 +49,7 @@ public async Task AnalyzeSyntaxAsync(Document document, CancellationToken cancel
// but, can be called concurrently for different documents in future if we choose to.
Contract.ThrowIfFalse(document.IsFromPrimaryBranch());
if (!document.Project.Solution.Workspace.Options.GetOption(InternalFeatureOnOffOptions.TodoComments))
if (!document.Options.GetOption(InternalFeatureOnOffOptions.TodoComments))
{
return;
}
......@@ -76,7 +76,7 @@ public async Task AnalyzeSyntaxAsync(Document document, CancellationToken cancel
return;
}
var comments = await service.GetTodoCommentsAsync(document, _todoCommentTokens.GetTokens(_workspace), cancellationToken).ConfigureAwait(false);
var comments = await service.GetTodoCommentsAsync(document, _todoCommentTokens.GetTokens(document), cancellationToken).ConfigureAwait(false);
var items = await CreateItemsAsync(document, comments, cancellationToken).ConfigureAwait(false);
var data = new Data(textVersion, syntaxVersion, items);
......
......@@ -71,9 +71,9 @@ public TokenInfo(string optionText, ImmutableArray<TodoCommentDescriptor> tokens
private TokenInfo _lastTokenInfo;
public ImmutableArray<TodoCommentDescriptor> GetTokens(Workspace workspace)
public ImmutableArray<TodoCommentDescriptor> GetTokens(Document document)
{
var optionText = workspace.Options.GetOption(TodoCommentOptions.TokenList);
var optionText = document.Options.GetOption(TodoCommentOptions.TokenList);
var lastInfo = _lastTokenInfo;
if (lastInfo != null && lastInfo.OptionText == optionText)
......
......@@ -12,25 +12,13 @@ namespace Microsoft.CodeAnalysis.Editor.Shared.Extensions
{
internal static partial class ITextBufferExtensions
{
internal static OptionSet TryGetOptions(this ITextBuffer textBuffer)
{
Workspace workspace;
if (Workspace.TryGetWorkspace(textBuffer.AsTextContainer(), out workspace))
{
return workspace.Options;
}
return null;
}
internal static T GetOption<T>(this ITextBuffer buffer, Option<T> option)
{
var options = TryGetOptions(buffer);
var document = buffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
if (options != null)
if (document != null)
{
return options.GetOption(option);
return document.Options.GetOption(option);
}
return option.DefaultValue;
......@@ -41,14 +29,14 @@ internal static T GetOption<T>(this ITextBuffer buffer, PerLanguageOption<T> opt
// Add a FailFast to help diagnose 984249. Hopefully this will let us know what the issue is.
try
{
Workspace workspace;
if (!Workspace.TryGetWorkspace(buffer.AsTextContainer(), out workspace))
var document = buffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document != null)
{
return option.DefaultValue;
return document.Options.GetOption(option);
}
var language = workspace.Services.GetLanguageServices(buffer).Language;
return workspace.Options.GetOption(option, language);
return option.DefaultValue;
}
catch (Exception e) when (FatalError.Report(e))
{
......
......@@ -65,7 +65,7 @@ internal static CompletionHelper GetCompletionHelper(Document document)
internal static async Task<CompletionContext> GetCompletionListContextAsync(CompletionProvider provider, Document document, int position, CompletionTrigger triggerInfo, OptionSet options = null)
{
options = options ?? document.Project.Solution.Workspace.Options;
options = options ?? document.Options;
var service = document.Project.LanguageServices.GetService<CompletionService>();
var text = await document.GetTextAsync();
var span = service.GetDefaultItemSpan(text, position);
......
......@@ -45,7 +45,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.LineCommit
Return
End If
If Not (isExplicitFormat OrElse document.Project.Solution.Workspace.Options.GetOption(FeatureOnOffOptions.PrettyListing, LanguageNames.VisualBasic)) Then
If Not (isExplicitFormat OrElse document.Options.GetOption(FeatureOnOffOptions.PrettyListing)) Then
Return
End If
......@@ -228,13 +228,12 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.LineCommit
Dim token = vbTree.GetRoot(cancellationToken).FindToken(Math.Min(endPosition, syntaxTree.GetRoot(cancellationToken).FullSpan.End))
Dim node = token.Parent
Dim optionSet = document.Project.Solution.Workspace.Options
' collect all indent operation
Dim operations = New List(Of IndentBlockOperation)()
While node IsNot Nothing
operations.AddRange(FormattingOperations.GetIndentBlockOperations(
Formatter.GetDefaultFormattingRules(document), node, lastToken:=Nothing, optionSet:=optionSet))
Formatter.GetDefaultFormattingRules(document), node, lastToken:=Nothing, optionSet:=document.Options))
node = node.Parent
End While
......
......@@ -43,7 +43,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.NavigationBar
Return Formatter.FormatAsync(newDocument,
Formatter.Annotation,
options:=newDocument.Project.Solution.Workspace.Options,
options:=newDocument.Options,
cancellationToken:=cancellationToken,
rules:=formatterRules).WaitAndGetResult(cancellationToken)
End Function
......
......@@ -511,7 +511,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.NavigationBar
Dim newDocument = generateCodeItem.GetGeneratedDocumentAsync(document, cancellationToken).WaitAndGetResult(cancellationToken)
Dim generatedTree = newDocument.GetSyntaxRootAsync(cancellationToken).WaitAndGetResult(cancellationToken)
Dim generatedNode = generatedTree.GetAnnotatedNodes(AbstractGenerateCodeItem.GeneratedSymbolAnnotation).Single().FirstAncestorOrSelf(Of MethodBlockBaseSyntax)
Dim indentSize = document.Project.Solution.Workspace.Options.GetOption(FormattingOptions.IndentationSize, LanguageNames.VisualBasic)
Dim indentSize = newDocument.Options.GetOption(FormattingOptions.IndentationSize)
Dim navigationPoint = NavigationPointHelpers.GetNavigationPoint(generatedTree.GetText(text.Encoding), indentSize, generatedNode)
Using transaction = New CaretPreservingEditTransaction(VBEditorResources.GenerateMember, textView, _textUndoHistoryRegistry, _editorOperationsFactoryService)
......
......@@ -101,7 +101,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.Utilities.CommandHandlers
Return False
End If
If Not document.Project.Solution.Workspace.Options.GetOption(FeatureOnOffOptions.AutomaticInsertionOfAbstractOrInterfaceMembers, LanguageNames.VisualBasic) Then
If Not document.Options.GetOption(FeatureOnOffOptions.AutomaticInsertionOfAbstractOrInterfaceMembers) Then
Return False
End If
......
......@@ -115,7 +115,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Completion.Complet
Dim item = completionList.Items.First(Function(i) i.DisplayText.StartsWith(textTypedSoFar))
Dim helper = CompletionHelper.GetHelper(document)
Assert.Equal(expected, helper.SendEnterThroughToEditor(item, textTypedSoFar, workspace.Options))
Assert.Equal(expected, helper.SendEnterThroughToEditor(item, textTypedSoFar, document.Options))
End Using
End Function
......
......@@ -97,9 +97,8 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.ExtractMethod
Dim document = workspace.CurrentSolution.GetDocument(testDocument.Id)
Assert.NotNull(document)
Dim options = document.Project.Solution.Workspace.Options.
WithChangedOption(ExtractMethodOptions.AllowMovingDeclaration, document.Project.Language, allowMovingDeclaration).
WithChangedOption(ExtractMethodOptions.DontPutOutOrRefOnStruct, document.Project.Language, dontPutOutOrRefOnStruct)
Dim options = document.Options.WithChangedOption(ExtractMethodOptions.AllowMovingDeclaration, document.Project.Language, allowMovingDeclaration) _
.WithChangedOption(ExtractMethodOptions.DontPutOutOrRefOnStruct, document.Project.Language, dontPutOutOrRefOnStruct)
Dim sdocument = Await SemanticDocument.CreateAsync(document, CancellationToken.None)
Dim validator = New VisualBasicSelectionValidator(sdocument, snapshotSpan.Span.ToTextSpan(), options)
......@@ -130,7 +129,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.ExtractMethod
Dim document = workspace.CurrentSolution.GetDocument(workspace.Documents.First().Id)
Assert.NotNull(document)
Dim options = document.Project.Solution.Workspace.Options.WithChangedOption(ExtractMethodOptions.AllowMovingDeclaration, document.Project.Language, True)
Dim options = document.Options.WithChangedOption(ExtractMethodOptions.AllowMovingDeclaration, document.Project.Language, True)
Dim sdocument = Await SemanticDocument.CreateAsync(document, CancellationToken.None)
Dim validator = New VisualBasicSelectionValidator(sdocument, namedSpans("b").Single(), options)
Dim result = Await validator.GetValidSelectionAsync(CancellationToken.None)
......@@ -164,8 +163,7 @@ End Class</text>
Dim root = Await document.GetSyntaxRootAsync()
Dim iterator = root.DescendantNodesAndSelf()
Dim options = document.Project.Solution.Workspace.Options _
.WithChangedOption(ExtractMethodOptions.AllowMovingDeclaration, document.Project.Language, True)
Dim options = document.Options.WithChangedOption(ExtractMethodOptions.AllowMovingDeclaration, document.Project.Language, True)
For Each node In iterator
Try
......
......@@ -38,7 +38,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Formatting
Dim changes = Formatter.GetFormattedTextChanges(
Await syntaxTree.GetRootAsync(),
workspace.Documents.First(Function(d) d.SelectedSpans.Any()).SelectedSpans,
workspace, workspace.Options, rules, CancellationToken.None)
workspace, document.Options, rules, CancellationToken.None)
AssertResult(expected, clonedBuffer, changes)
End Using
End Function
......
......@@ -195,7 +195,7 @@ End Class
Assert.True(VisualBasicIndentationService.ShouldUseSmartTokenFormatterInsteadOfIndenter(formattingRules, root, line, workspace.Options, Nothing, ignoreMissingToken))
Dim smartFormatter = New SmartTokenFormatter(workspace.Options, formattingRules, root)
Dim smartFormatter = New SmartTokenFormatter(document.Options, formattingRules, root)
Dim changes = Await smartFormatter.FormatTokenAsync(workspace, token, Nothing)
Using edit = buffer.CreateEdit()
......
......@@ -481,8 +481,7 @@ protected override string GetDescription(IReadOnlyList<string> nameParts)
.Single();
newRoot = newRoot.TrackNodes(newUsing);
var documentWithSyntaxRoot = document.WithSyntaxRoot(newRoot);
var options = document.Project.Solution.Workspace.Options;
var simplifiedDocument = await Simplifier.ReduceAsync(documentWithSyntaxRoot, newUsing.Span, options, cancellationToken).ConfigureAwait(false);
var simplifiedDocument = await Simplifier.ReduceAsync(documentWithSyntaxRoot, newUsing.Span, cancellationToken: cancellationToken).ConfigureAwait(false);
newRoot = (CompilationUnitSyntax)await simplifiedDocument.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var simplifiedUsing = newRoot.GetCurrentNode(newUsing);
......
......@@ -13,7 +13,7 @@ private class RemoveUnnecessaryCastFixAllProvider : BatchSimplificationFixAllPro
{
internal static new readonly RemoveUnnecessaryCastFixAllProvider Instance = new RemoveUnnecessaryCastFixAllProvider();
protected override SyntaxNode GetNodeToSimplify(SyntaxNode root, SemanticModel model, Diagnostic diagnostic, Workspace workspace, out string codeActionId, CancellationToken cancellationToken)
protected override SyntaxNode GetNodeToSimplify(SyntaxNode root, SemanticModel model, Diagnostic diagnostic, Document document, out string codeActionId, CancellationToken cancellationToken)
{
codeActionId = null;
return GetCastNode(root, model, diagnostic.Location.SourceSpan, cancellationToken);
......
......@@ -11,11 +11,11 @@ private class SimplifyTypeNamesFixAllProvider : BatchSimplificationFixAllProvide
{
internal static new readonly SimplifyTypeNamesFixAllProvider Instance = new SimplifyTypeNamesFixAllProvider();
protected override SyntaxNode GetNodeToSimplify(SyntaxNode root, SemanticModel model, Diagnostic diagnostic, Workspace workspace, out string codeActionId, CancellationToken cancellationToken)
protected override SyntaxNode GetNodeToSimplify(SyntaxNode root, SemanticModel model, Diagnostic diagnostic, Document document, out string codeActionId, CancellationToken cancellationToken)
{
codeActionId = null;
string diagnosticId;
var node = SimplifyTypeNamesCodeFixProvider.GetNodeToSimplify(root, model, diagnostic.Location.SourceSpan, workspace.Options, out diagnosticId, cancellationToken);
var node = SimplifyTypeNamesCodeFixProvider.GetNodeToSimplify(root, model, diagnostic.Location.SourceSpan, document.Options, out diagnosticId, cancellationToken);
if (node != null)
{
codeActionId = GetCodeActionId(diagnosticId, node.ToString());
......
......@@ -65,9 +65,8 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var model = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var optionSet = document.Project.Solution.Workspace.Options;
string diagnosticId;
var node = GetNodeToSimplify(root, model, span, optionSet, out diagnosticId, cancellationToken);
var node = GetNodeToSimplify(root, model, span, document.Options, out diagnosticId, cancellationToken);
if (node == null)
{
return;
......
......@@ -820,8 +820,6 @@ internal override async Task<Solution> TryAddUsingsOrImportToDocumentAsync(Solut
return updatedSolution;
}
var placeSystemNamespaceFirst = document.Project.Solution.Workspace.Options.GetOption(OrganizerOptions.PlaceSystemNamespaceFirst, document.Project.Language);
SyntaxNode root = null;
if (modifiedRoot == null)
{
......@@ -851,6 +849,7 @@ internal override async Task<Solution> TryAddUsingsOrImportToDocumentAsync(Solut
return updatedSolution;
}
var placeSystemNamespaceFirst = document.Options.GetOption(OrganizerOptions.PlaceSystemNamespaceFirst);
var addedCompilationRoot = compilationRoot.AddUsingDirectives(new[] { usingDirective }, placeSystemNamespaceFirst, Formatter.Annotation);
updatedSolution = updatedSolution.WithDocumentSyntaxRoot(document.Id, addedCompilationRoot, PreservationMode.PreserveIdentity);
}
......
......@@ -30,8 +30,6 @@ internal partial class CSharpIntroduceVariableService
bool isConstant,
CancellationToken cancellationToken)
{
var options = document.Project.Solution.Workspace.Options;
var newLocalNameToken = GenerateUniqueLocalName(document, expression, isConstant, cancellationToken);
var newLocalName = SyntaxFactory.IdentifierName(newLocalNameToken);
......@@ -42,7 +40,7 @@ internal partial class CSharpIntroduceVariableService
var declarationStatement = SyntaxFactory.LocalDeclarationStatement(
modifiers,
SyntaxFactory.VariableDeclaration(
this.GetTypeSyntax(document, expression, isConstant, options, cancellationToken),
this.GetTypeSyntax(document, expression, isConstant, cancellationToken),
SyntaxFactory.SingletonSeparatedList(SyntaxFactory.VariableDeclarator(
newLocalNameToken.WithAdditionalAnnotations(RenameAnnotation.Create()),
null,
......@@ -120,7 +118,7 @@ private SyntaxNode GetParentLambda(ExpressionSyntax expression, ISet<SyntaxNode>
return null;
}
private TypeSyntax GetTypeSyntax(SemanticDocument document, ExpressionSyntax expression, bool isConstant, OptionSet options, CancellationToken cancellationToken)
private TypeSyntax GetTypeSyntax(SemanticDocument document, ExpressionSyntax expression, bool isConstant, CancellationToken cancellationToken)
{
var typeSymbol = GetTypeSymbol(document, expression, cancellationToken);
if (typeSymbol.ContainsAnonymousType())
......@@ -130,7 +128,7 @@ private TypeSyntax GetTypeSyntax(SemanticDocument document, ExpressionSyntax exp
if (!isConstant &&
CanUseVar(typeSymbol) &&
TypeStyleHelper.IsImplicitTypePreferred(expression, document.SemanticModel, options, cancellationToken))
TypeStyleHelper.IsImplicitTypePreferred(expression, document.SemanticModel, document.Document.Options, cancellationToken))
{
return SyntaxFactory.IdentifierName("var");
}
......
......@@ -84,7 +84,7 @@ private Task<SyntaxNode> FormatResultAsync(Document document, CompilationUnitSyn
{
var spans = new List<TextSpan>();
AddFormattingSpans(newRoot, spans, cancellationToken);
return Formatter.FormatAsync(newRoot, spans, document.Project.Solution.Workspace, document.Project.Solution.Workspace.Options, cancellationToken: cancellationToken);
return Formatter.FormatAsync(newRoot, spans, document.Project.Solution.Workspace, document.Options, cancellationToken: cancellationToken);
}
private void AddFormattingSpans(
......
......@@ -79,9 +79,8 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
return;
}
var options = document.Project.Solution.Workspace.Options;
var placeSystemNamespaceFirst = options.GetOption(
OrganizerOptions.PlaceSystemNamespaceFirst, document.Project.Language);
var placeSystemNamespaceFirst = document.Options.GetOption(
OrganizerOptions.PlaceSystemNamespaceFirst);
using (Logger.LogBlock(FunctionId.Refactoring_AddImport, cancellationToken))
{
......@@ -502,4 +501,4 @@ internal override bool IsApplicable(Workspace workspace)
}
}
}
}
\ No newline at end of file
}
......@@ -49,7 +49,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
solution,
symbol,
fixedName,
solution.Workspace.Options,
document.Options,
c).ConfigureAwait(false),
nameof(AbstractNamingStyleCodeFixProvider)),
diagnostic);
......
......@@ -59,17 +59,15 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
TextSpan textSpan,
CancellationToken cancellationToken)
{
var options = document.Project.Solution.Workspace.Options;
var result = await ExtractMethodService.ExtractMethodAsync(
document,
textSpan,
options,
cancellationToken).ConfigureAwait(false);
cancellationToken: cancellationToken).ConfigureAwait(false);
Contract.ThrowIfNull(result);
if (result.Succeeded || result.SucceededWithSuggestion)
{
var description = options.GetOption(ExtractMethodOptions.AllowMovingDeclaration, document.Project.Language) ?
var description = document.Options.GetOption(ExtractMethodOptions.AllowMovingDeclaration) ?
FeaturesResources.ExtractMethodLocal : FeaturesResources.ExtractMethod;
var codeAction = new MyCodeAction(description, (c) => AddRenameAnnotationAsync(result.Document, result.InvocationNameToken, c));
......
......@@ -172,7 +172,7 @@ internal protected CompletionProvider GetProvider(CompletionItem item)
var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
var defaultItemSpan = this.GetDefaultItemSpan(text, caretPosition);
options = options ?? document.Project.Solution.Workspace.Options;
options = options ?? document.Options;
var providers = GetProviders(roles, trigger);
var completionProviderToIndex = GetCompletionProviderToIndex(providers);
......
......@@ -143,7 +143,7 @@ private Task ClearOnlyDocumentStates(Document document)
private bool CheckOptions(Project project, bool forceAnalysis)
{
var workspace = project.Solution.Workspace;
if (ServiceFeatureOnOffOptions.IsClosedFileDiagnosticsEnabled(workspace, project.Language) &&
if (ServiceFeatureOnOffOptions.IsClosedFileDiagnosticsEnabled(project) &&
workspace.Options.GetOption(RuntimeOptions.FullSolutionAnalysis))
{
return true;
......@@ -169,7 +169,7 @@ private bool CheckOptions(Project project, bool forceAnalysis)
Func<Exception, bool> analyzerExceptionFilter = ex =>
{
if (project.Solution.Workspace.Options.GetOption(InternalDiagnosticsOptions.CrashOnAnalyzerException))
if (project.Solution.Options.GetOption(InternalDiagnosticsOptions.CrashOnAnalyzerException))
{
// if option is on, crash the host to get crash dump.
FatalError.ReportUnlessCanceled(ex);
......
......@@ -404,16 +404,13 @@ private async Task UpdateAnalyzerTelemetryDataAsync(CompilationWithAnalyzers ana
private static async Task<bool> FullAnalysisEnabledAsync(Project project, bool ignoreFullAnalysisOptions, CancellationToken cancellationToken)
{
var workspace = project.Solution.Workspace;
var language = project.Language;
if (ignoreFullAnalysisOptions)
{
return await project.HasSuccessfullyLoadedAsync(cancellationToken).ConfigureAwait(false);
}
if (!ServiceFeatureOnOffOptions.IsClosedFileDiagnosticsEnabled(workspace, language) ||
!workspace.Options.GetOption(RuntimeOptions.FullSolutionAnalysis))
if (!ServiceFeatureOnOffOptions.IsClosedFileDiagnosticsEnabled(project) ||
!project.Solution.Options.GetOption(RuntimeOptions.FullSolutionAnalysis))
{
return false;
}
......
......@@ -225,7 +225,7 @@ public async Task MergeAsync(ActiveFileState state, Document document)
var semantic = state.GetAnalysisData(AnalysisKind.Semantic);
var project = document.Project;
var fullAnalysis = ServiceFeatureOnOffOptions.IsClosedFileDiagnosticsEnabled(project.Solution.Workspace, project.Language);
var fullAnalysis = ServiceFeatureOnOffOptions.IsClosedFileDiagnosticsEnabled(project);
// keep from build flag if full analysis is off
var fromBuild = fullAnalysis ? false : lastResult.FromBuild;
......
......@@ -228,7 +228,7 @@ private IEnumerable<StateSet> GetStateSetsForFullSolutionAnalysis(IEnumerable<St
// if full analysis is off, remove state that is from build.
// this will make sure diagnostics (converted from build to live) from build will never be cleared
// until next build.
if (!ServiceFeatureOnOffOptions.IsClosedFileDiagnosticsEnabled(project.Solution.Workspace, project.Language))
if (!ServiceFeatureOnOffOptions.IsClosedFileDiagnosticsEnabled(project))
{
stateSets = stateSets.Where(s => !s.FromBuild(project.Id));
}
......
......@@ -239,7 +239,7 @@ private async Task<Result> EncapsulateFieldAsync(IFieldSymbol field, Document do
var constructorSyntaxes = GetConstructorNodes(field.ContainingType).ToSet();
if (finalFieldName != field.Name && constructorSyntaxes.Count > 0)
{
solution = await Renamer.RenameSymbolAsync(solution, field, finalFieldName, solution.Workspace.Options,
solution = await Renamer.RenameSymbolAsync(solution, field, finalFieldName, solution.Options,
location => constructorSyntaxes.Any(c => c.Span.IntersectsWith(location.SourceSpan)), cancellationToken: cancellationToken).ConfigureAwait(false);
document = solution.GetDocument(document.Id);
......@@ -249,13 +249,13 @@ private async Task<Result> EncapsulateFieldAsync(IFieldSymbol field, Document do
}
// Outside the constructor we want to rename references to the field to final property name.
return await Renamer.RenameSymbolAsync(solution, field, generatedPropertyName, solution.Workspace.Options,
return await Renamer.RenameSymbolAsync(solution, field, generatedPropertyName, solution.Options,
location => !constructorSyntaxes.Any(c => c.Span.IntersectsWith(location.SourceSpan)), cancellationToken: cancellationToken).ConfigureAwait(false);
}
else
{
// Just rename everything.
return await Renamer.RenameSymbolAsync(solution, field, generatedPropertyName, solution.Workspace.Options, cancellationToken).ConfigureAwait(false);
return await Renamer.RenameSymbolAsync(solution, field, generatedPropertyName, solution.Options, cancellationToken).ConfigureAwait(false);
}
}
......
......@@ -21,7 +21,7 @@ internal abstract class AbstractExtractMethodService<TValidator, TExtractor, TRe
OptionSet options,
CancellationToken cancellationToken)
{
options = options ?? document.Project.Solution.Workspace.Options;
options = options ?? document.Options;
var semanticDocument = await SemanticDocument.CreateAsync(document, cancellationToken).ConfigureAwait(false);
......
......@@ -53,7 +53,7 @@ private async Task<SyntaxNode> GetNewRoot(CancellationToken cancellationToken)
var semanticModel = await _document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
if (_service.TryConvertToLocalDeclaration(_state.LocalType, _state.IdentifierToken, _document.Project.Solution.Workspace.Options, semanticModel, cancellationToken, out newRoot))
if (_service.TryConvertToLocalDeclaration(_state.LocalType, _state.IdentifierToken, _document.Options, semanticModel, cancellationToken, out newRoot))
{
return newRoot;
}
......
......@@ -26,7 +26,6 @@ private class IntroduceVariableAllOccurrenceCodeAction : AbstractIntroduceVariab
protected override async Task<Document> PostProcessChangesAsync(Document document, CancellationToken cancellationToken)
{
var optionSet = document.Project.Solution.Workspace.Options.WithChangedOption(FormattingOptions.AllowDisjointSpanMerging, true);
document = await Simplifier.ReduceAsync(document, Simplifier.Annotation, cancellationToken: cancellationToken).ConfigureAwait(false);
document = await Formatter.FormatAsync(document, Formatter.Annotation, cancellationToken: cancellationToken).ConfigureAwait(false);
document = await CaseCorrector.CaseCorrectAsync(document, CaseCorrector.Annotation, cancellationToken).ConfigureAwait(false);
......
......@@ -65,13 +65,12 @@ private async Task<Solution> RenameThenRemoveAsyncTokenAsync(Document document,
var name = methodSymbol.Name;
var newName = name.Substring(0, name.Length - AsyncSuffix.Length);
var solution = document.Project.Solution;
var options = solution.Workspace.Options;
// Store the path to this node. That way we can find it post rename.
var syntaxPath = new SyntaxPath(node);
// Rename the method to remove the 'Async' suffix, then remove the 'async' keyword.
var newSolution = await Renamer.RenameSymbolAsync(solution, methodSymbol, newName, options, cancellationToken).ConfigureAwait(false);
var newSolution = await Renamer.RenameSymbolAsync(solution, methodSymbol, newName, solution.Options, cancellationToken).ConfigureAwait(false);
var newDocument = newSolution.GetDocument(document.Id);
var newRoot = await newDocument.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
......
......@@ -14,8 +14,7 @@ internal static class DocumentExtensions
{
public static bool ShouldHideAdvancedMembers(this Document document)
{
return document.Project.Solution.Workspace.Options
.GetOption(CompletionOptions.HideAdvancedMembers, document.Project.Language);
return document.Options.GetOption(CompletionOptions.HideAdvancedMembers);
}
public static async Task<Document> ReplaceNodeAsync<TNode>(this Document document, TNode oldNode, TNode newNode, CancellationToken cancellationToken) where TNode : SyntaxNode
......
......@@ -18,15 +18,14 @@ internal static class ServiceFeatureOnOffOptions
/// </summary>
public static readonly PerLanguageOption<bool?> ClosedFileDiagnostic = new PerLanguageOption<bool?>(OptionName, "Closed File Diagnostic", defaultValue: null);
public static bool IsClosedFileDiagnosticsEnabled(Workspace workspace, string language)
public static bool IsClosedFileDiagnosticsEnabled(Project project)
{
var optionsService = workspace.Services.GetService<IOptionService>();
return optionsService != null && IsClosedFileDiagnosticsEnabled(optionsService, language);
return IsClosedFileDiagnosticsEnabled(project.Solution.Options, project.Language);
}
public static bool IsClosedFileDiagnosticsEnabled(IOptionService optionService, string language)
public static bool IsClosedFileDiagnosticsEnabled(OptionSet options, string language)
{
var option = optionService.GetOption(ClosedFileDiagnostic, language);
var option = options.GetOption(ClosedFileDiagnostic, language);
if (!option.HasValue)
{
return language == LanguageNames.CSharp ?
......
......@@ -78,7 +78,7 @@ private async Task<Solution> ProcessResult(CodeFixContext context, Diagnostic di
var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
var solution = context.Document.Project.Solution;
var fieldLocations = await Renamer.GetRenameLocationsAsync(solution, fieldSymbol, solution.Workspace.Options, cancellationToken).ConfigureAwait(false);
var fieldLocations = await Renamer.GetRenameLocationsAsync(solution, fieldSymbol, solution.Options, cancellationToken).ConfigureAwait(false);
// First, create the updated property we want to replace the old property with
var isWrittenToOutsideOfConstructor = IsWrittenToOutsideOfConstructorOrProperty(fieldSymbol, fieldLocations, property, cancellationToken);
......
......@@ -15,7 +15,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.RemoveUnnecessaryCast
Friend Shared Shadows ReadOnly Instance As RemoveUnnecessaryCastFixAllProvider = New RemoveUnnecessaryCastFixAllProvider()
Protected Overrides Function GetNodeToSimplify(root As SyntaxNode, model As SemanticModel, diagnostic As Diagnostic, workspace As Workspace, ByRef codeActionId As String, cancellationToken As CancellationToken) As SyntaxNode
Protected Overrides Function GetNodeToSimplify(root As SyntaxNode, model As SemanticModel, diagnostic As Diagnostic, document As Document, ByRef codeActionId As String, cancellationToken As CancellationToken) As SyntaxNode
codeActionId = Nothing
Return GetCastNode(root, model, diagnostic.Location.SourceSpan, cancellationToken)
End Function
......
......@@ -13,10 +13,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.SimplifyTypeNames
Friend Shared Shadows ReadOnly Instance As SimplifyTypeNamesFixAllProvider = New SimplifyTypeNamesFixAllProvider
Protected Overrides Function GetNodeToSimplify(root As SyntaxNode, model As SemanticModel, diagnostic As Diagnostic, workspace As Workspace, ByRef codeActionId As String, cancellationToken As CancellationToken) As SyntaxNode
Protected Overrides Function GetNodeToSimplify(root As SyntaxNode, model As SemanticModel, diagnostic As Diagnostic, document As Document, ByRef codeActionId As String, cancellationToken As CancellationToken) As SyntaxNode
codeActionId = Nothing
Dim diagnosticId As String = Nothing
Dim node = SimplifyTypeNamesCodeFixProvider.GetNodeToSimplify(root, model, diagnostic.Location.SourceSpan, workspace.Options, diagnosticId, cancellationToken)
Dim node = SimplifyTypeNamesCodeFixProvider.GetNodeToSimplify(root, model, diagnostic.Location.SourceSpan, document.Options, diagnosticId, cancellationToken)
If node IsNot Nothing Then
codeActionId = GetCodeActionId(diagnosticId, node.ToString)
End If
......
......@@ -50,10 +50,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.SimplifyTypeNames
Dim cancellationToken = context.CancellationToken
Dim root = Await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(False)
Dim optionSet = document.Project.Solution.Workspace.Options
Dim model = Await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(False)
Dim diagnosticId As String = Nothing
Dim node = GetNodeToSimplify(root, model, span, optionSet, diagnosticId, cancellationToken)
Dim node = GetNodeToSimplify(root, model, span, document.Options, diagnosticId, cancellationToken)
If node Is Nothing Then
Return
End If
......
......@@ -628,7 +628,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.GenerateType
Return updatedSolution
End If
Dim placeSystemNamespaceFirst = document.Project.Solution.Workspace.Options.GetOption(OrganizerOptions.PlaceSystemNamespaceFirst, document.Project.Language)
Dim placeSystemNamespaceFirst = document.Options.GetOption(OrganizerOptions.PlaceSystemNamespaceFirst)
Dim root As SyntaxNode = Nothing
If (modifiedRoot Is Nothing) Then
root = Await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(False)
......
......@@ -152,8 +152,8 @@ public void RemoveProject(ProjectId projectId)
private bool CheckOptions(Document document)
{
if (ServiceFeatureOnOffOptions.IsClosedFileDiagnosticsEnabled(_workspace, document.Project.Language) &&
_workspace.Options.GetOption(RuntimeOptions.FullSolutionAnalysis))
if (ServiceFeatureOnOffOptions.IsClosedFileDiagnosticsEnabled(document.Project) &&
document.Options.GetOption(RuntimeOptions.FullSolutionAnalysis))
{
return true;
}
......
......@@ -174,8 +174,7 @@ private void CleanUpEndLocation(ITrackingSpan endTrackingSpan)
var document = this.SubjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document != null)
{
var options = document.Project.Solution.Workspace.Options;
var tabSize = options.GetOption(FormattingOptions.TabSize, document.Project.Language);
var tabSize = document.Options.GetOption(FormattingOptions.TabSize);
indentDepth = lineText.GetColumnFromLineOffset(lineText.Length, tabSize);
}
else
......@@ -525,8 +524,7 @@ private void AddReferencesAndImports(IVsExpansionSession pSession, CancellationT
return;
}
var options = documentWithImports.Project.Solution.Workspace.Options;
var placeSystemNamespaceFirst = options.GetOption(OrganizerOptions.PlaceSystemNamespaceFirst, documentWithImports.Project.Language);
var placeSystemNamespaceFirst = documentWithImports.Options.GetOption(OrganizerOptions.PlaceSystemNamespaceFirst);
documentWithImports = AddImports(documentWithImports, snippetNode, placeSystemNamespaceFirst, cancellationToken);
AddReferences(documentWithImports.Project, snippetNode);
}
......
......@@ -217,8 +217,13 @@ public static string GetEventHandlerMemberId(Document document, string className
var formattingRules = additionalFormattingRule.Concat(Formatter.GetDefaultFormattingRules(targetDocument));
var workspace = targetDocument.Project.Solution.Workspace;
newRoot = Formatter.FormatAsync(newRoot, Formatter.Annotation, workspace, workspace.Options, formattingRules, cancellationToken).WaitAndGetResult_Venus(cancellationToken);
newRoot = Formatter.FormatAsync(
newRoot,
Formatter.Annotation,
targetDocument.Project.Solution.Workspace,
targetDocument.Options,
formattingRules,
cancellationToken).WaitAndGetResult_Venus(cancellationToken);
var newMember = newRoot.GetAnnotatedNodesAndTokens(annotation).Single();
var newMemberText = newMember.ToFullString();
......
......@@ -548,7 +548,7 @@ public void Rename(ISymbol symbol, string newName, Solution solution)
}
// Rename symbol.
var newSolution = Renamer.RenameSymbolAsync(solution, symbol, newName, workspace.Options).WaitAndGetResult_CodeModel(CancellationToken.None);
var newSolution = Renamer.RenameSymbolAsync(solution, symbol, newName, solution.Options).WaitAndGetResult_CodeModel(CancellationToken.None);
var changedDocuments = newSolution.GetChangedDocuments(solution);
// Notify third parties of the coming rename operation and let exceptions propagate out
......
......@@ -26,7 +26,7 @@ public bool Value
{
get
{
return ServiceFeatureOnOffOptions.IsClosedFileDiagnosticsEnabled(_optionService, _languageName) &&
return ServiceFeatureOnOffOptions.IsClosedFileDiagnosticsEnabled(_optionService.GetOptions(), _languageName) &&
_optionService.GetOption(_fullSolutionAnalysis);
}
......
......@@ -47,7 +47,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options
<Obsolete("This SettingStore option has now been deprecated in favor of BasicClosedFileDiagnostics")>
Public Property ClosedFileDiagnostics As Boolean
Get
Return ServiceFeatureOnOffOptions.IsClosedFileDiagnosticsEnabled(_workspace, LanguageNames.VisualBasic)
Return ServiceFeatureOnOffOptions.IsClosedFileDiagnosticsEnabled(_workspace.Options, LanguageNames.VisualBasic)
End Get
Set(value As Boolean)
' Even though this option has been deprecated, we want to respect the setting if the user has explicitly turned off closed file diagnostics (which is the non-default value for 'ClosedFileDiagnostics').
......
......@@ -34,7 +34,7 @@ private Document GetDocument(string code)
private async Task TestAsync(string initialText, string importsAddedText, string simplifiedText, OptionSet options = null)
{
var doc = GetDocument(initialText);
options = options ?? doc.Project.Solution.Workspace.Options;
options = options ?? doc.Options;
var imported = await ImportAdder.AddImportsAsync(doc, options);
......
......@@ -37,7 +37,7 @@ internal class BatchSimplificationFixAllProvider : BatchFixAllProvider
/// <summary>
/// Get node on which to add simplifier and formatter annotation for fixing the given diagnostic.
/// </summary>
protected virtual SyntaxNode GetNodeToSimplify(SyntaxNode root, SemanticModel model, Diagnostic diagnostic, Workspace workspace, out string codeActionEquivalenceKey, CancellationToken cancellationToken)
protected virtual SyntaxNode GetNodeToSimplify(SyntaxNode root, SemanticModel model, Diagnostic diagnostic, Document document, out string codeActionEquivalenceKey, CancellationToken cancellationToken)
{
codeActionEquivalenceKey = null;
var span = diagnostic.Location.SourceSpan;
......@@ -56,7 +56,7 @@ protected virtual Task<Document> AddSimplifyAnnotationsAsync(Document document,
/// <summary>
/// By default, this property returns false and <see cref="AddSimplifierAnnotationsAsync(Document, ImmutableArray{Diagnostic}, FixAllState, CancellationToken)"/> will just add <see cref="Simplifier.Annotation"/> to each node to simplify
/// returned by <see cref="GetNodeToSimplify(SyntaxNode, SemanticModel, Diagnostic, Workspace, out string, CancellationToken)"/>.
/// returned by <see cref="GetNodeToSimplify(SyntaxNode, SemanticModel, Diagnostic, Document, out string, CancellationToken)"/>.
///
/// Override this property to return true if the fix all provider needs to add simplify annotations/fixup any of the parent nodes of the nodes to simplify.
/// This could be the case if simplifying certain nodes can enable cascaded simplifications, such as parentheses removal on parenting node.
......@@ -77,7 +77,7 @@ protected virtual Task<Document> AddSimplifyAnnotationsAsync(Document document,
foreach (var diagnostic in diagnostics)
{
string codeActionEquivalenceKey;
var node = GetNodeToSimplify(root, model, diagnostic, fixAllState.Solution.Workspace, out codeActionEquivalenceKey, cancellationToken);
var node = GetNodeToSimplify(root, model, diagnostic, document, out codeActionEquivalenceKey, cancellationToken);
if (node != null && fixAllState.CodeActionEquivalenceKey == codeActionEquivalenceKey)
{
nodesToSimplify.Add(node);
......
......@@ -18,7 +18,7 @@ internal abstract class ImportAdderService : ILanguageService
{
public async Task<Document> AddImportsAsync(Document document, IEnumerable<TextSpan> spans, OptionSet options, CancellationToken cancellationToken)
{
options = options ?? document.Project.Solution.Workspace.Options;
options = options ?? document.Options;
var model = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var root = await model.SyntaxTree.GetRootAsync(cancellationToken).ConfigureAwait(false);
......
......@@ -133,7 +133,7 @@ internal static async Task<Document> FormatAsync(Document document, IEnumerable<
}
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
return document.WithSyntaxRoot(await FormatAsync(root, spans, document.Project.Solution.Workspace, options, rules, cancellationToken).ConfigureAwait(false));
return document.WithSyntaxRoot(await FormatAsync(root, spans, document.Project.Solution.Workspace, options ?? document.Options, rules, cancellationToken).ConfigureAwait(false));
}
/// <summary>
......@@ -162,7 +162,7 @@ internal static async Task<Document> FormatAsync(Document document, SyntaxAnnota
}
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
return document.WithSyntaxRoot(await FormatAsync(root, annotation, document.Project.Solution.Workspace, options, rules, cancellationToken).ConfigureAwait(false));
return document.WithSyntaxRoot(await FormatAsync(root, annotation, document.Project.Solution.Workspace, options ?? document.Options, rules, cancellationToken).ConfigureAwait(false));
}
/// <summary>
......
......@@ -203,8 +203,7 @@ internal async Task<Solution> SimplifyAsync(Solution solution, IEnumerable<Docum
if (replacementTextValid)
{
var optionSet = solution.Workspace.Options;
document = await Simplifier.ReduceAsync(document, Simplifier.Annotation, optionSet, cancellationToken).ConfigureAwait(false);
document = await Simplifier.ReduceAsync(document, Simplifier.Annotation, cancellationToken: cancellationToken).ConfigureAwait(false);
document = await Formatter.FormatAsync(document, Formatter.Annotation, cancellationToken: cancellationToken).ConfigureAwait(false);
}
......
......@@ -32,7 +32,7 @@ internal static Task<RenameLocations> GetRenameLocationsAsync(Solution solution,
cancellationToken.ThrowIfCancellationRequested();
options = options ?? solution.Workspace.Options;
options = options ?? solution.Options;
return RenameLocations.FindAsync(symbol, solution, options, cancellationToken);
}
......
......@@ -48,7 +48,7 @@ public async Task<Document> ReduceAsync(Document document, IEnumerable<TextSpan>
return document;
}
optionSet = optionSet ?? document.Project.Solution.Workspace.Options;
optionSet = optionSet ?? document.Options;
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册