import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{B as t,O as n,f as r,r as i}from"./dist-Cm9oLHSV.js";import{r as a}from"./dist-CyQm0xfj.js";import{t as o}from"./typescript-BjBODG6q.js";function s(e,t,n){e.getSourceFile(t)?e.updateFile(t,n):e.createFile(t,n)}var c=n.define({combine(e){return t(e,{})}});function l(){let e=!0;return i.updateListener.of(t=>{let n=t.view.state.facet(c);n&&(!t.docChanged&&!e||(e=!1,s(n.env,n.path,t.state.doc.toString()||` `)))})}var u=e(o(),1),d=`Object.Function.Array.Number.parseFloat.parseInt.Infinity.NaN.undefined.Boolean.String.Symbol.Date.Promise.RegExp.Error.JSON.Math.Intl.ArrayBuffer.Atomics.Uint8Array.Int8Array.Uint16Array.Int16Array.Uint32Array.Int32Array.Float32Array.Float64Array.Uint8ClampedArray.BigUint64Array.BigInt64Array.DataView.Map.BigInt.Set.WeakMap.WeakSet.decodeURI.decodeURIComponent.encodeURI.encodeURIComponent.escape.unescape.isFinite.isNaN.Deno.Blob.FormData.Request.Response.TextDecoder.TextEncoder.URL.URLPattern.URLSearchParams.atob.btoa.crypto.fetch.clearInterval.clearTimeout.performance.setInterval.setTimeout`.split(`.`),f=new Set([`class`,`constant`,`enum`,`function`,`interface`,`keyword`,`method`,`namespace`,`property`,`text`,`type`,`variable`]);function p(e,t){let{source:n}=e,r=t&&n[0]!=`^`,i=n[n.length-1]!=`$`;return!r&&!i?e:RegExp(`${r?`^`:``}(?:${n})${i?`$`:``}`,e.flags??(e.ignoreCase?`i`:``))}function m(e,t){let n=e.lastIndexOf(`
`,t-1)+1,r=e.indexOf(`
`,t);r===-1&&(r=e.length);let i=e.slice(n,r);return{from:n,to:r,text:i}}function h(e,t,n){let r=m(e,t),i=Math.max(r.from,t-250),a=r.text.slice(i-r.from,t-r.from),o=a.search(p(n,!1));return o<0?null:{from:i+o,to:t,text:a.slice(o)}}var g=[u.default.ScriptElementKind.warning];async function _({env:e,path:t,context:n,keepLegacyLimitationForAutocompletionSymbols:r=!0}){let{pos:i,explicit:a}=n,o=e.getSourceFile(t)?.getFullText();if(!o)return null;let s=h(o,i,/\w*/);if(s?.text||(s=h(o,i,/\./)),!s?.text&&!a)return null;let c=e.languageService.getCompletionsAtPosition(t,i,{},{});if(!c)return null;let l=c.entries.filter(e=>!g.includes(e.kind)&&(e.sortText<`15`||c.optionalReplacementSpan?.length&&(!r||d.includes(e.name)))).map(e=>{let t=-Number(e.sortText)||0,n=e.kind?String(e.kind):void 0;return n===`member`&&(n=`property`),n&&!f.has(n)&&(n=void 0),{label:e.name,type:n,boost:t}});return{from:s?s.text===`.`?s.to:s.from:i,options:l}}function v(){return async e=>{let t=e.state.facet(c);return t?_({...t,context:e}):null}}function y(e){if(e.code===7027)return`warning`;switch(e.category){case u.default.DiagnosticCategory.Error:return`error`;case u.default.DiagnosticCategory.Message:return`info`;case u.default.DiagnosticCategory.Warning:return`warning`;case u.default.DiagnosticCategory.Suggestion:return`info`}}function b(e){return!!(e.file&&typeof e.start==`number`&&typeof e.length==`number`)}function x(e){return typeof e.messageText==`string`?e.messageText:e.messageText.messageText}function S(e){let t=e.start,n=x(e);return{from:t,to:t+e.length,message:n,severity:y(e)}}function C({env:e,path:t,diagnosticCodesToIgnore:n}){if(!e.getSourceFile(t))return[];let r=e.languageService.getSyntacticDiagnostics(t),i=e.languageService.getSemanticDiagnostics(t);return[...r,...i].filter(e=>b(e)&&!n.includes(e.code)).map(S)}function w({diagnosticCodesToIgnore:e}={}){return a(async t=>{let n=t.state.facet(c);return n?C({...n,diagnosticCodesToIgnore:e||[]}):[]})}function T({env:e,path:t,pos:n}){let r=n;if(r===null)return null;let i=e.languageService.getQuickInfoAtPosition(t,r);if(!i)return null;let a=i.textSpan.start,o=e.languageService.getTypeDefinitionAtPosition(t,r)??e.languageService.getDefinitionAtPosition(t,r);return{start:a,end:a+i.textSpan.length,typeDef:o,quickInfo:i}}var E=e=>{let t=document.createElement(`div`);if(e.quickInfo?.displayParts)for(let n of e.quickInfo.displayParts){let e=t.appendChild(document.createElement(`span`));e.className=`quick-info-${n.kind}`,e.innerText=n.text}return{dom:t}};function D({renderTooltip:e=E}={}){return r(async(t,n)=>{let r=t.state.facet(c);if(!r)return null;let i=T({...r,pos:n});return i?{pos:i.start,end:i.end,create:()=>e(i,t)}:null})}export{v as tsAutocomplete,c as tsFacet,D as tsHover,w as tsLinter,l as tsSync};