Format authored monorepo code with pinned language formatters
This commit is contained in:
@@ -16,9 +16,7 @@ export const readQxSource = async (root: string, name: string) => {
|
||||
};
|
||||
|
||||
/** Local imports share one workspace scope; paths are always repository-relative. */
|
||||
export const resolveQxSources = async (
|
||||
read: (name: string) => Promise<string>, entry = "workspace.qx",
|
||||
) => {
|
||||
export const resolveQxSources = async (read: (name: string) => Promise<string>, entry = "workspace.qx") => {
|
||||
const files = new Map<string, string>();
|
||||
const active: string[] = [];
|
||||
const visited = new Set<string>();
|
||||
@@ -34,8 +32,8 @@ export const resolveQxSources = async (
|
||||
if (visited.has(name)) return;
|
||||
const text = await read(name);
|
||||
const syntax = parseQx(text, name);
|
||||
if (syntax.diagnostics.length) throw new Error(syntax.diagnostics.map((d) =>
|
||||
`${name}:${d.line}:${d.column + 1}: ${d.message}`).join("\n"));
|
||||
if (syntax.diagnostics.length)
|
||||
throw new Error(syntax.diagnostics.map((d) => `${name}:${d.line}:${d.column + 1}: ${d.message}`).join("\n"));
|
||||
const declaration = syntax.root.children[0]!;
|
||||
if (declaration.kind !== (root ? "workspaceDecl" : "fragmentDecl"))
|
||||
throw new Error(`${name}: expected ${root ? "workspace" : "fragment"} document`);
|
||||
@@ -60,16 +58,22 @@ export const resolveQxSources = async (
|
||||
};
|
||||
await visit(entry, true);
|
||||
return {
|
||||
source, sourceFiles: [...files.keys()], files,
|
||||
source,
|
||||
sourceFiles: [...files.keys()],
|
||||
files,
|
||||
originalPosition(line: number, column: number) {
|
||||
const lines = source.split("\n");
|
||||
const offset = lines.slice(0, line - 1).reduce((sum, value) => sum + value.length + 1, 0) +
|
||||
const offset =
|
||||
lines.slice(0, line - 1).reduce((sum, value) => sum + value.length + 1, 0) +
|
||||
[...(lines[line - 1] ?? "")].slice(0, column).join("").length;
|
||||
const segment = segments.find((entry) => entry.start <= offset && entry.end > offset);
|
||||
if (!segment) return { fileName: entry, line, column };
|
||||
const prefix = files.get(segment.fileName)!.slice(0, segment.sourceStart + offset - segment.start);
|
||||
return { fileName: segment.fileName, line: prefix.split("\n").length,
|
||||
column: prefix.length - prefix.lastIndexOf("\n") - 1 };
|
||||
return {
|
||||
fileName: segment.fileName,
|
||||
line: prefix.split("\n").length,
|
||||
column: prefix.length - prefix.lastIndexOf("\n") - 1,
|
||||
};
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user