Skip to content

Commit

Permalink
fix codeLensProvider gets removed on syntax errors
Browse files Browse the repository at this point in the history
  • Loading branch information
firsttris committed Mar 28, 2024
1 parent 81b797c commit 0f6b410
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"dist": true
},
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.fixAll": "explicit",
}
}
14 changes: 7 additions & 7 deletions src/JestRunnerCodeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ function getTestsBlocks(
}

export class JestRunnerCodeLensProvider implements CodeLensProvider {
private lastSuccessfulCodeLens: CodeLens[] = [];

constructor(private readonly codeLensOptions: CodeLensOption[]) {}

public async provideCodeLenses(document: TextDocument): Promise<CodeLens[]> {
try {
const text = document.getText();
const parseResults = parse(document.fileName, text, { plugins: { decorators: 'legacy' } }).root.children;
const codeLens: CodeLens[] = [];
parseResults.forEach((parseResult) =>
codeLens.push(...getTestsBlocks(parseResult, parseResults, this.codeLensOptions))
const parseResults = parse(document.fileName, document.getText(), { plugins: { decorators: 'legacy' } }).root
.children;
this.lastSuccessfulCodeLens = parseResults.flatMap((parseResult) =>
getTestsBlocks(parseResult, parseResults, this.codeLensOptions)
);
return codeLens;
} catch (e) {
// Ignore error and keep showing Run/Debug buttons at same position
console.error('jest-editor-support parser returned error', e);
}
return this.lastSuccessfulCodeLens;
}
}

0 comments on commit 0f6b410

Please sign in to comment.