Initial work to move indentation services down to codestyle layer (step 8/N)#60451
Initial work to move indentation services down to codestyle layer (step 8/N)#60451CyrusNajmabadi merged 16 commits intodotnet:mainfrom
Conversation
| var formattingRuleProvider = workspace.Services.GetService<IHostDependentFormattingRuleFactoryService>(); | ||
|
|
||
| var rules = formattingRuleProvider.CreateRule(document, position).Concat(Formatter.GetDefaultFormattingRules(document)); | ||
| var rules = ImmutableArray.Create(formattingRuleProvider.CreateRule(document, position)).AddRange(Formatter.GetDefaultFormattingRules(document)); |
There was a problem hiding this comment.
could the IHostDependentFormattingRuleFactoryService return an immutable array? or does it need to be ienumerable for some consumer
There was a problem hiding this comment.
teh host actually returns a single rule. but then we need to wrap that in an immutable array to be able to addrange after that. it's def not clean and i wish tehre was a better idiom for "i want to make an immutable array out of individual objects and streams of objects".
| var syntaxFormatting = this.SyntaxFormatting; | ||
|
|
||
| #if CODE_STYLE | ||
| var tree = document.GetSyntaxTreeAsync(cancellationToken).WaitAndGetResult_CanCallOnBackground(cancellationToken); |
There was a problem hiding this comment.
to me would read better if there was just a GetTreeAndIndentation and GetIndentationRule method that kind of hid the codestyle messiness, but that might just be me
There was a problem hiding this comment.
yeah. i don't love this. but i don't feel like there are really good alternaives here :(
| public static string GetPreferredIndentation(this SyntaxToken token, Document document, CancellationToken cancellationToken) | ||
| { | ||
| #if CODE_STYLE | ||
| var sourceText = document.GetTextAsync(cancellationToken).WaitAndGetResult_CanCallOnBackground(cancellationToken); |
There was a problem hiding this comment.
I thought the codestyle layer didn't use documents or am I totally off base
There was a problem hiding this comment.
this is not the codefixes layer, which can use documents (but only the public facing side of them).
Followup to https://github.com/dotnet/roslyn/pull/60445
This PR moves the remainder of the IndentationService down. The only thing remaining is moving existing that use this down to codestyle as well.
I'm doing these PRs in multiple parts to make things simpler to review. Every time i try to tackle the general problem, it explodes into a ton of changes.
The reason for this change overall is that we have fixers taht need to know indentation information. For example, the 'convert to file-scoped-namespace (and reverse)' fixes have to know indentation information so it can make the right fixes. Not having indentation info be available at thsi level means that the fixes are constrained to the VS host.