Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically reload Visual Studio Code window?

User can achieve this by running 'Reload Window' available via editor's 'Command Palette'. That however from an extension authoring point of view is not as straight forward as prompting the user right away.

Desired outcome is to take current implementation in this pull request from [screenshot]

warning message

to [screenshot]

prompt.

like image 349
Felicio Avatar asked Oct 25 '25 08:10

Felicio


2 Answers

Once you prompt the user to confirm using vscode.window.showInformationMessage(...) to confirm, you can run vscode.commands.executeCommand("workbench.action.reloadWindow") to reload the window.

like image 148
ajshort Avatar answered Oct 26 '25 22:10

ajshort


Accepted answer posted by user ajshort was crucial to figuring out how to call arbitrary editor commands, however, tying it together with user action still wasn't clear to me.

See function bellow for resolving the user action (click).

/** Prompts user to reload editor window in order for configuration change to take effect. */
function promptToReloadWindow() {
  const action = 'Reload';

  vscode.window
    .showInformationMessage(
      `Reload window in order for change in extension \`${EXTENSION_ID}\` configuration to take effect.`,
      action
    )
    .then(selectedAction => {
      if (selectedAction === action) {
        vscode.commands.executeCommand('workbench.action.reloadWindow');
      }
    });
}
like image 45
Felicio Avatar answered Oct 26 '25 22:10

Felicio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!