From 5ad804da1c3a811dcdbe59f30b44115abb59ffab Mon Sep 17 00:00:00 2001 From: Brendan Molloy Date: Sun, 22 Jan 2023 18:45:01 +0100 Subject: [PATCH] Add various language syntax highlighting (#329) --- common/deps.ts | 28 ++++++++++- web/editor.tsx | 128 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+), 2 deletions(-) diff --git a/common/deps.ts b/common/deps.ts index f8363f51..6f9e6bb3 100644 --- a/common/deps.ts +++ b/common/deps.ts @@ -92,8 +92,32 @@ export { syntaxTree, } from "@codemirror/language"; -export { yaml as yamlLanguage } from "https://esm.sh/@codemirror/legacy-modes@6.2.0/mode/yaml?external=@codemirror/language"; -export { standardSQL as sqlLanguage } from "https://esm.sh/@codemirror/legacy-modes@6.3.1/mode/sql?external=@codemirror/language"; +export { yaml as yamlLanguage } from "https://esm.sh/@codemirror/legacy-modes@6.3.1/mode/yaml?external=@codemirror/language"; +export { + standardSQL as sqlLanguage, + pgSQL as postgresqlLanguage, +} from "https://esm.sh/@codemirror/legacy-modes@6.3.1/mode/sql?external=@codemirror/language"; +export { rust as rustLanguage } from "https://esm.sh/@codemirror/legacy-modes@6.3.1/mode/rust?external=@codemirror/language"; +export { css as cssLanguage } from "https://esm.sh/@codemirror/legacy-modes@6.3.1/mode/css?external=@codemirror/language"; +export { python as pythonLanguage } from "https://esm.sh/@codemirror/legacy-modes@6.3.1/mode/python?external=@codemirror/language"; +export { protobuf as protobufLanguage } from "https://esm.sh/@codemirror/legacy-modes@6.3.1/mode/protobuf?external=@codemirror/language"; +export { shell as shellLanguage } from "https://esm.sh/@codemirror/legacy-modes@6.3.1/mode/shell?external=@codemirror/language"; +export { swift as swiftLanguage } from "https://esm.sh/@codemirror/legacy-modes@6.3.1/mode/swift?external=@codemirror/language"; +export { toml as tomlLanguage } from "https://esm.sh/@codemirror/legacy-modes@6.3.1/mode/toml?external=@codemirror/language"; +export { xml as xmlLanguage } from "https://esm.sh/@codemirror/legacy-modes@6.3.1/mode/xml?external=@codemirror/language"; +export { json as jsonLanguage } from "https://esm.sh/@codemirror/legacy-modes@6.3.1/mode/javascript?external=@codemirror/language"; +export { + c as cLanguage, + cpp as cppLanguage, + java as javaLanguage, + csharp as csharpLanguage, + scala as scalaLanguage, + kotlin as kotlinLanguage, + objectiveC as objectiveCLanguage, + objectiveCpp as objectiveCppLanguage, + dart as dartLanguage, +} from "https://esm.sh/@codemirror/legacy-modes@6.3.1/mode/clike?external=@codemirror/language"; + export { javascriptLanguage, typescriptLanguage, diff --git a/web/editor.tsx b/web/editor.tsx index 13d08c32..8fe3bc8f 100644 --- a/web/editor.tsx +++ b/web/editor.tsx @@ -1,11 +1,15 @@ // Third party web dependencies import { autocompletion, + cLanguage, closeBrackets, closeBracketsKeymap, CompletionContext, completionKeymap, CompletionResult, + cppLanguage, + csharpLanguage, + dartLanguage, drawSelection, dropCursor, EditorSelection, @@ -16,22 +20,35 @@ import { historyKeymap, indentOnInput, indentWithTab, + javaLanguage, javascriptLanguage, + jsonLanguage, KeyBinding, keymap, + kotlinLanguage, LanguageDescription, LanguageSupport, markdown, + objectiveCLanguage, + objectiveCppLanguage, + postgresqlLanguage, + protobufLanguage, + pythonLanguage, runScopeHandlers, + rustLanguage, + scalaLanguage, searchKeymap, + shellLanguage, sqlLanguage, standardKeymap, StreamLanguage, syntaxHighlighting, syntaxTree, + tomlLanguage, typescriptLanguage, ViewPlugin, ViewUpdate, + xmlLanguage, yamlLanguage, } from "../common/deps.ts"; import { SilverBulletHooks } from "../common/manifest.ts"; @@ -526,6 +543,117 @@ export class Editor { alias: ["sql"], support: new LanguageSupport(StreamLanguage.define(sqlLanguage)), }), + LanguageDescription.of({ + name: "postgresql", + alias: ["pgsql", "postgres"], + support: new LanguageSupport( + StreamLanguage.define(postgresqlLanguage), + ), + }), + LanguageDescription.of({ + name: "rust", + alias: ["rs"], + support: new LanguageSupport(StreamLanguage.define(rustLanguage)), + }), + LanguageDescription.of({ + name: "css", + support: new LanguageSupport(StreamLanguage.define(sqlLanguage)), + }), + LanguageDescription.of({ + name: "python", + alias: ["py"], + support: new LanguageSupport( + StreamLanguage.define(pythonLanguage), + ), + }), + LanguageDescription.of({ + name: "protobuf", + alias: ["proto"], + support: new LanguageSupport( + StreamLanguage.define(protobufLanguage), + ), + }), + LanguageDescription.of({ + name: "shell", + alias: ["sh", "bash", "zsh", "fish"], + support: new LanguageSupport( + StreamLanguage.define(shellLanguage), + ), + }), + LanguageDescription.of({ + name: "swift", + support: new LanguageSupport(StreamLanguage.define(rustLanguage)), + }), + LanguageDescription.of({ + name: "toml", + support: new LanguageSupport(StreamLanguage.define(tomlLanguage)), + }), + LanguageDescription.of({ + name: "json", + support: new LanguageSupport(StreamLanguage.define(jsonLanguage)), + }), + LanguageDescription.of({ + name: "xml", + support: new LanguageSupport(StreamLanguage.define(xmlLanguage)), + }), + LanguageDescription.of({ + name: "c", + support: new LanguageSupport(StreamLanguage.define(cLanguage)), + }), + LanguageDescription.of({ + name: "cpp", + alias: ["c++", "cxx"], + support: new LanguageSupport(StreamLanguage.define(cppLanguage)), + }), + LanguageDescription.of({ + name: "java", + support: new LanguageSupport(StreamLanguage.define(javaLanguage)), + }), + LanguageDescription.of({ + name: "csharp", + alias: ["c#", "cs"], + support: new LanguageSupport( + StreamLanguage.define(csharpLanguage), + ), + }), + LanguageDescription.of({ + name: "scala", + alias: ["sc"], + support: new LanguageSupport( + StreamLanguage.define(scalaLanguage), + ), + }), + LanguageDescription.of({ + name: "kotlin", + alias: ["kt", "kts"], + support: new LanguageSupport( + StreamLanguage.define(kotlinLanguage), + ), + }), + LanguageDescription.of({ + name: "objc", + alias: ["objective-c", "objectivec"], + support: new LanguageSupport( + StreamLanguage.define(objectiveCLanguage), + ), + }), + LanguageDescription.of({ + name: "objcpp", + alias: [ + "objc++", + "objective-cpp", + "objectivecpp", + "objective-c++", + "objectivec++", + ], + support: new LanguageSupport( + StreamLanguage.define(objectiveCppLanguage), + ), + }), + LanguageDescription.of({ + name: "dart", + support: new LanguageSupport(StreamLanguage.define(dartLanguage)), + }), ], addKeymap: true, }),