According to the API docs, a Message box can take a second argument: an array of strings which act as actions on the message box (which normally just has a single close button/action):
https://code.visualstudio.com/docs/extensionAPI/vscode-api#_window
showInformationMessage(message: string, ...items: string[]): Thenable<string>
So I tried this:
vscode.window.showInformationMessage('hello world', ['test','taco','cheeseburger'], function(value){
console.log(value + " was clicked");
});
But this doesn't seem to work. I get the message box along with a Close button like normal. But then to the left of the close button appears to be another single button with no text or title.
Another function definition is:
showInformationMessage<T extends MessageItem>(message: string, ...items: T[]): Thenable<T>
So I tried something like this:
let message: vscode.MessageItem = { title: 'testing' };
vscode.window.showInformationMessage('hello', [message], function(value){
console.log(value + " was clicked");
});
But that doesn't seem to work either. There is a scarce amount of documentation on this so I cannot figure it out.
vscode.window
.showInformationMessage('hello', 'test', 'taco', 'cheeseburger')
.then(selection => {
console.log(selection);
});
or
vscode.window
.showInformationMessage('hello', ...['test', 'taco', 'cheeseburger'])
.then(selection => {
console.log(selection);
});
Both result in a dialog that looks like this:

来源:https://stackoverflow.com/questions/39442735/how-to-handle-click-event-in-visual-studio-code-message-box