Skip to content

Commit 34de741

Browse files
committed
refactor: use jsonParseLinter from @codemirror/lang-json
1 parent 8fa67f9 commit 34de741

File tree

3 files changed

+15
-33
lines changed

3 files changed

+15
-33
lines changed

client/modules/IDE/components/Editor/stateUtils.js

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import {
4545

4646
import { css } from '@codemirror/lang-css';
4747
import { html } from '@codemirror/lang-html';
48-
import { json } from '@codemirror/lang-json';
48+
import { json, jsonParseLinter } from '@codemirror/lang-json';
4949
import { xml } from '@codemirror/lang-xml';
5050
import { linter } from '@codemirror/lint';
5151
import { JSHINT } from 'jshint';
@@ -231,29 +231,10 @@ function makeJsLinter(callback) {
231231
}
232232

233233
function makeJsonLinter(callback) {
234+
const baseJsonLinter = jsonParseLinter();
234235
return (view) => {
235-
const documentContent = view.state.doc.toString();
236-
const diagnostics = [];
237-
238-
try {
239-
JSON.parse(documentContent);
240-
} catch (e) {
241-
let pos = 0;
242-
const match = e.message.match(/at position (\d+)/);
243-
if (match) {
244-
pos = parseInt(match[1], 10);
245-
}
246-
247-
diagnostics.push({
248-
from: pos,
249-
to: pos + 1,
250-
severity: 'error',
251-
message: e.message
252-
});
253-
}
254-
236+
const diagnostics = baseJsonLinter(view);
255237
if (callback) callback(diagnostics);
256-
257238
return diagnostics;
258239
};
259240
}

package-lock.json

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@
216216
"@babel/core": "^7.14.6",
217217
"@babel/parser": "^7.27.5",
218218
"@babel/register": "^7.14.5",
219+
"@babel/traverse": "^7.27.4",
219220
"@codemirror/autocomplete": "^6.18.6",
220221
"@codemirror/commands": "^6.8.1",
221222
"@codemirror/lang-css": "^6.3.1",
@@ -226,20 +227,19 @@
226227
"@codemirror/language": "^6.11.0",
227228
"@codemirror/lint": "^6.8.5",
228229
"@codemirror/search": "^6.5.11",
229-
"@codemirror/state": "^6.5.2",
230+
"@codemirror/state": "^6.6.0",
230231
"@codemirror/view": "^6.36.5",
231-
"@emmetio/codemirror6-plugin": "^0.4.0",
232-
"@babel/traverse": "^7.27.4",
233232
"@emmetio/codemirror-plugin": "^1.2.4",
233+
"@emmetio/codemirror6-plugin": "^0.4.0",
234234
"@gatsbyjs/webpack-hot-middleware": "^2.25.3",
235235
"@lezer/highlight": "^1.2.3",
236236
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.11",
237237
"@redux-devtools/core": "^3.11.0",
238238
"@redux-devtools/dock-monitor": "^3.0.1",
239239
"@redux-devtools/log-monitor": "^4.0.2",
240240
"@reduxjs/toolkit": "^1.9.3",
241-
"@uiw/codemirror-extensions-color": "^4.23.12",
242241
"@types/express": "^5.0.3",
242+
"@uiw/codemirror-extensions-color": "^4.23.12",
243243
"acorn": "^8.14.1",
244244
"acorn-walk": "^8.3.4",
245245
"async": "^3.2.3",

0 commit comments

Comments
 (0)