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
25 lines (22 loc) · 1.28 KB
/
yapfFormatter.ts
File metadata and controls
25 lines (22 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
'use strict';
import * as vscode from 'vscode';
import { BaseFormatter } from './baseFormatter';
import * as settings from './../common/configSettings';
import { Product } from '../common/installer';
import * as path from 'path';
export class YapfFormatter extends BaseFormatter {
constructor(outputChannel: vscode.OutputChannel, pythonSettings: settings.IPythonSettings, workspaceRootPath?: string) {
super('yapf', Product.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}`]);
}
// Yapf starts looking for config file starting from the file path
let cwd = path.dirname(document.fileName);
return super.provideDocumentFormattingEdits(document, options, token, yapfPath, yapfArgs, cwd);
}
}