Skip to content

Commit

Permalink
fix: handle unimplemented file capabilities slightly more gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc3 committed Sep 11, 2024
1 parent ae089cf commit 58f3207
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions src/playground/workers/biomeWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
isCssFilename,
isFrameworkTemplateFilename,
isGraphqlFilename,
isHtmlFilename,
isJsonFilename,
} from "@/playground/utils";
import init, {
Expand Down Expand Up @@ -223,20 +224,27 @@ self.addEventListener("message", async (e) => {
const path = getPathForFile(file);
const isFrameworkTemplate = isFrameworkTemplateFilename(filename);

const syntaxTree = !isFrameworkTemplate
? workspace.getSyntaxTree({
function getSyntaxTree(): { ast: string; cst: string } {
try {
return workspace.getSyntaxTree({
path,
})
: {
});
} catch (err) {
console.error(err);
return {
ast: "Not available",
cst: "Not available",
};
}
}
const syntaxTree = getSyntaxTree();

const isGraphql = isGraphqlFilename(filename);

const controlFlowGraph = !(
isJsonFilename(filename) ||
isCssFilename(filename) ||
isHtmlFilename(filename) ||
isGraphql ||
isFrameworkTemplate
)
Expand All @@ -246,17 +254,24 @@ self.addEventListener("message", async (e) => {
})
: "";

const formatterIr = !isFrameworkTemplate
? workspace.getFormatterIr({
path,
})
: "Not available";

const importSorting = isGraphql
? { code: "" }
: workspace.organizeImports({
function getFormatterIr() {
try {
return workspace.getFormatterIr({
path,
});
} catch (err) {
console.error(err);
return "Not available";
}
}
const formatterIr = getFormatterIr();

const importSorting =
isGraphql || isHtmlFilename(filename)
? { code: "" }
: workspace.organizeImports({
path,
});

const categories: RuleCategories = [];
if (configuration?.formatter?.enabled) {
Expand Down

0 comments on commit 58f3207

Please sign in to comment.