Remove reliance on document.lineAt (#154191)

* Remove reliance on document.lineAt

This helps aligning more with the LSP types: https://github.com/microsoft/vscode-languageserver-node/issues/146

* Strip newline
This commit is contained in:
Matt Bierner
2022-07-05 11:52:47 -07:00
committed by GitHub
parent 510a74fc2c
commit fc0bd9d377
9 changed files with 40 additions and 47 deletions

View File

@@ -5,14 +5,12 @@
import * as vscode from 'vscode';
import { TextDocument } from 'vscode-languageserver-textdocument';
import { ITextDocument, ITextLine } from '../types/textDocument';
import { ITextDocument } from '../types/textDocument';
export class InMemoryDocument implements ITextDocument {
private readonly _doc: TextDocument;
private lines: ITextLine[] | undefined;
constructor(
public readonly uri: vscode.Uri, contents: string,
public readonly version = 0,
@@ -25,16 +23,6 @@ export class InMemoryDocument implements ITextDocument {
return this._doc.lineCount;
}
lineAt(index: any): ITextLine {
if (!this.lines) {
this.lines = this._doc.getText().split(/\r?\n/).map(text => ({
text,
get isEmptyOrWhitespace() { return /^\s*$/.test(text); }
}));
}
return this.lines[index];
}
positionAt(offset: number): vscode.Position {
const pos = this._doc.positionAt(offset);
return new vscode.Position(pos.line, pos.character);

View File

@@ -0,0 +1,8 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export function isEmptyOrWhitespace(str: string): boolean {
return /^\s*$/.test(str);
}