Skip to content

Create "Sort and Consolidate Usings" code action#12824

Merged
davidwengier merged 5 commits intodotnet:mainfrom
davidwengier:SortUsingsCodeAction
Feb 25, 2026
Merged

Create "Sort and Consolidate Usings" code action#12824
davidwengier merged 5 commits intodotnet:mainfrom
davidwengier:SortUsingsCodeAction

Conversation

@davidwengier
Copy link
Copy Markdown
Member

Part of #8548

#12804 does remove, this does sort. You'll never guess what's next!

This one was easy, and we probably should have done it years ago.

@davidwengier davidwengier requested a review from a team as a code owner February 24, 2026 10:13
var directiveLineNumber = sourceText.GetLinePosition(directive.Span.Start).Line;
var line = sourceText.Lines[directiveLineNumber];

var lineText = sourceText.ToString(TextSpan.FromBounds(line.Start, line.End));
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.

sourceText.ToString(TextSpan.FromBounds(line.Start, line.End))

Is this just an allocating version of using line.Text?

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.

edit: now that I look, no, it's not. But there is a version of ToString on the TextLine, so this could just be

var lineText = line.ToString();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

line.Text actually just returns a reference to the SourceText. BUT this is a silly way to check if the line only has a using directive on it, so I'll make it better

Copy link
Copy Markdown
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

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

:shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature request Large improvement request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants