|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | import * as vscode from 'vscode'; |
4 | | -import * as telemetryContracts from "../common/telemetryContracts"; |
5 | | -import {RefactorProxy} from '../refactor/proxy'; |
6 | | -import {getWorkspaceEditsFromPatch, getTextEdits} from '../common/editor'; |
| 4 | +import { RefactorProxy } from '../refactor/proxy'; |
| 5 | +import { getWorkspaceEditsFromPatch } from '../common/editor'; |
7 | 6 | import * as path from 'path'; |
8 | | -import {PythonSettings} from '../common/configSettings'; |
| 7 | +import { PythonSettings } from '../common/configSettings'; |
9 | 8 |
|
10 | 9 | const pythonSettings = PythonSettings.getInstance(); |
11 | 10 | const EXTENSION_DIR = path.join(__dirname, '..', '..', '..'); |
@@ -14,24 +13,24 @@ interface RenameResponse { |
14 | 13 | } |
15 | 14 |
|
16 | 15 | export class PythonRenameProvider implements vscode.RenameProvider { |
| 16 | + constructor(private outputChannel: vscode.OutputChannel) { |
| 17 | + } |
17 | 18 | public provideRenameEdits(document: vscode.TextDocument, position: vscode.Position, newName: string, token: vscode.CancellationToken): Thenable<vscode.WorkspaceEdit> { |
18 | 19 | return vscode.workspace.saveAll(false).then(() => { |
19 | 20 | return this.doRename(document, position, newName, token); |
20 | 21 | }); |
21 | 22 | } |
22 | 23 |
|
23 | 24 | private doRename(document: vscode.TextDocument, position: vscode.Position, newName: string, token: vscode.CancellationToken): Thenable<vscode.WorkspaceEdit> { |
24 | | - var filename = document.fileName; |
25 | 25 | if (document.lineAt(position.line).text.match(/^\s*\/\//)) { |
26 | 26 | return; |
27 | 27 | } |
28 | 28 | if (position.character <= 0) { |
29 | 29 | return; |
30 | 30 | } |
31 | 31 |
|
32 | | - var source = document.getText(); |
33 | 32 | var range = document.getWordRangeAtPosition(position); |
34 | | - if (range == undefined || range == null || range.isEmpty) { |
| 33 | + if (!range || range.isEmpty) { |
35 | 34 | return; |
36 | 35 | } |
37 | 36 | const oldName = document.getText(range); |
@@ -40,12 +39,14 @@ export class PythonRenameProvider implements vscode.RenameProvider { |
40 | 39 | } |
41 | 40 |
|
42 | 41 | let proxy = new RefactorProxy(EXTENSION_DIR, pythonSettings, vscode.workspace.rootPath); |
43 | | - return new Promise<vscode.WorkspaceEdit>(resolve => { |
44 | | - proxy.rename<RenameResponse>(document, newName, document.uri.fsPath, range).then(response => { |
45 | | - //return response.results[0].diff; |
46 | | - const workspaceEdit = getWorkspaceEditsFromPatch(response.results.map(fileChanges => fileChanges.diff)); |
47 | | - resolve(workspaceEdit); |
48 | | - }); |
| 42 | + return proxy.rename<RenameResponse>(document, newName, document.uri.fsPath, range).then(response => { |
| 43 | + //return response.results[0].diff; |
| 44 | + const workspaceEdit = getWorkspaceEditsFromPatch(response.results.map(fileChanges => fileChanges.diff)); |
| 45 | + return workspaceEdit; |
| 46 | + }).catch(reason => { |
| 47 | + vscode.window.showErrorMessage(reason); |
| 48 | + this.outputChannel.appendLine(reason); |
| 49 | + return; |
49 | 50 | }); |
50 | 51 | } |
51 | 52 | } |