Skip to content

Commit 4a1a932

Browse files
committed
refactor(vscode): simplify welcome activation and execution functions
1 parent 740fd20 commit 4a1a932

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

extensions/vscode/index.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from 'reactive-vscode';
1717
import * as vscode from 'vscode';
1818
import { config } from './lib/config';
19-
import { activate as activateWelcome, executeWelcome } from './lib/welcome';
19+
import * as welcome from './lib/welcome';
2020

2121
let client: lsp.BaseLanguageClient | undefined;
2222
let needRestart = false;
@@ -40,7 +40,7 @@ for (
4040
}
4141
}
4242

43-
export const { activate, deactivate } = defineExtension(() => {
43+
export = defineExtension(() => {
4444
const context = extensionContext.value!;
4545
const volarLabs = createLabsInfo();
4646
const activeTextEditor = useActiveTextEditor();
@@ -98,10 +98,10 @@ export const { activate, deactivate } = defineExtension(() => {
9898

9999
activateAutoInsertion(selectors, client);
100100
activateDocumentDropEdit(selectors, client);
101-
activateWelcome(context);
101+
welcome.activate(context);
102102
}, { immediate: true });
103103

104-
useCommand('vue.welcome', () => executeWelcome(context));
104+
useCommand('vue.welcome', () => welcome.execute(context));
105105
useCommand('vue.action.restartServer', async () => {
106106
await executeCommand('typescript.restartTsServer');
107107
await client?.stop();
@@ -183,9 +183,9 @@ else {
183183
const extensionJsPath = require.resolve('./dist/extension.js', {
184184
paths: [tsExtension.extensionPath],
185185
});
186+
const vuePluginName = require('./package.json').contributes.typescriptServerPlugins[0].name;
186187

187-
// @ts-expect-error
188-
fs.readFileSync = (...args) => {
188+
fs.readFileSync = (...args: any[]) => {
189189
if (args[0] === extensionJsPath) {
190190
let text = readFileSync(...args) as string;
191191

@@ -194,7 +194,7 @@ else {
194194
'languages:Array.isArray(e.languages)',
195195
[
196196
'languages:',
197-
`e.name==='vue-typescript-plugin-pack'?[${
197+
`e.name==='${vuePluginName}'?[${
198198
config.server.includeLanguages
199199
.map(lang => `'${lang}'`)
200200
.join(',')
@@ -215,7 +215,6 @@ else {
215215
);
216216

217217
// sort plugins for johnsoncodehk.tsslint, zardoy.ts-essential-plugins
218-
const vuePluginName = require('./package.json').contributes.typescriptServerPlugins[0].name;
219218
text = text.replace(
220219
'"--globalPlugins",i.plugins',
221220
s => s + `.sort((a,b)=>(b.name==="${vuePluginName}"?-1:0)-(a.name==="${vuePluginName}"?-1:0))`,

extensions/vscode/lib/welcome.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ export function activate(context: vscode.ExtensionContext) {
1010
&& context.globalState.get('vue-welcome') !== welcomeVersion
1111
) {
1212
context.globalState.update('vue-welcome', welcomeVersion);
13-
vscode.commands.executeCommand('vue.welcome');
13+
execute(context);
1414
}
1515
}
1616

17-
export function executeWelcome(context: vscode.ExtensionContext) {
17+
export function execute(context: vscode.ExtensionContext) {
1818
if (panel) {
1919
panel.reveal(vscode.ViewColumn.One);
2020
return;

0 commit comments

Comments
 (0)