11import * as path from 'path' ;
22
3- import * as vscode from 'vscode' ;
43import escapeRegExp = require( 'lodash.escaperegexp' ) ;
4+ import * as vscode from 'vscode' ;
55
66import * as filepaths from './managers/filepaths' ;
77import * as fsUtils from './utils/fs' ;
@@ -12,16 +12,16 @@ import { IPluginSettings } from './types';
1212/**
1313 * Open file after duplicate action.
1414 */
15- async function openFile ( filepath : string ) {
16- const document = await vscode . workspace . openTextDocument ( filepath ) ;
15+ async function openFile ( filepath : string ) : Promise < vscode . TextEditor > {
16+ const document = await ( vscode . workspace . openTextDocument ( filepath ) as Promise < vscode . TextDocument > ) ;
1717
1818 return vscode . window . showTextDocument ( document ) ;
1919}
2020
2121/**
2222 * Duplicate action.
2323 */
24- async function duplicator ( uri : vscode . Uri , settings : IPluginSettings ) {
24+ async function duplicator ( uri : vscode . Uri , settings : IPluginSettings ) : Promise < vscode . TextEditor | undefined > {
2525 const oldPath = uri . fsPath ;
2626 const oldPathParsed = path . parse ( oldPath ) ;
2727 const oldPathStats = await fsUtils . pathStat ( oldPath ) ;
@@ -38,6 +38,7 @@ async function duplicator(uri: vscode.Uri, settings: IPluginSettings) {
3838 // If a user tries to copy a file on the same path
3939 if ( uri . fsPath === newPath ) {
4040 vscode . window . showErrorMessage ( 'You can\'t copy a file or directory on the same path.' ) ;
41+
4142 return ;
4243 }
4344
@@ -69,19 +70,20 @@ async function duplicator(uri: vscode.Uri, settings: IPluginSettings) {
6970 return ;
7071}
7172
72- export function activate ( context : vscode . ExtensionContext ) {
73+ export function activate ( context : vscode . ExtensionContext ) : void {
7374 const command = vscode . commands . registerCommand ( 'duplicate.execute' , ( uri : vscode . TextDocument | vscode . Uri ) => {
75+ const settings = vscode . workspace . getConfiguration ( ) . get ( 'duplicate' ) as IPluginSettings ;
76+
7477 if ( ! uri || ! ( < vscode . Uri > uri ) . fsPath ) {
7578 const editor = vscode . window . activeTextEditor ;
7679 if ( ! editor ) {
7780 return ;
7881 }
79- uri = editor . document . uri ;
80- }
8182
82- const settings = vscode . workspace . getConfiguration ( ) . get ( 'duplicate' ) as IPluginSettings ;
83+ return duplicator ( < vscode . Uri > editor . document . uri , settings ) ;
84+ }
8385
84- duplicator ( < vscode . Uri > uri , settings ) ;
86+ return duplicator ( < vscode . Uri > uri , settings ) ;
8587 } ) ;
8688
8789 context . subscriptions . push ( command ) ;
0 commit comments