-
-
Notifications
You must be signed in to change notification settings - Fork 599
/
Copy pathvueMain.ts
104 lines (91 loc) · 3.4 KB
/
vueMain.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import * as vscode from 'vscode';
import { LanguageClient, WorkspaceEdit } from 'vscode-languageclient';
import { generateGrammarCommandHandler } from './commands/generateGrammarCommand';
import { registerLanguageConfigurations } from './languages';
import { initializeLanguageClient } from './client';
import { join } from 'path';
import {
setVirtualContents,
registerVeturTextDocumentProviders,
generateShowVirtualFileCommand
} from './commands/virtualFileCommand';
import { getGlobalSnippetDir } from './userSnippetDir';
import { generateOpenUserScaffoldSnippetFolderCommand } from './commands/openUserScaffoldSnippetFolderCommand';
export async function activate(context: vscode.ExtensionContext) {
const isInsiders = vscode.env.appName.includes('Insiders');
const globalSnippetDir = getGlobalSnippetDir(isInsiders);
/**
* Virtual file display command for debugging template interpolation
*/
context.subscriptions.push(await registerVeturTextDocumentProviders());
/**
* Custom Block Grammar generation command
*/
context.subscriptions.push(
vscode.commands.registerCommand('vetur.generateGrammar', generateGrammarCommandHandler(context.extensionPath))
);
/**
* Open custom snippet folder
*/
context.subscriptions.push(
vscode.commands.registerCommand(
'vetur.openUserScaffoldSnippetFolder',
generateOpenUserScaffoldSnippetFolderCommand(globalSnippetDir)
)
);
context.subscriptions.push(
vscode.commands.registerCommand('vetur.chooseTypeScriptRefactoring', (args: any) => {
client.sendRequest<WorkspaceEdit | undefined>('requestCodeActionEdits', args).then(edits => {
if (edits) {
vscode.workspace.applyEdit(client.protocol2CodeConverter.asWorkspaceEdit(edits)!);
}
});
})
);
registerLanguageConfigurations();
/**
* Vue Language Server Initialization
*/
const serverModule = context.asAbsolutePath(join('server', 'dist', 'vueServerMain.js'));
const client = initializeLanguageClient(serverModule, globalSnippetDir);
context.subscriptions.push(client.start());
const promise = client
.onReady()
.then(() => {
registerCustomClientNotificationHandlers(client);
registerCustomLSPCommands(context, client);
})
.catch(e => {
console.log('Client initialization failed');
});
const ts = vscode.extensions.getExtension('vscode.typescript-language-features');
if (ts) {
if (!ts.isActive) { ts.activate(); }
}
return vscode.window.withProgress(
{
title: 'Vetur initialization',
location: vscode.ProgressLocation.Window
},
() => promise
);
}
function registerCustomClientNotificationHandlers(client: LanguageClient) {
client.onNotification('$/displayInfo', (msg: string) => {
vscode.window.showInformationMessage(msg);
});
client.onNotification('$/displayWarning', (msg: string) => {
vscode.window.showWarningMessage(msg);
});
client.onNotification('$/displayError', (msg: string) => {
vscode.window.showErrorMessage(msg);
});
client.onNotification('$/showVirtualFile', (virtualFileSource: string, prettySourceMap: string) => {
setVirtualContents(virtualFileSource, prettySourceMap);
});
}
function registerCustomLSPCommands(context: vscode.ExtensionContext, client: LanguageClient) {
context.subscriptions.push(
vscode.commands.registerCommand('vetur.showCorrespondingVirtualFile', generateShowVirtualFileCommand(client))
);
}