import{parser}from"@lezer/json";import{LRLanguage,indentNodeProp,continuedIndent,foldNodeProp,foldInside,LanguageSupport}from"@codemirror/language";const jsonParseLinter=()=>e=>{try{JSON.parse(e.state.doc.toString())}catch(n){if(!(n instanceof SyntaxError))throw n;const r=getErrorPosition(n,e.state.doc);return[{from:r,message:n.message,severity:"error",to:r}]}return[]};function getErrorPosition(e,n){let r;return(r=e.message.match(/at position (\d+)/))?Math.min(+r[1],n.length):(r=e.message.match(/at line (\d+) column (\d+)/))?Math.min(n.line(+r[1]).from+ +r[2]-1,n.length):0}const jsonLanguage=LRLanguage.define({parser:parser.configure({props:[indentNodeProp.add({Object:continuedIndent({except:/^\s*\}/}),Array:continuedIndent({except:/^\s*\]/})}),foldNodeProp.add({"Object Array":foldInside})]}),languageData:{closeBrackets:{brackets:["[","{",'"']},indentOnInput:/^\s*[\}\]]$/}});function json(){return new LanguageSupport(jsonLanguage)}export{json,jsonLanguage,jsonParseLinter};