How to programmatically reload Visual Studio Code window?

☆樱花仙子☆ 提交于 2019-12-11 15:37:20

问题


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]

to [screenshot]

.


回答1:


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.




回答2:


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');
      }
    });
}


来源:https://stackoverflow.com/questions/47126031/how-to-programmatically-reload-visual-studio-code-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!