From 7259f69c9e9342a8f8b0eb53235fd877c81628c1 Mon Sep 17 00:00:00 2001 From: Adham Farrag Date: Wed, 24 Jan 2024 05:24:56 +0800 Subject: [PATCH] feat: Volar TakeOver Mode watcher --- src/extension.ts | 7 +++++-- src/watchers/index.ts | 4 +++- src/watchers/vscode.ts | 29 +++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 src/watchers/vscode.ts diff --git a/src/extension.ts b/src/extension.ts index 7205373..4b7f7cf 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,11 +1,11 @@ -import { window, ExtensionContext, commands, Uri } from 'vscode'; +import { window, ExtensionContext, commands, Uri, extensions } from 'vscode'; import nuxtrCommands from './commands' import { ModulesView } from './sideBar' import { logger, updateDependencies } from './utils'; import codelens from './codelens' import { statusBars, activateStatusBarIcons } from './statusBar' import { activateIntellisense } from './intellisense' -import { filesWatcher } from './watchers' +import { filesWatcher, checkTakeOverMode } from './watchers' const extensionCommands = [ { command: 'nuxtr.createPage', function: nuxtrCommands.createPage }, @@ -96,6 +96,9 @@ export async function activateExtension(context: ExtensionContext) { // activate codelens codelens.activateCodelenses(context) + // checkTakeOverMode + checkTakeOverMode() + extensionCommands.forEach(({ command, function: commandFunction }) => { context.subscriptions.push(commands.registerCommand(command, commandFunction)); }); diff --git a/src/watchers/index.ts b/src/watchers/index.ts index aa223ee..f0144fd 100644 --- a/src/watchers/index.ts +++ b/src/watchers/index.ts @@ -1,9 +1,11 @@ import filesWatcher from './files' import { snippetsConfigWatcher, templatesConfigWatcher, piniaConfigWatcher } from './config' +import { checkTakeOverMode} from './vscode' export { filesWatcher, snippetsConfigWatcher, templatesConfigWatcher, - piniaConfigWatcher + piniaConfigWatcher, + checkTakeOverMode } diff --git a/src/watchers/vscode.ts b/src/watchers/vscode.ts new file mode 100644 index 0000000..7cf749e --- /dev/null +++ b/src/watchers/vscode.ts @@ -0,0 +1,29 @@ +import { extensions, window , commands} from "vscode"; +import { openExternalLink, isNuxtTwo } from "../utils"; + +const checkTakeOverMode = async () => { + const tsExtension = extensions.getExtension('vscode.typescript-language-features') + console.log('tsExtension', tsExtension); + + if (tsExtension !== undefined && !isNuxtTwo()) { + const message = await window.showWarningMessage( + `Volar's TakeOver mode is not enabled`, 'Enable', 'Learn More' + ) + + if (message === 'Learn More') { + openExternalLink('https://nuxt.com/docs/getting-started/installation#prerequisites') + } + + if (message === 'Enable') { + await commands.executeCommand('workbench.view.extensions'); + await commands.executeCommand('workbench.extensions.action.showExtensionsWithIds', ['vscode.typescript-language-features']); + await commands.executeCommand( + 'workbench.extensions.action.enableExtension', + 'vscode.typescript-language-features' + ) + } + } +} + + +export { checkTakeOverMode } \ No newline at end of file