Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applying SnippetTextEdits don't put the editor into snippet mode #162073

Closed
joyceerhl opened this issue Sep 27, 2022 · 3 comments
Closed

Applying SnippetTextEdits don't put the editor into snippet mode #162073

joyceerhl opened this issue Sep 27, 2022 · 3 comments
Assignees

Comments

@joyceerhl
Copy link
Contributor

Testing #161809

  1. Have the following code in a command
		const edit = new vscode.WorkspaceEdit();
		const file = vscode.Uri.joinPath(vscode.workspace.workspaceFolders![0].uri, 'test.md');
		await vscode.window.showTextDocument(file);
		const pos = new vscode.Position(0, 0);
		const snip1 = new vscode.SnippetTextEdit(new vscode.Range(pos, pos), new vscode.SnippetString('foo'));
		const snip2 = new vscode.SnippetTextEdit(new vscode.Range(pos, pos), new vscode.SnippetString('bar'));
		edit.set(file, [snip1, snip2]);
		vscode.workspace.applyEdit(edit);
  1. Create an empty file called test.md in the root of your folder
  2. Run the command
  3. 🐛 editor is not put into snippet mode, edits are applied as though the file was not open in the active editor
@jrieken
Copy link
Member

jrieken commented Sep 28, 2022

empty file called test.md in the root of your folder

The editor for the file needs to be open at the time of submitting the edits. That's the current limitation because while we prepare the edits we decide to use editor-based text editing or not. The fact that an editor eventually opens in only due to workbench logic that auto-reveals unsaved files

@joyceerhl
Copy link
Contributor Author

Oh to clarify, I was able to repro this behavior even when the file being edited was open in the active editor.

@jrieken
Copy link
Member

jrieken commented Dec 5, 2022

Got the time to look into this. The issue is that the snippet edits from above aren't actually triggering snippet mode, now placeholder etc are being used so this is effectively a "normal" edit. Using something like below works fine for me. Please reopen if it doesn't work for you

const snip1 = new vscode.SnippetTextEdit(new vscode.Range(pos, pos), new vscode.SnippetString('f$1oo'));
const snip2 = new vscode.SnippetTextEdit(new vscode.Range(pos, pos), new vscode.SnippetString(`b$1a\${2:hehe}r`));

@jrieken jrieken closed this as completed Dec 5, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jan 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants