Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PowerShell and Diff language modes #191

Merged
merged 3 commits into from
Feb 9, 2024
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
27 changes: 1 addition & 26 deletions public/langdetect-worker.js
Original file line number Diff line number Diff line change
@@ -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()

Expand Down
2 changes: 1 addition & 1 deletion src/editor/lang-heynote/heynote.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion src/editor/lang-heynote/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const parser = LRParser.deserialize({
maxTerm: 10,
skippedNodes: [0],
repeatNodeCount: 1,
tokenData: ",p~RaYZ!W}!O!]#V#W!h#X#Y$U#Z#[$t#[#]%g#^#_%y#_#`'g#`#a(P#a#b(i#d#e)h#f#g*T#g#h*d#h#i+Y#l#m%m#m#n,X%&x%&y,_~!]OX~~!`P#T#U!c~!hOU~~!kR#`#a!t#d#e#i#g#h#o~!wP#c#d!z~!}P#^#_#Q~#TP#i#j#W~#ZP#f#g#^~#aP#X#Y#d~#iOT~~#lP#d#e#d~#rQ#[#]#x#g#h#d~#{P#T#U$O~$RP#f#g#i~$XP#f#g$[~$_P#`#a$b~$eP#T#U$h~$kP#b#c$n~$qP#Z#[#d~$wQ#c#d$[#f#g$}~%QP#c#d%T~%WP#c#d%Z~%^P#j#k%a~%dP#m#n#d~%jP#h#i%m~%pP#a#b%s~%vP#`#a#d~%|Q#T#U&S#g#h'W~&VP#j#k&Y~&]P#T#U&`~&ePT~#g#h&h~&kP#V#W&n~&qP#f#g&t~&wP#]#^&z~&}P#d#e'Q~'TP#h#i#d~'ZQ#c#d'a#l#m#d~'dP#b#c#d~'jP#c#d'm~'pP#h#i's~'vP#`#a'y~'|P#]#^'a~(SP#X#Y(V~(YP#n#o(]~(`P#X#Y(c~(fP#f#g#d~(lP#T#U(o~(rQ#f#g(x#h#i)b~({P#_#`)O~)RP#W#X)U~)XP#c#d)[~)_P#k#l'a~)eP#[#]#d~)kQ#[#]#i#m#n)q~)tP#h#i)w~)zP#[#])}~*QP#c#d'a~*WP#i#j*Z~*^Q#U#V%a#g#h'Q~*gR#[#]*p#e#f%s#k#l*|~*sP#X#Y*v~*yP#`#a%s~+PP#]#^+S~+VP#Y#Z'Q~+]S#X#Y+i#c#d%m#g#h+o#m#n+u~+lP#l#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y,q#c#d&S#g#h,w#m#n,}~,tP#l#m'g~,zP#l#m#g~-QP#d#e-T~-WP#X#Y-Z~-^P#g#h&}~-dP#T#U&S~-jP%&x%&y-m~-pP%&x%&y-s~-xOY~",
tokenizers: [0, noteContent],
topRules: {"Document":[0,2]},
tokenPrec: 0
Expand Down
14 changes: 14 additions & 0 deletions src/editor/languages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
}),
]


Expand Down
2 changes: 1 addition & 1 deletion tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
16 changes: 13 additions & 3 deletions vite.config.ts → vite.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as fs from 'node:fs'
import { rmSync } from 'node:fs'
import { join } from 'node:path'
import { defineConfig } from 'vite'
Expand All @@ -9,15 +10,14 @@ 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 })

const isDevelopment = process.env.NODE_ENV === "development" || !!process.env.VSCODE_DEBUG
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
Expand All @@ -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: {
Expand All @@ -48,6 +57,7 @@ export default defineConfig({
plugins: [
vue(),
updateReadmeKeybinds(),
updateGuesslangLanguagesInWebWorker(),
electron([
{
// Main-Process entry file of the Electron App.
Expand Down
Loading