class t{constructor(t,e,n,r){this._uri=t,this._languageId=e,this._version=n,this._content=r,this._lineOffsets=void 0}get uri(){return this._uri}get languageId(){return this._languageId}get version(){return this._version}getText(t){if(t){const e=this.offsetAt(t.start),n=this.offsetAt(t.end);return this._content.substring(e,n)}return this._content}update(e,n){for(const s of e)if(t.isIncremental(s)){const t=i(s.range),e=this.offsetAt(t.start),n=this.offsetAt(t.end);this._content=this._content.substring(0,e)+s.text+this._content.substring(n,this._content.length);const o=Math.max(t.start.line,0),c=Math.max(t.end.line,0);let h=this._lineOffsets;const a=r(s.text,!1,e);if(c-o===a.length)for(let r=0,s=a.length;r<s;r++)h[r+o+1]=a[r];else a.length<1e4?h.splice(o+1,c-o,...a):this._lineOffsets=h=h.slice(0,o+1).concat(a,h.slice(c+1));const f=s.text.length-(n-e);if(0!==f)for(let r=o+1+a.length,s=h.length;r<s;r++)h[r]=h[r]+f}else{if(!t.isFull(s))throw new Error("Unknown change event received");this._content=s.text,this._lineOffsets=void 0}this._version=n}getLineOffsets(){return void 0===this._lineOffsets&&(this._lineOffsets=r(this._content,!0)),this._lineOffsets}positionAt(t){t=Math.max(Math.min(t,this._content.length),0);const e=this.getLineOffsets();let n=0,r=e.length;if(0===r)return{line:0,character:t};for(;n<r;){const s=Math.floor((n+r)/2);e[s]>t?r=s:n=s+1}const s=n-1;return{line:s,character:(t=this.ensureBeforeEOL(t,e[s]))-e[s]}}offsetAt(t){const e=this.getLineOffsets();if(t.line>=e.length)return this._content.length;if(t.line<0)return 0;const n=e[t.line];if(t.character<=0)return n;const r=t.line+1<e.length?e[t.line+1]:this._content.length,s=Math.min(n+t.character,r);return this.ensureBeforeEOL(s,n)}ensureBeforeEOL(t,e){for(;t>e&&s(this._content.charCodeAt(t-1));)t--;return t}get lineCount(){return this.getLineOffsets().length}static isIncremental(t){const e=t;return null!=e&&"string"==typeof e.text&&void 0!==e.range&&(void 0===e.rangeLength||"number"==typeof e.rangeLength)}static isFull(t){const e=t;return null!=e&&"string"==typeof e.text&&void 0===e.range&&void 0===e.rangeLength}}var e;function n(t,e){if(t.length<=1)return t;const r=t.length/2|0,s=t.slice(0,r),i=t.slice(r);n(s,e),n(i,e);let o=0,c=0,h=0;for(;o<s.length&&c<i.length;){const n=e(s[o],i[c]);t[h++]=n<=0?s[o++]:i[c++]}for(;o<s.length;)t[h++]=s[o++];for(;c<i.length;)t[h++]=i[c++];return t}function r(t,e,n=0){const r=e?[n]:[];for(let i=0;i<t.length;i++){const e=t.charCodeAt(i);s(e)&&(13===e&&i+1<t.length&&10===t.charCodeAt(i+1)&&i++,r.push(n+i+1))}return r}function s(t){return 13===t||10===t}function i(t){const e=t.start,n=t.end;return e.line>n.line||e.line===n.line&&e.character>n.character?{start:n,end:e}:t}function o(t){const e=i(t.range);return e!==t.range?{newText:t.newText,range:e}:t}!function(e){e.create=function(e,n,r,s){return new t(e,n,r,s)},e.update=function(e,n,r){if(e instanceof t)return e.update(n,r),e;throw new Error("TextDocument.update: document must be created by TextDocument.create")},e.applyEdits=function(t,e){const r=t.getText(),s=n(e.map(o),(t,e)=>{const n=t.range.start.line-e.range.start.line;return 0===n?t.range.start.character-e.range.start.character:n});let i=0;const c=[];for(const n of s){const e=t.offsetAt(n.range.start);if(e<i)throw new Error("Overlapping edit");e>i&&c.push(r.substring(i,e)),n.newText.length&&c.push(n.newText),i=t.offsetAt(n.range.end)}return c.push(r.substr(i)),c.join("")}}(e||(e={}));export{e as T};
