Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 3 additions & 20 deletions packages/core/src/lib/tree-sitter/assets/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,29 +146,15 @@ async function downloadAndCombineQueries(
}

async function generateDefaultParsersFile(parsers: GeneratedParser[], outputPath: string): Promise<void> {
const imports = parsers
.map((parser) => {
const safeFiletype = parser.filetype.replace(/[^a-zA-Z0-9]/g, "_")
const lines = [
`import ${safeFiletype}_highlights from "${parser.highlightsPath}" with { type: "file" }`,
`import ${safeFiletype}_language from "${parser.languagePath}" with { type: "file" }`,
]
if (parser.injectionsPath) {
lines.push(`import ${safeFiletype}_injections from "${parser.injectionsPath}" with { type: "file" }`)
}
return lines.join("\n")
})
.join("\n")

const parserDefinitions = parsers
.map((parser) => {
const safeFiletype = parser.filetype.replace(/[^a-zA-Z0-9]/g, "_")
const queriesLines = [
` highlights: [resolve(dirname(fileURLToPath(import.meta.url)), ${safeFiletype}_highlights)],`,
` highlights: [fileURLToPath(new URL("${parser.highlightsPath}", import.meta.url))],`,
]
if (parser.injectionsPath) {
queriesLines.push(
` injections: [resolve(dirname(fileURLToPath(import.meta.url)), ${safeFiletype}_injections)],`,
` injections: [fileURLToPath(new URL("${parser.injectionsPath}", import.meta.url))],`,
)
}

Expand All @@ -182,7 +168,7 @@ async function generateDefaultParsersFile(parsers: GeneratedParser[], outputPath
${aliasesLine ? aliasesLine + "\n" : ""} queries: {
${queriesLines.join("\n")}
},
wasm: resolve(dirname(fileURLToPath(import.meta.url)), ${safeFiletype}_language),${injectionMappingLine ? "\n" + injectionMappingLine : ""}
wasm: fileURLToPath(new URL("${parser.languagePath}", import.meta.url)),${injectionMappingLine ? "\n" + injectionMappingLine : ""}
}`
})
.join(",\n")
Expand All @@ -192,11 +178,8 @@ ${queriesLines.join("\n")}
// Last generated: ${new Date().toISOString()}

import type { FiletypeParserOptions } from "./types"
import { resolve, dirname } from "path"
import { fileURLToPath } from "url"

${imports}

// Cached parsers to avoid re-resolving paths on every call
let _cachedParsers: FiletypeParserOptions[] | undefined

Expand Down
39 changes: 13 additions & 26 deletions packages/core/src/lib/tree-sitter/default-parsers.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
// This file is generated by assets/update.ts - DO NOT EDIT MANUALLY
// Run 'bun assets/update.ts' to regenerate this file
// Last generated: 2026-03-20T21:07:24.696Z
// Last generated: 2026-04-05T15:48:16.057Z

import type { FiletypeParserOptions } from "./types.js"
import { resolve, dirname } from "path"
import type { FiletypeParserOptions } from "./types"
import { fileURLToPath } from "url"

import javascript_highlights from "./assets/javascript/highlights.scm" with { type: "file" }
import javascript_language from "./assets/javascript/tree-sitter-javascript.wasm" with { type: "file" }
import typescript_highlights from "./assets/typescript/highlights.scm" with { type: "file" }
import typescript_language from "./assets/typescript/tree-sitter-typescript.wasm" with { type: "file" }
import markdown_highlights from "./assets/markdown/highlights.scm" with { type: "file" }
import markdown_language from "./assets/markdown/tree-sitter-markdown.wasm" with { type: "file" }
import markdown_injections from "./assets/markdown/injections.scm" with { type: "file" }
import markdown_inline_highlights from "./assets/markdown_inline/highlights.scm" with { type: "file" }
import markdown_inline_language from "./assets/markdown_inline/tree-sitter-markdown_inline.wasm" with { type: "file" }
import zig_highlights from "./assets/zig/highlights.scm" with { type: "file" }
import zig_language from "./assets/zig/tree-sitter-zig.wasm" with { type: "file" }

// Cached parsers to avoid re-resolving paths on every call
let _cachedParsers: FiletypeParserOptions[] | undefined

Expand All @@ -28,25 +15,25 @@ export function getParsers(): FiletypeParserOptions[] {
filetype: "javascript",
aliases: ["javascriptreact"],
queries: {
highlights: [resolve(dirname(fileURLToPath(import.meta.url)), javascript_highlights)],
highlights: [fileURLToPath(new URL("./assets/javascript/highlights.scm", import.meta.url))],
},
wasm: resolve(dirname(fileURLToPath(import.meta.url)), javascript_language),
wasm: fileURLToPath(new URL("./assets/javascript/tree-sitter-javascript.wasm", import.meta.url)),
},
{
filetype: "typescript",
aliases: ["typescriptreact"],
queries: {
highlights: [resolve(dirname(fileURLToPath(import.meta.url)), typescript_highlights)],
highlights: [fileURLToPath(new URL("./assets/typescript/highlights.scm", import.meta.url))],
},
wasm: resolve(dirname(fileURLToPath(import.meta.url)), typescript_language),
wasm: fileURLToPath(new URL("./assets/typescript/tree-sitter-typescript.wasm", import.meta.url)),
},
{
filetype: "markdown",
queries: {
highlights: [resolve(dirname(fileURLToPath(import.meta.url)), markdown_highlights)],
injections: [resolve(dirname(fileURLToPath(import.meta.url)), markdown_injections)],
highlights: [fileURLToPath(new URL("./assets/markdown/highlights.scm", import.meta.url))],
injections: [fileURLToPath(new URL("./assets/markdown/injections.scm", import.meta.url))],
},
wasm: resolve(dirname(fileURLToPath(import.meta.url)), markdown_language),
wasm: fileURLToPath(new URL("./assets/markdown/tree-sitter-markdown.wasm", import.meta.url)),
injectionMapping: {
"nodeTypes": {
"inline": "markdown_inline",
Expand All @@ -69,16 +56,16 @@ export function getParsers(): FiletypeParserOptions[] {
{
filetype: "markdown_inline",
queries: {
highlights: [resolve(dirname(fileURLToPath(import.meta.url)), markdown_inline_highlights)],
highlights: [fileURLToPath(new URL("./assets/markdown_inline/highlights.scm", import.meta.url))],
},
wasm: resolve(dirname(fileURLToPath(import.meta.url)), markdown_inline_language),
wasm: fileURLToPath(new URL("./assets/markdown_inline/tree-sitter-markdown_inline.wasm", import.meta.url)),
},
{
filetype: "zig",
queries: {
highlights: [resolve(dirname(fileURLToPath(import.meta.url)), zig_highlights)],
highlights: [fileURLToPath(new URL("./assets/zig/highlights.scm", import.meta.url))],
},
wasm: resolve(dirname(fileURLToPath(import.meta.url)), zig_language),
wasm: fileURLToPath(new URL("./assets/zig/tree-sitter-zig.wasm", import.meta.url)),
},
]
}
Expand Down
Loading