Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sketchbuch/777dfab2193da8cc74400872eedc8f1e to your computer and use it in GitHub Desktop.
Save sketchbuch/777dfab2193da8cc74400872eedc8f1e to your computer and use it in GitHub Desktop.
VSC - How to detect a change of the langauge used by the active editor in a VSC Extension
// Called when active editor language is changed:
// After the active editor language changes the content is "re-opened" so just listen for the open event
// And check the lang of the active editor
vscode.workspace.onDidOpenTextDocument(() => {
const editor = vscode.window.activeTextEditor
if (editor !== undefined) {
const {
document: { languageId },
} = editor;
if (languageId.indexOf('javascript') === 0) {
// Do something...
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment