diff --git a/extension.ts b/extension.ts index 78eff41d9..fe46d29f0 100644 --- a/extension.ts +++ b/extension.ts @@ -265,7 +265,7 @@ export async function activate(context: vscode.ExtensionContext) { } } - CommandLine.SetHistoryDirPath(context.extensionPath); + CommandLine.LoadHistory(); registerCommand(context, 'toggleVim', async () => { configuration.disableExt = !configuration.disableExt; diff --git a/src/cmd_line/commandLine.ts b/src/cmd_line/commandLine.ts index c8d67bd01..7e59bc2be 100644 --- a/src/cmd_line/commandLine.ts +++ b/src/cmd_line/commandLine.ts @@ -92,10 +92,13 @@ export class CommandLine { return cmd; } - public static SetHistoryDirPath(historyDirPath: string): void { - const path = require('path'); - const filePath: string = path.join(historyDirPath, '.cmdline_history'); - this._history.setFilePath(filePath); - this._history.load(); + public static LoadHistory(): void { + util.getExternalExtensionDirPath().then(externalExtensionDirPath => { + const path = require('path'); + const filePath: string = path.join(externalExtensionDirPath, '.cmdline_history'); + + this._history.setFilePath(filePath); + this._history.load(); + }); } } diff --git a/src/util.ts b/src/util.ts index 9d800a6e9..5575c2453 100644 --- a/src/util.ts +++ b/src/util.ts @@ -67,3 +67,22 @@ export async function allowVSCodeToPropagateCursorUpdatesAndReturnThem( x => new Range(Position.FromVSCodePosition(x.start), Position.FromVSCodePosition(x.end)) ); } + +export async function getExternalExtensionDirPath(): Promise { + return new Promise((resolve, reject) => { + const os = require('os'); + const homeDir: string = os.homedir(); + const path = require('path'); + const extensionFolder = path.join(homeDir, '.VSCodeVim'); + const fs = require('fs'); + + fs.mkdir(extensionFolder, 0o775, (err: any) => { + if (!err || err.code === 'EEXIST') { + resolve(extensionFolder); + } else { + console.log(err); + reject(err); + } + }); + }); +}