11'use strict' ;
22
33import * 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' ;
76import * as path from 'path' ;
8- import { PythonSettings } from '../common/configSettings' ;
7+ import { PythonSettings } from '../common/configSettings' ;
98
109const pythonSettings = PythonSettings . getInstance ( ) ;
1110const EXTENSION_DIR = path . join ( __dirname , '..' , '..' , '..' ) ;
@@ -14,24 +13,24 @@ interface RenameResponse {
1413}
1514
1615export class PythonRenameProvider implements vscode . RenameProvider {
16+ constructor ( private outputChannel : vscode . OutputChannel ) {
17+ }
1718 public provideRenameEdits ( document : vscode . TextDocument , position : vscode . Position , newName : string , token : vscode . CancellationToken ) : Thenable < vscode . WorkspaceEdit > {
1819 return vscode . workspace . saveAll ( false ) . then ( ( ) => {
1920 return this . doRename ( document , position , newName , token ) ;
2021 } ) ;
2122 }
2223
2324 private doRename ( document : vscode . TextDocument , position : vscode . Position , newName : string , token : vscode . CancellationToken ) : Thenable < vscode . WorkspaceEdit > {
24- var filename = document . fileName ;
2525 if ( document . lineAt ( position . line ) . text . match ( / ^ \s * \/ \/ / ) ) {
2626 return ;
2727 }
2828 if ( position . character <= 0 ) {
2929 return ;
3030 }
3131
32- var source = document . getText ( ) ;
3332 var range = document . getWordRangeAtPosition ( position ) ;
34- if ( range == undefined || range == null || range . isEmpty ) {
33+ if ( ! range || range . isEmpty ) {
3534 return ;
3635 }
3736 const oldName = document . getText ( range ) ;
@@ -40,12 +39,14 @@ export class PythonRenameProvider implements vscode.RenameProvider {
4039 }
4140
4241 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 ;
4950 } ) ;
5051 }
5152}
0 commit comments