Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/perky-clowns-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro-vscode': patch
---

Fixes organize imports across frontmatter and multiple script tags
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,50 @@ describe('TypeScript - Organize & Sort Imports', () => {

assert.ok(returnedText.some((text) => text.includes('helperOne, helperTwo')));
});

it('organizes imports in every TypeScript region for full-document actions', async () => {
const document = await languageServer.openFakeDocument(
`---
import { serverTwo, serverOne } from './server';

serverOne();
serverTwo();
---

<script>
import { clientTwo, clientOne } from './client';

clientOne();
clientTwo();
</script>

<script>
import { otherTwo, otherOne } from './other';

otherOne();
otherTwo();
</script>
`,
'astro',
);
const organizeActions = await languageServer.handle.sendCodeActionsRequest(
document.uri,
Range.create(0, 0, document.lineCount - 1, 0),
{
diagnostics: [],
only: ['source.organizeImports'],
triggerKind: 2,
},
);
const organizeEdits = await Promise.all(
(organizeActions as CodeAction[]).map((action) =>
languageServer.handle.sendCodeActionResolveRequest(action),
),
);
const returnedText = getTextEdits(organizeEdits).map((edit) => edit.newText);

assert.ok(returnedText.some((text) => text.includes('serverOne, serverTwo')));
assert.ok(returnedText.some((text) => text.includes('clientOne, clientTwo')));
assert.ok(returnedText.some((text) => text.includes('otherOne, otherTwo')));
});
});
11 changes: 11 additions & 0 deletions patches/@volar__language-service@2.4.28.patch

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can't we send a patch to volar instead?

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.

It's not being actively maintained. My understanding is that after all of the content mapping stuff is done we'll be able to remove Volar from usage in our vscode plugin.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's a pity

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
diff --git a/lib/utils/dedupe.js b/lib/utils/dedupe.js
--- a/lib/utils/dedupe.js
+++ b/lib/utils/dedupe.js
@@ -39,6 +39,7 @@ function createLocationSet() {
function withCodeAction(items) {
return dedupe(items, item => [
item.title,
+ JSON.stringify(item.data),
].join(':'));
}
function withTextEdits(items) {
23 changes: 12 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,5 @@ allowBuilds:
workerd: false

patchedDependencies:
'@volar/language-service@2.4.28': patches/@volar__language-service@2.4.28.patch
'@volar/typescript@2.4.28': patches/@volar__typescript@2.4.28.patch
Loading