Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Organize imports fix (add missing testfile) #1501

Merged
merged 2 commits into from May 28, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -103,7 +103,10 @@ export class CodeActionsProviderImpl implements CodeActionsProvider {
const { lang, tsDoc, userPreferences } = await this.getLSAndTSDoc(document);
const fragment = tsDoc.getFragment();

if (cancellationToken?.isCancellationRequested) {
if (cancellationToken?.isCancellationRequested || tsDoc.parserError) {
// If there's a parser error, we fall back to only the script contents,
// so organize imports likely throws out a lot of seemingly unused imports
// because they are only used in the template. Therefore do nothing in this case.
return [];
}

Expand Down
Expand Up @@ -905,6 +905,21 @@ function test(useNewTransformation: boolean) {
]);
});

it('organize imports should do nothing if there is a parser error', async () => {
const { provider, document } = setup('organize-imports-error.svelte');

const codeActions = await provider.getCodeActions(
document,
Range.create(Position.create(1, 4), Position.create(1, 5)),
{
diagnostics: [],
only: [CodeActionKind.SourceOrganizeImports]
}
);

assert.deepStrictEqual(codeActions, []);
});

it('should do extract into const refactor', async () => {
const { provider, document } = setup('codeactions.svelte');

Expand Down
@@ -0,0 +1,7 @@
<script>
import {c} from './c';
const a = true;
</script>

{c}
<