From 8fa67f9c40b000c0458cda617f7e9e901e270303 Mon Sep 17 00:00:00 2001 From: Geethegreat <86944224+Geethegreat@users.noreply.github.com> Date: Thu, 29 Jan 2026 23:23:08 +0530 Subject: [PATCH 1/2] Add JSON syntax linting to CodeMirror v6 editor --- .../IDE/components/Editor/stateUtils.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/client/modules/IDE/components/Editor/stateUtils.js b/client/modules/IDE/components/Editor/stateUtils.js index 32ac339abd..a8b069bc23 100644 --- a/client/modules/IDE/components/Editor/stateUtils.js +++ b/client/modules/IDE/components/Editor/stateUtils.js @@ -230,6 +230,34 @@ function makeJsLinter(callback) { }; } +function makeJsonLinter(callback) { + return (view) => { + const documentContent = view.state.doc.toString(); + const diagnostics = []; + + try { + JSON.parse(documentContent); + } catch (e) { + let pos = 0; + const match = e.message.match(/at position (\d+)/); + if (match) { + pos = parseInt(match[1], 10); + } + + diagnostics.push({ + from: pos, + to: pos + 1, + severity: 'error', + message: e.message + }); + } + + if (callback) callback(diagnostics); + + return diagnostics; + }; +} + function getFileLinter(fileName, callback) { const fileMode = getFileMode(fileName); @@ -240,6 +268,8 @@ function getFileLinter(fileName, callback) { return linter(makeHtmlLinter(callback)); case 'css': return linter(makeCssLinter(callback)); + case 'application/json': + return linter(makeJsonLinter(callback)); default: return null; } From 34de741739df6cbcdc4c735648bb4b48e5fb1ac0 Mon Sep 17 00:00:00 2001 From: Geethegreat <86944224+Geethegreat@users.noreply.github.com> Date: Sun, 22 Mar 2026 08:55:01 +0530 Subject: [PATCH 2/2] refactor: use jsonParseLinter from @codemirror/lang-json --- .../IDE/components/Editor/stateUtils.js | 25 +++---------------- package-lock.json | 15 +++++------ package.json | 8 +++--- 3 files changed, 15 insertions(+), 33 deletions(-) diff --git a/client/modules/IDE/components/Editor/stateUtils.js b/client/modules/IDE/components/Editor/stateUtils.js index a8b069bc23..07222a5faa 100644 --- a/client/modules/IDE/components/Editor/stateUtils.js +++ b/client/modules/IDE/components/Editor/stateUtils.js @@ -45,7 +45,7 @@ import { import { css } from '@codemirror/lang-css'; import { html } from '@codemirror/lang-html'; -import { json } from '@codemirror/lang-json'; +import { json, jsonParseLinter } from '@codemirror/lang-json'; import { xml } from '@codemirror/lang-xml'; import { linter } from '@codemirror/lint'; import { JSHINT } from 'jshint'; @@ -231,29 +231,10 @@ function makeJsLinter(callback) { } function makeJsonLinter(callback) { + const baseJsonLinter = jsonParseLinter(); return (view) => { - const documentContent = view.state.doc.toString(); - const diagnostics = []; - - try { - JSON.parse(documentContent); - } catch (e) { - let pos = 0; - const match = e.message.match(/at position (\d+)/); - if (match) { - pos = parseInt(match[1], 10); - } - - diagnostics.push({ - from: pos, - to: pos + 1, - severity: 'error', - message: e.message - }); - } - + const diagnostics = baseJsonLinter(view); if (callback) callback(diagnostics); - return diagnostics; }; } diff --git a/package-lock.json b/package-lock.json index 495af02afa..238e4d3512 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,7 +25,7 @@ "@codemirror/language": "^6.11.0", "@codemirror/lint": "^6.8.5", "@codemirror/search": "^6.5.11", - "@codemirror/state": "^6.5.2", + "@codemirror/state": "^6.6.0", "@codemirror/view": "^6.36.5", "@emmetio/codemirror-plugin": "^1.2.4", "@emmetio/codemirror6-plugin": "^0.4.0", @@ -6664,9 +6664,10 @@ } }, "node_modules/@codemirror/state": { - "version": "6.5.2", - "resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.5.2.tgz", - "integrity": "sha512-FVqsPqtPWKVVL3dPSxy8wEF/ymIEuVzF1PK3VbUgrxXpJUSHQWWZz4JMToquRxnkw+36LTamCZG2iua2Ptq0fA==", + "version": "6.6.0", + "resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.6.0.tgz", + "integrity": "sha512-4nbvra5R5EtiCzr9BTHiTLc+MLXK2QGiAVYMyi8PkQd3SR+6ixar/Q/01Fa21TBIDOZXgeWV4WppsQolSreAPQ==", + "license": "MIT", "dependencies": { "@marijn/find-cluster-break": "^1.0.0" } @@ -44192,9 +44193,9 @@ } }, "@codemirror/state": { - "version": "6.5.2", - "resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.5.2.tgz", - "integrity": "sha512-FVqsPqtPWKVVL3dPSxy8wEF/ymIEuVzF1PK3VbUgrxXpJUSHQWWZz4JMToquRxnkw+36LTamCZG2iua2Ptq0fA==", + "version": "6.6.0", + "resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.6.0.tgz", + "integrity": "sha512-4nbvra5R5EtiCzr9BTHiTLc+MLXK2QGiAVYMyi8PkQd3SR+6ixar/Q/01Fa21TBIDOZXgeWV4WppsQolSreAPQ==", "requires": { "@marijn/find-cluster-break": "^1.0.0" } diff --git a/package.json b/package.json index 3e70f9beec..3a36b8824c 100644 --- a/package.json +++ b/package.json @@ -216,6 +216,7 @@ "@babel/core": "^7.14.6", "@babel/parser": "^7.27.5", "@babel/register": "^7.14.5", + "@babel/traverse": "^7.27.4", "@codemirror/autocomplete": "^6.18.6", "@codemirror/commands": "^6.8.1", "@codemirror/lang-css": "^6.3.1", @@ -226,11 +227,10 @@ "@codemirror/language": "^6.11.0", "@codemirror/lint": "^6.8.5", "@codemirror/search": "^6.5.11", - "@codemirror/state": "^6.5.2", + "@codemirror/state": "^6.6.0", "@codemirror/view": "^6.36.5", - "@emmetio/codemirror6-plugin": "^0.4.0", - "@babel/traverse": "^7.27.4", "@emmetio/codemirror-plugin": "^1.2.4", + "@emmetio/codemirror6-plugin": "^0.4.0", "@gatsbyjs/webpack-hot-middleware": "^2.25.3", "@lezer/highlight": "^1.2.3", "@pmmmwh/react-refresh-webpack-plugin": "^0.5.11", @@ -238,8 +238,8 @@ "@redux-devtools/dock-monitor": "^3.0.1", "@redux-devtools/log-monitor": "^4.0.2", "@reduxjs/toolkit": "^1.9.3", - "@uiw/codemirror-extensions-color": "^4.23.12", "@types/express": "^5.0.3", + "@uiw/codemirror-extensions-color": "^4.23.12", "acorn": "^8.14.1", "acorn-walk": "^8.3.4", "async": "^3.2.3",