From 8fb49605c75afb165f5ae07986e540082480e11b Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Sat, 18 Apr 2020 17:39:04 +0800 Subject: [PATCH] make sure new file loaded on rename --- package.json | 2 +- src/server/features/updatePathOnRename.ts | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 21cfea2..778d233 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "lib/index.js", "publisher": "chemzqm", "engines": { - "coc": "^0.0.69" + "coc": "^0.0.78" }, "repository": { "type": "git", diff --git a/src/server/features/updatePathOnRename.ts b/src/server/features/updatePathOnRename.ts index 3dae40b..d4347e4 100644 --- a/src/server/features/updatePathOnRename.ts +++ b/src/server/features/updatePathOnRename.ts @@ -49,28 +49,28 @@ export default class UpdateImportsOnFileRenameHandler { } const targetFile = newResource.fsPath const oldFile = oldResource.fsPath - await workspace.openResource(newResource.toString()) - // Make sure TS knows about file - await wait(100) - - let document = workspace.getDocument(newResource.toString()) + const newUri = newResource.toString() + let document = workspace.getDocument(newUri) + if (document) { + await workspace.nvim.command(`silent ${document.bufnr}bwipeout!`) + await wait(30) + } + document = await workspace.loadFile(newUri) if (!document) return - + await wait(50) const edits = await this.getEditsForFileRename( document.textDocument, oldFile, targetFile, ) if (!edits) return - if (await this.promptUser(newResource)) { await workspace.applyEdit(edits) } } private async promptUser(newResource: Uri): Promise { - const res = await workspace.nvim.call('coc#util#prompt_confirm', [`Update imports for moved file: ${newResource.fsPath} ?`]) - return res == 1 + return await workspace.showPrompt(`Update imports for moved file: ${newResource.fsPath}?`) } private async getEditsForFileRename(document: TextDocument, oldFile: string, newFile: string): Promise {