import { Position , TextDocument } from 'vscode-languageserver' ; import { getLineOffsets , offsetAt , positionAt } from './utils' ; /**
 * Represents a textual document.
 */ export abstract class ReadableDocument implements TextDocument { /**
     * Get the text content of the document
     */ abstract getText ( ) ; /**
     * Returns the url of the document
     */ abstract getURL ( ) ; /**
     * Returns the file path if the url scheme is file
     */ abstract getFilePath ( ) ; /**
     * Current version of the document.
     */ public version = 0 ; /**
     * Should be cleared when there's an update to the text
     */ protected lineOffsets ? : number [ ] ; /**
     * Get the length of the document's content
     */ getTextLength ( ) { return this . getText ( ) . length ; } param offset positionAt ( offset ) { return positionAt ( offset , this . getText ( ) , this . getLineOffsets ( ) ) ; } param position offsetAt ( position ) { return offsetAt ( position , this . getText ( ) , this . getLineOffsets ( ) ) ; } private getLineOffsets ( ) { if ( ! this . lineOffsets ) { this . lineOffsets = getLineOffsets ( this . getText ( ) ) ; } return this . lineOffsets ; } /**
     * Implements TextDocument
     */ get uri ( ) : string { return this . getURL ( ) ; } get lineCount ( ) : number { return this . getText ( ) . split ( /\r?\n/ ) . length ; } abstract languageId : string ; } /**
 * Represents a textual document that can be manipulated.
 */ export abstract class WritableDocument extends ReadableDocument { param text abstract setText ( text ) ; param text param start param end update ( text , start , end ) { this . lineOffsets = undefined ; const content = this . getText ( ) ; this . setText ( content . slice ( 0 , start ) + text + content . slice ( end ) ) ; } }