Skip to content

Commit

Permalink
feat: startup extension by open .ts file for take over mode
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Oct 14, 2021
1 parent 63e2467 commit eda4612
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions extensions/vscode-vue-language-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
],
"activationEvents": [
"onLanguage:vue",
"onLanguage:javascript",
"onLanguage:typescript",
"onLanguage:javascriptreact",
"onLanguage:typescriptreact",
"onWebviewPanel:preview"
],
"main": "node_modules/@volar/client/out/extension.js",
Expand Down
24 changes: 24 additions & 0 deletions packages/client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@ let lowPowerMode = false;

export async function activate(context: vscode.ExtensionContext) {

const stopCheck = vscode.window.onDidChangeActiveTextEditor(tryActivate);
tryActivate();

function tryActivate() {

if (!vscode.window.activeTextEditor)
return;

const currentlangId = vscode.window.activeTextEditor.document.languageId;
if (currentlangId === 'vue') {
doActivate(context);
stopCheck.dispose();
}

const takeOverMode = takeOverModeEnabled();
if (takeOverMode && ['javascript', 'typescript', 'javascriptreact', 'typescriptreact'].includes(currentlangId)) {
doActivate(context);
stopCheck.dispose();
}
}
}

async function doActivate(context: vscode.ExtensionContext) {

lowPowerMode = lowPowerModeEnabled();
if (lowPowerMode) {
vscode.window
Expand Down

0 comments on commit eda4612

Please sign in to comment.