microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.19k stars 29.29k forks source link

WorkspaceEdit.insert used to support inserting new lines but not anymore #105378

Closed ctf0 closed 4 years ago

ctf0 commented 4 years ago
Version: 1.49.0-insider
Commit: 4ccab0deda29628076ce1bbb17e9fef239337f21
Date: 2020-08-25T08:14:36.185Z
Electron: 9.2.0
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Darwin x64 18.7.0

Steps to Reproduce:

let file = Uri.file('path/to/file.txt')
let edit = await new WorkspaceEdit()
edit.createFile(file)
edit.insert(file, new Position(0, 0), "test\n\ncreate new line\n\ninsert")

Does this issue occur when all extensions are disabled?: Yes

jrieken commented 4 years ago

works for me. tho, you must apply the workspace edit, you makes no sense to await the new-call. My working snippet looks like this

let file = vscode.Uri.file('/Users/jrieken/Code/_samples/devfest/issues/105378/test.txt')
let edit = new vscode.WorkspaceEdit()
edit.createFile(file)
edit.insert(file, new vscode.Position(0, 0), "test\n\ncreate new line\n\ninsert")

const success = await vscode.workspace.applyEdit(edit); // This is when it happens
console.log(success)
ctf0 commented 4 years ago

works for me. tho, you must apply the workspace edit, you makes no sense to await the new-call

i reinstalled vscode and it started working, so sorry for the inconvenience & many thanks for the tip 🏆