mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-26 00:16:51 +00:00
Implement renaming files
This commit is contained in:
@@ -132,7 +132,7 @@ export class SpyglassService {
|
||||
|
||||
public async writeFile(uri: string, content: string) {
|
||||
const document = this.client.documents.get(uri)
|
||||
if (document !== undefined) {
|
||||
if (document) {
|
||||
document.undoStack.push(document.doc.getText())
|
||||
document.redoStack = []
|
||||
TextDocument.update(document.doc, [{ text: content }], document.doc.version + 1)
|
||||
@@ -143,6 +143,21 @@ export class SpyglassService {
|
||||
}
|
||||
}
|
||||
|
||||
public async renameFile(oldUri: string, newUri: string) {
|
||||
const content = await this.readFile(oldUri)
|
||||
if (!content) {
|
||||
throw new Error(`Cannot rename nonexistent file ${oldUri}`)
|
||||
}
|
||||
await this.service.project.externals.fs.writeFile(newUri, content)
|
||||
await this.service.project.externals.fs.unlink(oldUri)
|
||||
const d = this.client.documents.get(oldUri)
|
||||
if (d) {
|
||||
const doc = TextDocument.create(newUri, d.doc.languageId, d.doc.version, d.doc.getText())
|
||||
this.client.documents.set(newUri, { ...d, doc })
|
||||
this.client.documents.delete(oldUri)
|
||||
}
|
||||
}
|
||||
|
||||
public async applyEdit(uri: string, edit: (node: core.FileNode<core.AstNode>) => void) {
|
||||
const document = this.client.documents.get(uri)
|
||||
if (document !== undefined) {
|
||||
|
||||
Reference in New Issue
Block a user