DEV Community

Adrian Matei for Codever

Posted on β€’ Edited on β€’ Originally published at codever.land

5

Get user input value 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 === ''){
  console.log(searchQuery);
  vscode.window.showErrorMessage('A search query is mandatory to execute this action');
}

if(searchQuery !== undefined){
  const searchUrl = `https://www.codever.land/search?q=${searchQuery}&sd=my-snippets`;
  vscode.env.openExternal(Uri.parse(searchUrl));
}
Enter fullscreen mode Exit fullscreen mode

You can see it in action below:

vs-code-extension-search


The whole source for the Codever Snippets VSCode extension on Github.


Shared with ❀️ from Codever.   πŸ‘‰ use the copy to mine functionality to add it to your personal snippets collection.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

πŸ‘‹ Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay