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

fix: handle unimplemented file capabilities slightly more gracefully #1089

Merged
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
92 changes: 48 additions & 44 deletions src/playground/workers/biomeWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ import {
QuoteStyle,
Semicolons,
} from "@/playground/types";
import {
isCssFilename,
isFrameworkTemplateFilename,
isGraphqlFilename,
isJsonFilename,
} from "@/playground/utils";
import init, {
DiagnosticPrinter,
type PartialConfiguration as Configuration,
Expand Down Expand Up @@ -221,42 +215,49 @@ self.addEventListener("message", async (e) => {
}
files.set(filename, file);
const path = getPathForFile(file);
const isFrameworkTemplate = isFrameworkTemplateFilename(filename);

const syntaxTree = !isFrameworkTemplate
? workspace.getSyntaxTree({
path,
})
: {
ast: "Not available",
cst: "Not available",
};
const fileFeatures = workspace.fileFeatures({
features: ["Debug", "Format", "Lint", "OrganizeImports"],
path,
});

const syntaxTree =
fileFeatures.features_supported.get("Debug") === "Supported"
? workspace.getSyntaxTree({
path,
})
: { ast: "Not supported", cst: "Not supported" };

const isGraphql = isGraphqlFilename(filename);

const controlFlowGraph = !(
isJsonFilename(filename) ||
isCssFilename(filename) ||
isGraphql ||
isFrameworkTemplate
)
? workspace.getControlFlowGraph({
path,
cursor: cursorPosition,
})
: "";

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

const importSorting = isGraphql
? { code: "" }
: workspace.organizeImports({
path,
});
let controlFlowGraph = "";
try {
controlFlowGraph =
fileFeatures.features_supported.get("Debug") === "Supported"
? workspace.getControlFlowGraph({
path,
cursor: cursorPosition,
})
: "";
} catch (e) {
console.warn("Failed to get control flow graph:", e);
controlFlowGraph = "";
}

const formatterIr =
fileFeatures.features_supported.get("Debug") === "Supported"
? workspace.getFormatterIr({
path,
})
: "Not supported";

const importSorting =
fileFeatures.features_supported.get("OrganizeImports") === "Supported"
? workspace.organizeImports({
path,
})
: {
code:
fileFeatures.features_supported.get("OrganizeImports") ??
"Not supported",
};

const categories: RuleCategories = [];
if (configuration?.formatter?.enabled) {
Expand All @@ -278,9 +279,12 @@ self.addEventListener("message", async (e) => {
printer.print_verbose(diag);
}

const printed = workspace.formatFile({
path,
});
const printed =
fileFeatures.features_supported.get("Format") === "Supported"
? workspace.formatFile({
path,
})
: { code: "Not supported" };

const biomeOutput: BiomeOutput = {
syntax: {
Expand Down