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

//# sourceMappingURL=https://main.vscode-cdn.net/sourcemaps/21b1e2955ddda36eeba3a94e643128e465285b93/core/vs/workbench/services/languageDetection/browser/languageDetectionSimpleWorker.js.map
