дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 18:17:15 +02:00
feat(languages): Jinja2 Template language for .jinja, .jinja2 and .j2 files (#6645)
.jinja, .jinja2 and .j2 files opened as Plain Text. They now open as Jinja2 templates, with the extension before them deciding the content between the tags: Jinja2 HTML (.html.j2, .html.jinja, .htm.*) gets the HTML language server, Emmet, tag closing and linked tags like Django templates; any other name (nginx.conf.j2, values.yaml.j2, base.jinja) is a Jinja2 Template over plain text without HTML tooling. Both use @codemirror/lang-jinja (now a direct dependency, the same 6.0.1 already in the lockfile): highlighting, folding and indentation of block statements, completion of tags, filters and tests, and tag matching. The file icon follows the extension before .j2, and breakpoints in a file typed as a Jinja language turn on debugpy's jinja support. Closes #6644 Co-authored-by: wildcatDownstairs <[email protected]>
Цей коміт міститься в:
1 джерело
5b486f1588
коміт
9ee8f67e9f
22 files changed
+288
-14
No files matched your search
@@ -23,19 +23,24 @@ function load() {
|
||||
.finally(() => (loading = false));
|
||||
}
|
||||
|
||||
/** Jinja2's own extensions: no language of theirs yet, but debugpy stops in them (`jinja: true`). */
|
||||
const JINJA_EXTENSION = /\.(jinja2?|j2)$/i;
|
||||
|
||||
/** A Jinja2 template for debugpy: a `.jinja` / `.j2` file, or markup or text in a `templates` folder. */
|
||||
export const isJinjaTemplate = (path: string) =>
|
||||
JINJA_EXTENSION.test(path) || /[\\/]templates[\\/].*\.(html?|xml|txt)$/i.test(path);
|
||||
/**
|
||||
* A Jinja2 template for debugpy: a Jinja2 Template file (also by extension, should File Types give
|
||||
* it to another language), or markup or text in a `templates` folder.
|
||||
*/
|
||||
export const isJinjaTemplate = (path: string, language?: string | null) =>
|
||||
language === "jinja" ||
|
||||
language === "jinja-html" ||
|
||||
JINJA_EXTENSION.test(path) ||
|
||||
/[\\/]templates[\\/].*\.(html?|xml|txt)$/i.test(path);
|
||||
|
||||
/** Whether a new breakpoint may be placed in a file of `language`. */
|
||||
export function canPlaceBreakpoint(language: string, path = ""): boolean {
|
||||
if (classFileBreakpointReason(path)) return false;
|
||||
// Templates have no adapter of their own: a Python Debug configuration stops in them (debugpy
|
||||
// `django` / `jinja`). Django's doesn't declare debugpy, or it would shadow Python's `[debugger]`.
|
||||
if (workflowSettings().debugger.breakpointsAnyFile || language === "django-html" || isJinjaTemplate(path)) {
|
||||
if (workflowSettings().debugger.breakpointsAnyFile || language === "django-html" || isJinjaTemplate(path, language)) {
|
||||
return true;
|
||||
}
|
||||
load();
|
||||
@@ -70,6 +75,6 @@ export async function templateBreakpoints(): Promise<TemplateBreakpoints> {
|
||||
const languages = await Promise.all(paths.map(languageOf));
|
||||
return {
|
||||
django: languages.includes("django-html"),
|
||||
jinja: paths.some((path, i) => languages[i] !== "django-html" && isJinjaTemplate(path)),
|
||||
jinja: paths.some((path, i) => languages[i] !== "django-html" && isJinjaTemplate(path, languages[i])),
|
||||
};
|
||||
}
|
||||
Reference in new issue
Заблокувати користувача