I'm currently trying to write an extension for Visual Studio Code, and I can't manage to understand how to read the clipboard content.
The VSCode API specifies this method:
readText ():Thenable<String>
Following what I read about Thenable
, I should be able to get the clipboard's text like that:
var clipboard_content = vscode.env.clipboard.readText().then((text)=>text);
But all I manage to get is a Promise { pending }
object.
What I would like to get is the clipboard content as a string
Click on Site Settings. Click View permissions and data stored across sites. Select the entry for the site that is associated with your VS Code server. Scroll down until you find a Clipboard permission, and select Allow from the provided dropdown menu to the right of the permission.
CodeLens lets you stay focused on your work while you find out what happened to your code–without leaving the editor. You can find references to a piece of code, changes to your code, linked bugs, work items, code reviews, and unit tests.
@:jsRequire("vscode","Uri") A universal resource identifier representing either a file on disk or another resource, like untitled resources.
Basics mistake.
Because you use promises
(async) and want async/await
(linear) functionality.
It should be (promises, async code):
vscode.env.clipboard.readText().then((text)=>{
clipboard_content = text;
/* code */
});
or (sequential code)
let clipboard_content = await vscode.env.clipboard.readText();
/* code */
PS.: In JS, you should use camelCase
instead of snake_case
when naming variables and functions. This is one of the recommendations of JavaScript Standard Style
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With