Skip to content

Commit

Permalink
added error highlighting in script editor
Browse files Browse the repository at this point in the history
  • Loading branch information
ishubin committed Jan 10, 2025
1 parent 2075762 commit 39803d3
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 84 deletions.
98 changes: 20 additions & 78 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@
"@babel/preset-env": "^7.15.8",
"@codemirror/autocomplete": "^6.18.4",
"@codemirror/commands": "^6.7.1",
"@codemirror/lang-javascript": "^6.2.2",
"@codemirror/language": "^6.10.8",
"@codemirror/lint": "^6.8.4",
"@codemirror/state": "^6.5.0",
"@codemirror/theme-one-dark": "^6.1.2",
"@codemirror/view": "^6.36.1",
"@electron-forge/cli": "^6.0.1",
"@electron-forge/maker-deb": "^6.0.1",
Expand Down Expand Up @@ -71,6 +70,7 @@
"sanitize-html": "^2.10.0",
"shortid": "^2.2.16",
"style-loader": "^3.3.1",
"thememirror": "^2.0.1",
"tiptap": "^1.22.3",
"tiptap-extensions": "^1.22.3",
"vue": "^2.6.10",
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/SchemeEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@
<ScriptsTab v-if="currentLeftTab === 'Scripts'"
:key="`${editorId}-${schemeContainer.scheme.id}`"
:editorId="editorId"
:scheme-container="schemeContainer"
:schemeContainer="schemeContainer"
/>
</div>
</div>
Expand Down
23 changes: 20 additions & 3 deletions src/ui/components/editor/ScriptEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,27 @@ import {EditorState, Compartment} from "@codemirror/state";
import {EditorView, keymap} from "@codemirror/view";
import {SchemioScript } from "codemirror-lang-schemioscript";
import {defaultKeymap, indentWithTab} from "@codemirror/commands";
import { oneDark } from '@codemirror/theme-one-dark';
import {dracula, clouds} from 'thememirror';
import {autocompletion} from "@codemirror/autocomplete";
import {syntaxTree, indentUnit} from "@codemirror/language";
import { linter } from "@codemirror/lint";


function basicLinter(view) {
let diagnostics = [];
syntaxTree(view.state).cursor().iterate(node => {
if (node.type.isError) {
diagnostics.push({
from: node.from,
to: node.to,
severity: "error",
message: null
});
}
})
return diagnostics;
}

const keywords = `
local for while if else func struct
`.split(/\s+/).filter(name => name).map(name => {return {
Expand Down Expand Up @@ -185,7 +201,7 @@ export default {
created() {
const editorTheme = new Compartment();
let themeId = document.body.getAttribute('data-theme');
let theme = themeId === 'dark' ? oneDark : [];
let theme = themeId === 'dark' ? dracula : clouds;
this.editorState = EditorState.create({
doc: this.script,
extensions: [
Expand All @@ -195,6 +211,7 @@ export default {
keymap.of(indentWithTab),
basicSetup,
SchemioScript(),
linter(basicLinter),
editorTheme.of(theme),
EditorView.updateListener.of((v)=> {
if(v.docChanged) {
Expand All @@ -212,7 +229,7 @@ export default {

this.themeObserver = new MutationObserver(() => {
const newThemeId = document.body.getAttribute('data-theme');
const theme = newThemeId === 'dark' ? oneDark : [];
const theme = newThemeId === 'dark' ? dracula : clouds;
if (this.editor) {
this.editor.dispatch({
effects: editorTheme.reconfigure(theme)
Expand Down
1 change: 1 addition & 0 deletions src/ui/components/editor/ScriptsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
<ScriptFunctionEditor
:editorId="editorId"
:args="funcModal.props"
:schemeContainer="schemeContainer"
@argument-changed="onScriptFunctionEditorPropChange"/>
</div>
</Panel>
Expand Down

0 comments on commit 39803d3

Please sign in to comment.