Get user input from input box in visual studio code

Use vscode.window.showInputBox - the returned value will be undefined if the input box was canceled (e.g. pressing ESC). Otherwise the returned value will be the string typed by the user or an empty string if the user did not type anything but dismissed the input box with OK.

const searchQuery = await vscode.window.showInputBox({
  placeHolder: "Search query",
  prompt: "Search my snippets on Codever",
  value: selectedText
if(searchQuery === ''){
  vscode.window.showErrorMessage('A search query is mandatory to execute this action');

if(searchQuery !== undefined){
  const searchUrl = `${searchQuery}&sd=my-snippets`;

Reference -

You can see it in action in the following demo:

Search from Codever Snippets VSCode Extension Demo
Search from Codever Snippets VSCode Extension Demo

Shared with from 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Subscribe to our newsletter for more code resources and news

Adrian Matei

Adrian Matei
Life force expressing itself as a coding capable human being