mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 02:28:34 +01:00
- Use `vscode-languageserver-textdocument` instead of custom impl - Reuse `InMemoryDocument` across tests and working code - Use `SkinnyTextDocument` in more places - Fixes some test errors that seem to be caused by bad `InMemoryDocument` impl
38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
import * as os from 'os';
|
|
import * as vscode from 'vscode';
|
|
import { InMemoryDocument } from '../util/inMemoryDocument';
|
|
|
|
export const joinLines = (...args: string[]) =>
|
|
args.join(os.platform() === 'win32' ? '\r\n' : '\n');
|
|
|
|
export const noopToken = new class implements vscode.CancellationToken {
|
|
_onCancellationRequestedEmitter = new vscode.EventEmitter<void>();
|
|
onCancellationRequested = this._onCancellationRequestedEmitter.event;
|
|
|
|
get isCancellationRequested() { return false; }
|
|
};
|
|
|
|
export const CURSOR = '$$CURSOR$$';
|
|
|
|
export function getCursorPositions(contents: string, doc: InMemoryDocument): vscode.Position[] {
|
|
let positions: vscode.Position[] = [];
|
|
let index = 0;
|
|
let wordLength = 0;
|
|
while (index !== -1) {
|
|
index = contents.indexOf(CURSOR, index + wordLength);
|
|
if (index !== -1) {
|
|
positions.push(doc.positionAt(index));
|
|
}
|
|
wordLength = CURSOR.length;
|
|
}
|
|
return positions;
|
|
}
|
|
|
|
export function workspaceFile(...segments: string[]): vscode.Uri {
|
|
return vscode.Uri.joinPath(vscode.workspace.workspaceFolders![0].uri, ...segments);
|
|
}
|