Sha256: a876f873f9e4fc83bd69a67d05e28a4f847dc2ad9a1ce4bfdba7a7f5d5650072
Contents?: true
Size: 930 Bytes
Versions: 39
Compression:
Stored size: 930 Bytes
Contents
import{parser as e}from"@lezer/json";import{LRLanguage as t,indentNodeProp as r,continuedIndent as n,foldNodeProp as o,foldInside as s,LanguageSupport as a}from"@codemirror/language";const jsonParseLinter=()=>e=>{try{JSON.parse(e.state.doc.toString())}catch(t){if(!(t instanceof SyntaxError))throw t;const r=getErrorPosition(t,e.state.doc);return[{from:r,message:t.message,severity:"error",to:r}]}return[]};function getErrorPosition(e,t){let r;return(r=e.message.match(/at position (\d+)/))?Math.min(+r[1],t.length):(r=e.message.match(/at line (\d+) column (\d+)/))?Math.min(t.line(+r[1]).from+ +r[2]-1,t.length):0}const c=t.define({name:"json",parser:e.configure({props:[r.add({Object:n({except:/^\s*\}/}),Array:n({except:/^\s*\]/})}),o.add({"Object Array":s})]}),languageData:{closeBrackets:{brackets:["[","{",'"']},indentOnInput:/^\s*[\}\]]$/}});function json(){return new a(c)}export{json,c as jsonLanguage,jsonParseLinter};
Version data entries
39 entries across 39 versions & 1 rubygems