make sure new file loaded on rename
This commit is contained in:
parent
41eeb3330d
commit
8fb49605c7
2 changed files with 10 additions and 10 deletions
|
@ -5,7 +5,7 @@
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"publisher": "chemzqm",
|
"publisher": "chemzqm",
|
||||||
"engines": {
|
"engines": {
|
||||||
"coc": "^0.0.69"
|
"coc": "^0.0.78"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
|
@ -49,28 +49,28 @@ export default class UpdateImportsOnFileRenameHandler {
|
||||||
}
|
}
|
||||||
const targetFile = newResource.fsPath
|
const targetFile = newResource.fsPath
|
||||||
const oldFile = oldResource.fsPath
|
const oldFile = oldResource.fsPath
|
||||||
await workspace.openResource(newResource.toString())
|
const newUri = newResource.toString()
|
||||||
// Make sure TS knows about file
|
let document = workspace.getDocument(newUri)
|
||||||
await wait(100)
|
if (document) {
|
||||||
|
await workspace.nvim.command(`silent ${document.bufnr}bwipeout!`)
|
||||||
let document = workspace.getDocument(newResource.toString())
|
await wait(30)
|
||||||
|
}
|
||||||
|
document = await workspace.loadFile(newUri)
|
||||||
if (!document) return
|
if (!document) return
|
||||||
|
await wait(50)
|
||||||
const edits = await this.getEditsForFileRename(
|
const edits = await this.getEditsForFileRename(
|
||||||
document.textDocument,
|
document.textDocument,
|
||||||
oldFile,
|
oldFile,
|
||||||
targetFile,
|
targetFile,
|
||||||
)
|
)
|
||||||
if (!edits) return
|
if (!edits) return
|
||||||
|
|
||||||
if (await this.promptUser(newResource)) {
|
if (await this.promptUser(newResource)) {
|
||||||
await workspace.applyEdit(edits)
|
await workspace.applyEdit(edits)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async promptUser(newResource: Uri): Promise<boolean> {
|
private async promptUser(newResource: Uri): Promise<boolean> {
|
||||||
const res = await workspace.nvim.call('coc#util#prompt_confirm', [`Update imports for moved file: ${newResource.fsPath} ?`])
|
return await workspace.showPrompt(`Update imports for moved file: ${newResource.fsPath}?`)
|
||||||
return res == 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getEditsForFileRename(document: TextDocument, oldFile: string, newFile: string): Promise<WorkspaceEdit> {
|
private async getEditsForFileRename(document: TextDocument, oldFile: string, newFile: string): Promise<WorkspaceEdit> {
|
||||||
|
|
Loading…
Reference in a new issue