Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c96eb06

Browse files
author
Kapil Borle
committedFeb 14, 2017
Add function to convert to 1-based position
1 parent 1160398 commit c96eb06

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed
 

‎src/features/DocumentFormatter.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ function toRange(scriptRegion: ScriptRegion): vscode.Range {
9090
scriptRegion.endColumnNumber - 1);
9191
}
9292

93+
function toOneBasedPosition(position: Position): Position {
94+
return position.translate({ lineDelta: 1, characterDelta: 1 });
95+
}
96+
9397
function editComparer(leftOperand: ScriptRegion, rightOperand: ScriptRegion): number {
9498
if (leftOperand.startLineNumber < rightOperand.startLineNumber) {
9599
return -1;
@@ -246,13 +250,14 @@ class PSDocumentFormattingEditProvider implements
246250
}
247251

248252
private getScriptRegion(document: TextDocument, position: Position, ch: string): Thenable<ScriptRegion> {
253+
let oneBasedPosition = toOneBasedPosition(position);
249254
return this.languageClient.sendRequest(
250255
ScriptRegionRequest.type,
251256
{
252257
fileUri: document.uri.toString(),
253258
character: ch,
254-
line: position.line + 1,
255-
column: position.character + 1
259+
line: oneBasedPosition.line,
260+
column: oneBasedPosition.character
256261
}).then((result: ScriptRegionRequestResult) => {
257262
if (result === null) {
258263
return null;
@@ -489,4 +494,4 @@ export class DocumentFormatterFeature implements IFeature {
489494
this.rangeFormattingEditProvider.dispose();
490495
this.onTypeFormattingEditProvider.dispose();
491496
}
492-
}
497+
}

0 commit comments

Comments
 (0)
Please sign in to comment.