Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/inlineEdits/vscode-node/utils/translations.ts
13405 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as vscode from 'vscode';
7
import { Range } from '../../../../util/vs/editor/common/core/range';
8
import { Position } from '../../../../util/vs/editor/common/core/position';
9
import { TextReplacement } from '../../../../util/vs/editor/common/core/edits/textEdit';
10
11
export function toInternalRange(range: vscode.Range): Range {
12
return new Range(range.start.line + 1, range.start.character + 1, range.end.line + 1, range.end.character + 1);
13
}
14
15
export function toExternalRange(range: Range): vscode.Range {
16
return new vscode.Range(toExternalPosition(range.getStartPosition()), toExternalPosition(range.getEndPosition()));
17
}
18
19
export function toInternalPosition(position: vscode.Position): Position {
20
return new Position(position.line + 1, position.character + 1);
21
}
22
23
export function toExternalPosition(position: Position): vscode.Position {
24
return new vscode.Position(position.lineNumber - 1, position.column - 1);
25
}
26
27
export function toInternalTextEdit(range: vscode.Range, newText: string): TextReplacement {
28
return new TextReplacement(toInternalRange(range), newText);
29
}
30
31
export function toExternalTextEdit(edit: TextReplacement): vscode.TextEdit {
32
return new vscode.TextEdit(toExternalRange(edit.range), edit.text);
33
}
34