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

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