"use strict";/*!--------------------------------------------------------
 * Copyright (C) Microsoft Corporation. All rights reserved.
 *--------------------------------------------------------*/(function(){var g=["vs/workbench/services/languageDetection/browser/languageDetectionSimpleWorker","require","exports","vs/base/common/stopwatch","vs/editor/common/services/editorSimpleWorker"],p=function(f){for(var u=[],h=0,l=f.length;h<l;h++)u[h]=g[f[h]];return u};define(g[0],p([1,2,3,4]),function(f,u,h,l){"use strict";Object.defineProperty(u,"__esModule",{value:!0}),u.LanguageDetectionSimpleWorker=u.create=void 0;function v(b){return new c(b,null)}u.create=v;class c extends l.EditorSimpleWorker{constructor(){super(...arguments),this.u=!1,this.w=!1,this.x=new Map}async detectLanguage(s,n,e,r){const i=[],t=[],d=new h.StopWatch(!0),w=this.y(s);if(!w)return;const y=async()=>{for await(const a of this.D(w)){this.x.has(a.languageId)||this.x.set(a.languageId,await this.c.fhr("getLanguageId",[a.languageId]));const o=this.x.get(a.languageId);o&&(!r?.length||r.includes(o))&&(i.push(o),t.push(a.confidence))}if(d.stop(),i.length)return this.c.fhr("sendTelemetryEvent",[i,t,d.elapsed()]),i[0]},m=async()=>this.A(w,n??{},r);if(e){const a=await m();if(a)return a;const o=await y();if(o)return o}else{const a=await y();if(a)return a;const o=await m();if(o)return o}}y(s){const n=this.h(s);if(!n)return;const e=n.positionAt(1e4);return n.getValueInRange({startColumn:1,startLineNumber:1,endColumn:e.column,endLineNumber:e.lineNumber})}async z(){if(this.u)return;if(this.t)return this.t;const s=await this.c.fhr("getRegexpModelUri",[]);try{return this.t=await new Promise((n,e)=>{f([s],n,e)}),this.t}catch{this.u=!0;return}}async A(s,n,e){const r=await this.z();if(!r)return;if(e?.length)for(const t of Object.keys(n))e.includes(t)?n[t]=1:n[t]=0;return r.detect(s,n,e)}async B(){if(this.v)return this.v;const s=await this.c.fhr("getIndexJsUri",[]),{ModelOperations:n}=await new Promise((e,r)=>{f([s],e,r)});return this.v=new n({modelJsonLoaderFunc:async()=>{const e=await fetch(await this.c.fhr("getModelJsonUri",[]));try{return await e.json()}catch{const i="Failed to parse model JSON.";throw new Error(i)}},weightsLoaderFunc:async()=>await(await fetch(await this.c.fhr("getWeightsUri",[]))).arrayBuffer()}),this.v}C(s){switch(s.languageId){case"js":case"html":case"json":case"ts":case"css":case"py":case"xml":case"php":s.confidence+=c.q;break;case"cpp":case"sh":case"java":case"cs":case"c":s.confidence+=c.r;break;case"bat":case"ini":case"makefile":case"sql":case"csv":case"toml":s.confidence-=c.s;break;default:break}return s}async*D(s){if(this.w)return;let n;try{n=await this.B()}catch(t){console.log(t),this.w=!0;return}let e;try{e=await n.runModel(s)}catch(t){console.warn(t)}if(!e||e.length===0||e[0].confidence<c.p)return;const r=this.C(e[0]);if(r.confidence<c.p)return;const i=[r];for(let t of e){if(t===r)continue;if(t=this.C(t),i[i.length-1].confidence-t.confidence>=c.p){for(;i.length;)yield i.shift();if(t.confidence>c.p){i.push(t);continue}return}else{if(t.confidence>c.p){i.push(t);continue}return}}}}c.p=.2,c.q=.05,c.r=.025,c.s=.5,u.LanguageDetectionSimpleWorker=c})}).call(this);

//# sourceMappingURL=https://ticino.blob.core.windows.net/sourcemaps/ca23e219b31b75bc54777043dc532cfc2d44154d/core/vs/workbench/services/languageDetection/browser/languageDetectionSimpleWorker.js.map
