Archived
Add syntax highlighting for git diffs
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { EditorState, type Extension } from "@codemirror/state";
|
||||
import { EditorView, keymap, lineNumbers } from "@codemirror/view";
|
||||
import { defaultKeymap } from "@codemirror/commands";
|
||||
import { syntaxHighlighting, defaultHighlightStyle } from "@codemirror/language";
|
||||
import { syntaxHighlighting, defaultHighlightStyle, StreamLanguage } from "@codemirror/language";
|
||||
import { javascript } from "@codemirror/lang-javascript";
|
||||
import { json } from "@codemirror/lang-json";
|
||||
import { markdown } from "@codemirror/lang-markdown";
|
||||
@@ -10,6 +10,7 @@ import { html as htmlLang } from "@codemirror/lang-html";
|
||||
import { python } from "@codemirror/lang-python";
|
||||
import { rust } from "@codemirror/lang-rust";
|
||||
import { go } from "@codemirror/lang-go";
|
||||
import { diff } from "@codemirror/legacy-modes/mode/diff";
|
||||
import { LitElement, css, html } from "lit";
|
||||
import { customElement, property, query } from "lit/decorators.js";
|
||||
|
||||
@@ -108,6 +109,7 @@ function languageExtensions(language: string | undefined): Extension[] {
|
||||
case "python": return [python()];
|
||||
case "rust": return [rust()];
|
||||
case "go": return [go()];
|
||||
case "diff": return [StreamLanguage.define(diff)];
|
||||
default: return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ export class WorkspacePanel extends LitElement {
|
||||
if (diff === undefined) return html`<p class="muted">Loading diff…</p>`;
|
||||
return html`
|
||||
<div class="viewer-header"><strong>${diff.path ?? "diff"}</strong><small>${diff.staged ? "staged" : "unstaged"}${diff.truncated ? " · truncated" : ""}</small></div>
|
||||
<code-viewer .content=${diff.diff !== "" ? diff.diff : "No unstaged diff."}></code-viewer>
|
||||
<code-viewer .content=${diff.diff !== "" ? diff.diff : "No unstaged diff."} .language=${"diff"}></code-viewer>
|
||||
`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user