cuiping-monaco
Advanced tools
Comparing version 0.1.0 to 0.2.0
import * as Monaco from 'monaco-editor'; | ||
export declare const getMonacoForCuiping: (monaco: typeof Monaco) => typeof Monaco; | ||
import { Formula } from 'cuiping/core/parse'; | ||
export declare const getMonacoForCuiping: (monaco: typeof Monaco, { getFormula, markGroup }: { | ||
getFormula?: (() => Formula | undefined) | undefined; | ||
markGroup?: ((groupId: number) => void) | undefined; | ||
}) => typeof Monaco; |
import { GroupAttrs, BondAttrs } from 'cuiping/core/parse'; | ||
export const getMonacoForCuiping = (monaco) => { | ||
export const getMonacoForCuiping = (monaco, { getFormula, markGroup }) => { | ||
monaco.languages.register({ id: 'cuipingFormula' }); | ||
@@ -10,5 +10,5 @@ monaco.languages.setMonarchTokensProvider('cuipingFormula', { | ||
[/\{/, 'attrs', '@attrs'], | ||
[/[+\-|\/\\!*=#]/, 'bond.type'], | ||
[/[+\-|\/\\*!~=#]/, 'bond.type'], | ||
[/\s+/, 'space'], | ||
[/(?=([\^_`](.|\([^)]*?\))|[^[\]{+\-|\/\\!*=#;]+)+)/, 'group.dlmt', '@group'], | ||
[/(?=([\^_`](.|\([^)]*?\))|[^[\]{+\-|\/\\*!~=#;,]+)+)/, 'group.dlmt', '@group'], | ||
[/;/, 'semicolon'] | ||
@@ -18,2 +18,3 @@ ], | ||
{ include: 'root' }, | ||
[/,/, 'bonds.comma'], | ||
[/\]/, 'bonds', '@pop'] | ||
@@ -41,4 +42,4 @@ ], | ||
[/[\^_`]/, 'group.typeset', '@group-typeset'], | ||
[/[^[\]{+\-|\/\\!*=#;\^_`]+/, 'group.content'], | ||
[/(?=[[\]{+\-|\/\\!*=#;])/, 'group.dlmt', '@pop'] | ||
[/[^[\]{+\-|\/\\*!~=#;,\^_`]+/, 'group.content'], | ||
[/(?=[[\]{+\-|\/\\*!~=#;,])/, 'group.dlmt', '@pop'] | ||
], | ||
@@ -94,3 +95,3 @@ 'group-typeset-multiple': [ | ||
if (before.match(/(?<![\^_`]({[^}]*)?)&\w*$/)) { // Note: complete ref | ||
const refNames = [...all.matchAll(/(&|ref):(\w+)/g)]; | ||
const refNames = [...all.matchAll(/(&|ref)\s*:\s*(\w+)/g)]; | ||
range.startColumn--; | ||
@@ -106,7 +107,7 @@ return { | ||
} | ||
const res = before.match(/(.)\s*{([^}]*,)*[^}]+$/); | ||
const res = before.match(/(.)\s*{\s*([^}]*,)*[^:}]+$/); | ||
if (res) { | ||
if (res[1].match(/[\^_`]/)) | ||
return noSuggestions; | ||
if (res[1].match(/[+\-|\/\\!*=#]/)) | ||
if (res[1].match(/[+\-|\/\\*!~=#]/)) | ||
return { | ||
@@ -126,16 +127,41 @@ suggestions: attrSuggestions(BondAttrs, range) | ||
rules: [ | ||
{ token: 'bonds', foreground: '0000FF' }, | ||
{ token: 'ref', foreground: '#007F00', fontStyle: 'italic' }, | ||
{ token: 'bond.type', foreground: 'FF0000' }, | ||
{ token: 'group.typeset', foreground: 'FF9933' }, | ||
{ token: 'group.content.typeset', foreground: 'AAAAAA', fontStyle: 'italic' }, | ||
{ token: 'attrs', foreground: '0000FF' }, | ||
{ token: 'attr.key', foreground: '#3CCDFF' }, | ||
{ token: 'attr.colon', foreground: '0000FF' } | ||
{ token: 'bonds', foreground: 'FA9246' }, | ||
{ token: 'ref', foreground: 'DC68E6', fontStyle: 'italic' }, | ||
{ token: 'bond.type', foreground: '545A7B', fontStyle: 'bold' }, | ||
{ token: 'group.typeset', foreground: 'AAAAAA', fontStyle: 'italic' }, | ||
{ token: 'group.content.typeset', foreground: 'B9E260', fontStyle: 'italic' }, | ||
{ token: 'attrs', foreground: '62C169' }, | ||
{ token: 'attr.key', foreground: '64D99D', fontStyle: 'bold' }, | ||
{ token: 'attr.colon', foreground: '89E2B5' }, | ||
{ token: 'bonds.comma', foreground: 'B7ACf0' }, | ||
{ token: 'semicolon', foreground: 'B7ACf0' } | ||
], | ||
colors: { | ||
'editor.foreground': '#000000' | ||
'editor.foreground': '#876FFF' | ||
} | ||
}); | ||
if (getFormula && markGroup) | ||
monaco.editor.addEditorAction({ | ||
id: 'cuipingFormula.markGroupInOutput', | ||
label: 'Toggle Group Mark', | ||
keybindings: [ | ||
monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyM | ||
], | ||
contextMenuGroupId: 'navigation', | ||
run: (ed) => { | ||
const model = ed.getModel(); | ||
const position = ed.getPosition(); | ||
const formula = getFormula(); | ||
if (model && position && formula) { | ||
const offset = model.getOffsetAt(position); | ||
const group = formula.groups.find(g => g.R[0] <= offset && offset <= g.R[1] + 1); | ||
if (group) | ||
markGroup(group.i); | ||
} | ||
} | ||
}); | ||
if (MonacoEnvironment) | ||
MonacoEnvironment.getWorkerUrl = () => 'data:application/javascript;base64,' | ||
+ btoa(`console.log("Mocano, I DON'T NEED ANY WORKERS, YOU KNOW?")`); | ||
return monaco; | ||
}; |
{ | ||
"name": "cuiping-monaco", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Monaco Editor extension for Cuiping formula", | ||
@@ -19,5 +19,5 @@ "main": "./dist/index.js", | ||
"build": "tsc", | ||
"prepublish": "tsc", | ||
"prepublish": "pnpm build", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
} | ||
} |
import * as Monaco from 'monaco-editor' | ||
import { GroupAttrs, BondAttrs, Attr } from 'cuiping/core/parse' | ||
import { GroupAttrs, BondAttrs, Formula } from 'cuiping/core/parse' | ||
export const getMonacoForCuiping = (monaco: typeof Monaco) => { | ||
export const getMonacoForCuiping = (monaco: typeof Monaco, { | ||
getFormula, | ||
markGroup | ||
}: { | ||
getFormula?: () => Formula | undefined, | ||
markGroup?: (groupId: number) => void | ||
}) => { | ||
monaco.languages.register({ id: 'cuipingFormula' }) | ||
@@ -13,5 +19,5 @@ | ||
[ /\{/, 'attrs', '@attrs' ], | ||
[ /[+\-|\/\\!*=#]/, 'bond.type' ], | ||
[ /[+\-|\/\\*!~=#]/, 'bond.type' ], | ||
[ /\s+/, 'space' ], | ||
[ /(?=([\^_`](.|\([^)]*?\))|[^[\]{+\-|\/\\!*=#;]+)+)/, 'group.dlmt', '@group' ], | ||
[ /(?=([\^_`](.|\([^)]*?\))|[^[\]{+\-|\/\\*!~=#;,]+)+)/, 'group.dlmt', '@group' ], | ||
[ /;/, 'semicolon' ] | ||
@@ -21,2 +27,3 @@ ], | ||
{ include: 'root' }, | ||
[ /,/, 'bonds.comma' ], | ||
[ /\]/, 'bonds', '@pop' ] | ||
@@ -44,4 +51,4 @@ ], | ||
[ /[\^_`]/, 'group.typeset', '@group-typeset' ], | ||
[ /[^[\]{+\-|\/\\!*=#;\^_`]+/, 'group.content' ], | ||
[ /(?=[[\]{+\-|\/\\!*=#;])/, 'group.dlmt', '@pop' ] | ||
[ /[^[\]{+\-|\/\\*!~=#;,\^_`]+/, 'group.content' ], | ||
[ /(?=[[\]{+\-|\/\\*!~=#;,])/, 'group.dlmt', '@pop' ] | ||
], | ||
@@ -106,3 +113,3 @@ 'group-typeset-multiple': [ | ||
if (before.match(/(?<![\^_`]({[^}]*)?)&\w*$/)) { // Note: complete ref | ||
const refNames = [ ...all.matchAll(/(&|ref):(\w+)/g) ] | ||
const refNames = [ ...all.matchAll(/(&|ref)\s*:\s*(\w+)/g) ] | ||
range.startColumn -- | ||
@@ -119,6 +126,6 @@ return { | ||
const res = before.match(/(.)\s*{([^}]*,)*[^}]+$/) | ||
const res = before.match(/(.)\s*{\s*([^}]*,)*[^:}]+$/) | ||
if (res) { | ||
if (res[1].match(/[\^_`]/)) return noSuggestions | ||
if (res[1].match(/[+\-|\/\\!*=#]/)) return { | ||
if (res[1].match(/[+\-|\/\\*!~=#]/)) return { | ||
suggestions: attrSuggestions(BondAttrs, range) | ||
@@ -139,17 +146,41 @@ } | ||
rules: [ | ||
{ token: 'bonds', foreground: '0000FF' }, | ||
{ token: 'ref', foreground: '#007F00', fontStyle: 'italic' }, | ||
{ token: 'bond.type', foreground: 'FF0000' }, | ||
{ token: 'group.typeset', foreground: 'FF9933' }, | ||
{ token: 'group.content.typeset', foreground: 'AAAAAA', fontStyle: 'italic' }, | ||
{ token: 'attrs', foreground: '0000FF' }, | ||
{ token: 'attr.key', foreground: '#3CCDFF' }, | ||
{ token: 'attr.colon', foreground: '0000FF' } | ||
{ token: 'bonds', foreground: 'FA9246' }, | ||
{ token: 'ref', foreground: 'DC68E6', fontStyle: 'italic' }, | ||
{ token: 'bond.type', foreground: '545A7B', fontStyle: 'bold' }, | ||
{ token: 'group.typeset', foreground: 'AAAAAA', fontStyle: 'italic' }, | ||
{ token: 'group.content.typeset', foreground: 'B9E260', fontStyle: 'italic' }, | ||
{ token: 'attrs', foreground: '62C169' }, | ||
{ token: 'attr.key', foreground: '64D99D', fontStyle: 'bold' }, | ||
{ token: 'attr.colon', foreground: '89E2B5' }, | ||
{ token: 'bonds.comma', foreground: 'B7ACf0' }, | ||
{ token: 'semicolon', foreground: 'B7ACf0' } | ||
], | ||
colors: { | ||
'editor.foreground': '#000000' | ||
'editor.foreground': '#876FFF' | ||
} | ||
}) | ||
if (getFormula && markGroup) monaco.editor.addEditorAction({ | ||
id: 'cuipingFormula.markGroupInOutput', | ||
label: 'Toggle Group Mark', | ||
keybindings: [ | ||
monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyM | ||
], | ||
contextMenuGroupId: 'navigation', | ||
run: (ed) => { | ||
const model = ed.getModel() | ||
const position = ed.getPosition() | ||
const formula = getFormula() | ||
if (model && position && formula) { | ||
const offset = model.getOffsetAt(position) | ||
const group = formula.groups.find(g => g.R[0] <= offset && offset <= g.R[1] + 1) | ||
if (group) markGroup(group.i) | ||
} | ||
} | ||
}) | ||
if (MonacoEnvironment) MonacoEnvironment.getWorkerUrl = () => 'data:application/javascript;base64,' | ||
+ btoa(`console.log("Mocano, I DON'T NEED ANY WORKERS, YOU KNOW?")`) | ||
return monaco | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15273
344