forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyapfFormatter.ts
More file actions
21 lines (18 loc) · 1.08 KB
/
yapfFormatter.ts
File metadata and controls
21 lines (18 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
'use strict';
import * as vscode from 'vscode';
import {BaseFormatter} from './baseFormatter';
import * as settings from './../common/configSettings';
export class YapfFormatter extends BaseFormatter {
constructor(protected outputChannel: vscode.OutputChannel, protected pythonSettings: settings.IPythonSettings, protected workspaceRootPath: string) {
super('yapf', outputChannel, pythonSettings, workspaceRootPath);
}
public formatDocument(document: vscode.TextDocument, options: vscode.FormattingOptions, token: vscode.CancellationToken, range?: vscode.Range): Thenable<vscode.TextEdit[]> {
let yapfPath = this.pythonSettings.formatting.yapfPath;
let yapfArgs = Array.isArray(this.pythonSettings.formatting.yapfArgs) ? this.pythonSettings.formatting.yapfArgs : [];
yapfArgs = yapfArgs.concat(['--diff']);
if (range && !range.isEmpty) {
yapfArgs = yapfArgs.concat(['--lines', `${range.start.line + 1}-${range.end.line + 1}`]);
}
return super.provideDocumentFormattingEdits(document, options, token, yapfPath, yapfArgs);
}
}