3
3
activateDocumentDropEdit ,
4
4
activateServerSys ,
5
5
activateWriteVirtualFiles ,
6
+ activateTsConfigStatusItem ,
7
+ activateTsVersionStatusItem ,
6
8
getTsdk ,
7
9
} from '@volar/vscode' ;
8
10
import { DiagnosticModel , VueInitializationOptions } from '@vue/language-server' ;
@@ -24,22 +26,19 @@ type CreateLanguageClient = (
24
26
outputChannel : vscode . OutputChannel ,
25
27
) => lsp . BaseLanguageClient ;
26
28
29
+ const beginHybridMode = config . server . hybridMode ;
30
+
27
31
export async function activate ( context : vscode . ExtensionContext , createLc : CreateLanguageClient ) {
28
32
29
33
const stopCheck = vscode . window . onDidChangeActiveTextEditor ( tryActivate ) ;
30
34
tryActivate ( ) ;
31
35
32
36
function tryActivate ( ) {
33
-
34
- if ( ! vscode . window . activeTextEditor ) {
35
- // onWebviewPanel:preview
36
- doActivate ( context , createLc ) ;
37
- stopCheck . dispose ( ) ;
38
- return ;
39
- }
40
-
41
- const currentLangId = vscode . window . activeTextEditor . document . languageId ;
42
- if ( currentLangId === 'vue' || ( currentLangId === 'markdown' && config . server . vitePress . supportMdFile ) || ( currentLangId === 'html' && config . server . petiteVue . supportHtmlFile ) ) {
37
+ if (
38
+ vscode . window . visibleTextEditors . some ( editor => editor . document . languageId === 'vue' )
39
+ || ( config . server . vitePress . supportMdFile && vscode . window . visibleTextEditors . some ( editor => editor . document . languageId === 'vue' ) )
40
+ || ( config . server . petiteVue . supportHtmlFile && vscode . window . visibleTextEditors . some ( editor => editor . document . languageId === 'html' ) )
41
+ ) {
43
42
doActivate ( context , createLc ) ;
44
43
stopCheck . dispose ( ) ;
45
44
}
@@ -61,13 +60,6 @@ async function doActivate(context: vscode.ExtensionContext, createLc: CreateLang
61
60
outputChannel
62
61
) ;
63
62
64
- activateServerMaxOldSpaceSizeChange ( ) ;
65
- activateRestartRequest ( ) ;
66
- activateClientRequests ( ) ;
67
-
68
- splitEditors . register ( context , client ) ;
69
- doctor . register ( context , client ) ;
70
-
71
63
const selectors : vscode . DocumentFilter [ ] = [ { language : 'vue' } ] ;
72
64
73
65
if ( config . server . petiteVue . supportHtmlFile ) {
@@ -77,49 +69,63 @@ async function doActivate(context: vscode.ExtensionContext, createLc: CreateLang
77
69
selectors . push ( { language : 'markdown' } ) ;
78
70
}
79
71
72
+ activateConfigWatcher ( ) ;
73
+ activateRestartRequest ( ) ;
74
+
75
+ nameCasing . activate ( context , client , selectors ) ;
76
+ splitEditors . register ( context , client ) ;
77
+ doctor . register ( context , client ) ;
78
+
80
79
activateAutoInsertion ( selectors , client ) ;
81
80
activateDocumentDropEdit ( selectors , client ) ;
82
81
activateWriteVirtualFiles ( 'vue.action.writeVirtualFiles' , client ) ;
83
82
activateServerSys ( client ) ;
84
83
85
- async function requestReloadVscode ( ) {
86
- const reload = await vscode . window . showInformationMessage (
87
- 'Please reload VSCode to restart language servers.' ,
88
- 'Reload Window'
89
- ) ;
84
+ if ( ! config . server . hybridMode ) {
85
+ activateTsConfigStatusItem ( selectors , 'vue.tsconfig' , client ) ;
86
+ activateTsVersionStatusItem ( selectors , 'vue.tsversion' , context , client , text => 'TS ' + text ) ;
87
+ }
88
+
89
+ const hybridModeStatus = vscode . languages . createLanguageStatusItem ( 'vue-hybrid-mode' , selectors ) ;
90
+ hybridModeStatus . text = config . server . hybridMode ? 'Hybrid Mode: Enabled' : 'Hybrid Mode: Disabled' ;
91
+ hybridModeStatus . command = {
92
+ title : 'Open Setting' ,
93
+ command : 'workbench.action.openSettings' ,
94
+ arguments : [ 'vue.server.hybridMode' ] ,
95
+ } ;
96
+ if ( ! config . server . hybridMode ) {
97
+ hybridModeStatus . severity = vscode . LanguageStatusSeverity . Warning ;
98
+ }
99
+
100
+ async function requestReloadVscode ( msg : string ) {
101
+ const reload = await vscode . window . showInformationMessage ( msg , 'Reload Window' ) ;
90
102
if ( reload === undefined ) return ; // cancel
91
103
vscode . commands . executeCommand ( 'workbench.action.reloadWindow' ) ;
92
104
}
93
105
94
- function activateServerMaxOldSpaceSizeChange ( ) {
106
+ function activateConfigWatcher ( ) {
95
107
context . subscriptions . push ( vscode . workspace . onDidChangeConfiguration ( ( e ) => {
96
- if ( e . affectsConfiguration ( 'vue.server.runtime' ) || e . affectsConfiguration ( 'vue.server.path' ) ) {
97
- requestReloadVscode ( ) ;
108
+ if ( e . affectsConfiguration ( 'vue.server.hybridMode' ) && config . server . hybridMode !== beginHybridMode ) {
109
+ requestReloadVscode (
110
+ config . server . hybridMode
111
+ ? 'Please reload VSCode to enable Hybrid Mode.'
112
+ : 'Please reload VSCode to disable Hybrid Mode.'
113
+ ) ;
98
114
}
99
- if ( e . affectsConfiguration ( 'vue' ) ) {
115
+ else if ( e . affectsConfiguration ( 'vue' ) ) {
100
116
vscode . commands . executeCommand ( 'vue.action.restartServer' ) ;
101
117
}
102
118
} ) ) ;
103
119
}
104
120
105
121
async function activateRestartRequest ( ) {
106
122
context . subscriptions . push ( vscode . commands . registerCommand ( 'vue.action.restartServer' , async ( ) => {
107
-
108
123
await client . stop ( ) ;
109
-
110
124
outputChannel . clear ( ) ;
111
-
112
125
client . clientOptions . initializationOptions = await getInitializationOptions ( context ) ;
113
-
114
126
await client . start ( ) ;
115
-
116
- activateClientRequests ( ) ;
117
127
} ) ) ;
118
128
}
119
-
120
- function activateClientRequests ( ) {
121
- nameCasing . activate ( context , client ) ;
122
- }
123
129
}
124
130
125
131
export function deactivate ( ) : Thenable < any > | undefined {
@@ -151,6 +157,7 @@ async function getInitializationOptions(
151
157
tokenModifiers : [ ] ,
152
158
} ,
153
159
vue : {
160
+ hybridMode : beginHybridMode ,
154
161
additionalExtensions : [
155
162
...config . server . additionalExtensions ,
156
163
...! config . server . petiteVue . supportHtmlFile ? [ ] : [ 'html' ] ,
0 commit comments