Skip to content

Initial work to move indentation services down to codestyle layer (step 9/N)#60452

Merged
CyrusNajmabadi merged 21 commits intodotnet:mainfrom
CyrusNajmabadi:indentationDown9
Mar 29, 2022
Merged

Initial work to move indentation services down to codestyle layer (step 9/N)#60452
CyrusNajmabadi merged 21 commits intodotnet:mainfrom
CyrusNajmabadi:indentationDown9

Conversation

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

Followup to #60451.

This PR moves the 'Convert Namespace' fixer down to the CodeFixes layer now that the indentation service is available there.

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.

@CyrusNajmabadi CyrusNajmabadi requested review from a team as code owners March 29, 2022 06:20
@ghost ghost added the Area-IDE label Mar 29, 2022
@CyrusNajmabadi CyrusNajmabadi requested a review from mavasani March 29, 2022 06:58
@mavasani
Copy link
Copy Markdown
Contributor

@CyrusNajmabadi I can take a look at this PR once the other approved PR is merged and you have pushed a merge commit on this PR. Thanks!

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

@mavasani done.

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

though feel free to do this one piece at a time.

}

#pragma warning disable IDE0060 // Remove unused parameter
public static bool IsPreProcessorKeywordContext(this SyntaxTree syntaxTree, int position, SyntaxToken preProcessorTokenOnLeftOfPosition)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I understand this a move, but seems this can be an extension method on the token instead of the unused syntaxTree parameter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes. but that would have a downstream impact on all the existing callers. i didn't want to do that. :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sounds reasonable.

#if CODE_STYLE
var sourceText = document.GetTextAsync(cancellationToken).WaitAndGetResult_CanCallOnBackground(cancellationToken);
#else
var sourceText = document.GetTextSynchronously(cancellationToken);
Copy link
Copy Markdown
Contributor

@mavasani mavasani Mar 29, 2022

Choose a reason for hiding this comment

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

Ah, I hate that the synchronous API is non-public and we end up writing sync helper methods in Workspaces layer that should really be async, and now that we want to move it down you are either left with cascading async changes flowing up the call chain OR this ugly code with preprocessor directives and WaitAndGetResult_CanCallOnBackground calls and such. If possible, try to convert GetPreferredIndentation to an async method to avoid this and just use GetTextAsync here (if it doesn't lead to too big an explosion of changes).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

so the main problem here is that for VS we do want the actual indentation-feature (e.g. when you hit enter) to be synchronous. so we want to actually avoid async+blocking. We then also expose this functionality out for other features to use (like code-fixes). Codefixes could be async without issue, but we still need the hardened sync path for the mainline feature, and that mainline feature should not block on asynchrony as that could lead to stalls on UI thread. :(

(this is not pretty).

Copy link
Copy Markdown
Contributor

@mavasani mavasani left a comment

Choose a reason for hiding this comment

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

Overall looks good. Seems there are some WIP pieces and an API that can possible be made async to make it cleaner.

@CyrusNajmabadi CyrusNajmabadi requested a review from mavasani March 29, 2022 20:07
@CyrusNajmabadi CyrusNajmabadi merged commit 99876d2 into dotnet:main Mar 29, 2022
@ghost ghost added this to the Next milestone Mar 29, 2022
@dibarbet dibarbet modified the milestones: Next, 17.3.P1 Apr 25, 2022
@CyrusNajmabadi CyrusNajmabadi deleted the indentationDown9 branch May 3, 2022 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants