mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
create module smartly
This commit is contained in:
parent
748a4cacd2
commit
d34588bf83
12 changed files with 344 additions and 182 deletions
|
@ -113,12 +113,26 @@ export function activate(context: vscode.ExtensionContext) {
|
|||
return await vscode.tasks.executeTask(task)
|
||||
}
|
||||
})
|
||||
registerCommand('libsyntax-rust.createFile', async (uri_: string) => {
|
||||
let uri = vscode.Uri.parse(uri_)
|
||||
registerCommand('libsyntax-rust.fsEdit', async (ops: FsOp[]) => {
|
||||
let edit = new vscode.WorkspaceEdit()
|
||||
edit.createFile(uri)
|
||||
let created;
|
||||
let moved;
|
||||
for (let op of ops) {
|
||||
if (op.type == "createFile") {
|
||||
let uri = vscode.Uri.parse(op.uri!)
|
||||
edit.createFile(uri)
|
||||
created = uri
|
||||
} else if (op.type == "moveFile") {
|
||||
let src = vscode.Uri.parse(op.src!)
|
||||
let dst = vscode.Uri.parse(op.dst!)
|
||||
edit.renameFile(src, dst)
|
||||
moved = dst
|
||||
} else {
|
||||
console.error(`unknown op: ${JSON.stringify(op)}`)
|
||||
}
|
||||
}
|
||||
await vscode.workspace.applyEdit(edit)
|
||||
let doc = await vscode.workspace.openTextDocument(uri)
|
||||
let doc = await vscode.workspace.openTextDocument((created || moved)!)
|
||||
await vscode.window.showTextDocument(doc)
|
||||
})
|
||||
|
||||
|
@ -368,3 +382,10 @@ function createTask(spec: Runnable): vscode.Task {
|
|||
let t = new vscode.Task(definition, f, definition.label, TASK_SOURCE, exec, ['$rustc']);
|
||||
return t;
|
||||
}
|
||||
|
||||
interface FsOp {
|
||||
type: string;
|
||||
uri?: string;
|
||||
src?: string;
|
||||
dst?: string;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue