diff --git a/public/langdetect-worker.js b/public/langdetect-worker.js index 47ba638b..95ca2574 100644 --- a/public/langdetect-worker.js +++ b/public/langdetect-worker.js @@ -1,31 +1,6 @@ importScripts("guesslang.min.js") -GUESSLANG_LANGUAGES = [ - "json", - "py", - "js", - "ts", - "html", - "sql", - "java", - "cpp", - "php", - "css", - "xml", - "rs", - "md", - "cs", - "rb", - "sh", - "yaml", - "go", - "clj", - "erl", - "toml", - "swift", - "kt", - "groovy", -] +GUESSLANG_LANGUAGES = ["json","py","html","sql","md","java","php","css","xml","cpp","rs","cs","rb","sh","yaml","toml","go","clj","erl","js","ts","swift","kt","groovy","ps1"] const guessLang = new self.GuessLang() diff --git a/src/editor/lang-heynote/heynote.grammar b/src/editor/lang-heynote/heynote.grammar index 0a42bec5..afaa8e6f 100644 --- a/src/editor/lang-heynote/heynote.grammar +++ b/src/editor/lang-heynote/heynote.grammar @@ -11,7 +11,7 @@ NoteDelimiter { @tokens { noteDelimiterMark { "∞∞∞" } - NoteLanguage { "text" | "math" | "javascript" | "typescript" | "jsx" | "tsx" | "json" | "python" | "html" | "sql" | "markdown" | "java" | "php" | "css" | "xml" | "cpp" | "rust" | "csharp" | "ruby" | "shell" | "yaml" | "golang" | "clojure" | "erlang" | "lezer" | "toml" | "swift" | "kotlin" | "groovy" } + NoteLanguage { "text" | "math" | "javascript" | "typescript" | "jsx" | "tsx" | "json" | "python" | "html" | "sql" | "markdown" | "java" | "php" | "css" | "xml" | "cpp" | "rust" | "csharp" | "ruby" | "shell" | "yaml" | "golang" | "clojure" | "erlang" | "lezer" | "toml" | "swift" | "kotlin" | "groovy" | "diff" | "powershell" } Auto { "-a" } noteDelimiterEnter { "\n" } //NoteContent { String } diff --git a/src/editor/lang-heynote/parser.js b/src/editor/lang-heynote/parser.js index b242b68f..e24be277 100644 --- a/src/editor/lang-heynote/parser.js +++ b/src/editor/lang-heynote/parser.js @@ -10,7 +10,7 @@ export const parser = LRParser.deserialize({ maxTerm: 10, skippedNodes: [0],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, tokenPrec: 0 diff --git a/src/editor/languages.js b/src/editor/languages.js index 1ab10e97..a7d85ea9 100644 --- a/src/editor/languages.js +++ b/src/editor/languages.js @@ -24,6 +24,8 @@ import { toml } from "@codemirror/legacy-modes/mode/toml" import { swift } from "@codemirror/legacy-modes/mode/swift" import { kotlin } from "@codemirror/legacy-modes/mode/clike" import { groovy } from "@codemirror/legacy-modes/mode/groovy" +import { diff } from "@codemirror/legacy-modes/mode/diff"; +import { powerShell } from "@codemirror/legacy-modes/mode/powershell"; import typescriptPlugin from "prettier/plugins/typescript.mjs" import babelPrettierPlugin from "prettier/plugins/babel.mjs" @@ -239,6 +241,18 @@ export const LANGUAGES = [ parser: StreamLanguage.define(groovy).parser, guesslang: "groovy", }), + new Language({ + token: "diff", + name: "Diff", + parser: StreamLanguage.define(diff).parser, + guesslang: null, + }), + new Language({ + token: "powershell", + name: "PowerShell", + parser: StreamLanguage.define(powerShell).parser, + guesslang: "ps1", + }), ] diff --git a/tsconfig.node.json b/tsconfig.node.json index 9d3c6d6d..050be035 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -6,5 +6,5 @@ "resolveJsonModule": true, "allowSyntheticDefaultImports": true }, - "include": ["vite.config.ts", "package.json", "electron", "shared-utils"] + "include": ["vite.config.mjs", "package.json", "electron", "shared-utils"] } diff --git a/vite.config.ts b/vite.config.mjs similarity index 83% rename from vite.config.ts rename to vite.config.mjs index 2af59d54..a3591198 100644 --- a/vite.config.ts +++ b/vite.config.mjs @@ -1,3 +1,4 @@ +import * as fs from 'node:fs' import { rmSync } from 'node:fs' import { join } from 'node:path' import { defineConfig } from 'vite' @@ -9,6 +10,7 @@ import pkg from './package.json' import path from 'path' import { keyHelpStr } from "./shared-utils/key-helper"; +import { LANGUAGES }  from "./src/editor/languages" rmSync('dist-electron', { recursive: true, force: true }) @@ -16,8 +18,6 @@ const isDevelopment = process.env.NODE_ENV === "development" || !!process.env.VS const isProduction = process.env.NODE_ENV === "production" const updateReadmeKeybinds = async () => { - const fs = require('fs') - const path = require('path') const readmePath = path.resolve(__dirname, 'README.md') let readme = fs.readFileSync(readmePath, 'utf-8') const keybindsRegex = /^(### What are the default keyboard shortcuts\?\s*).*?^(```\s+#)/gms @@ -32,11 +32,20 @@ ${keyHelpStr('darwin')} \`\`\` ${keyHelpStr('win32')} $2` - readme = readme.replace(keybindsRegex, shortcuts) fs.writeFileSync(readmePath, readme) } +const updateGuesslangLanguagesInWebWorker = async () => { + const langDetectWorkerPath = path.resolve(__dirname, 'public', 'langdetect-worker.js') + let workerFileContents = fs.readFileSync(langDetectWorkerPath, 'utf-8') + const langListRegex = /^GUESSLANG_LANGUAGES = \[[^\]]+\]/gms + const newLangList = JSON.stringify(LANGUAGES.map(l => l.guesslang).filter(l => l !== null)) + workerFileContents = workerFileContents.replace(langListRegex, `GUESSLANG_LANGUAGES = ${newLangList}`) + fs.writeFileSync(langDetectWorkerPath, workerFileContents) +} + + // https://vitejs.dev/config/ export default defineConfig({ resolve: { @@ -48,6 +57,7 @@ export default defineConfig({ plugins: [ vue(), updateReadmeKeybinds(), + updateGuesslangLanguagesInWebWorker(), electron([ { // Main-Process entry file of the Electron App.