2
2
// will be required from ./node_modules/typescript-essential-plugins/index.js
3
3
const originalPluginFactory = require ( 'typescript-essential-plugins' )
4
4
5
- const plugin = ( context => {
5
+ const plugin = ( ( context , { typescript : tsModule } = { } ) => {
6
+ if ( ! context ) throw new Error ( 'Not recieve context' )
6
7
const { typescript } = context
7
- let configurationHost = context . configurationHost !
8
- configurationHost ?? = context [ 'env' ] . configurationHost
8
+ let configurationHost = context . env
9
+ if ( context [ ' configurationHost' ] ! ) configurationHost = context [ 'configurationHost' ] !
9
10
const patchConfig = config => {
10
11
return {
11
12
...config ,
@@ -17,13 +18,14 @@ const plugin = (context => {
17
18
}
18
19
19
20
if ( typescript && configurationHost ) {
21
+ const ts = tsModule ?? typescript [ 'module' ]
20
22
const plugin = originalPluginFactory ( {
21
- typescript : typescript . module ,
23
+ typescript : ts ,
22
24
} )
23
25
// todo support vue-specific settings
24
26
const originalLsMethods = { ...typescript . languageService }
25
27
26
- void configurationHost . getConfiguration < any > ( 'tsEssentialPlugins' ) . then ( _configuration => {
28
+ void configurationHost . getConfiguration ! < any > ( 'tsEssentialPlugins' ) . then ( _configuration => {
27
29
// if (typescript.languageService[thisPluginMarker]) return
28
30
const config = patchConfig ( _configuration )
29
31
if ( ! config . enablePlugin ) return
@@ -39,8 +41,8 @@ const plugin = (context => {
39
41
}
40
42
} )
41
43
42
- configurationHost . onDidChangeConfiguration ( ( ) => {
43
- void configurationHost . getConfiguration < any > ( 'tsEssentialPlugins' ) . then ( config => {
44
+ configurationHost . onDidChangeConfiguration ! ( ( ) => {
45
+ void configurationHost . getConfiguration ! < any > ( 'tsEssentialPlugins' ) . then ( config => {
44
46
config = patchConfig ( config )
45
47
plugin . onConfigurationChanged ?.( config )
46
48
// temporary workaround
@@ -54,17 +56,17 @@ const plugin = (context => {
54
56
console . warn ( 'Failed to activate tsEssentialPlugins, because of no typescript or configurationHost context' )
55
57
}
56
58
return { }
57
- } ) satisfies import ( '@volar/language-service' ) . LanguageServicePlugin
59
+ } ) satisfies import ( '@volar/language-service' ) . Service
58
60
59
61
module . exports = {
60
62
plugins : [
61
- c => {
63
+ ( ... args ) => {
62
64
try {
63
- return plugin ( c )
65
+ return plugin ( ... ( args as [ any ] ) )
64
66
} catch ( err ) {
65
67
console . log ( 'TS Essentials error' , err )
66
68
return { }
67
69
}
68
70
} ,
69
71
] ,
70
- }
72
+ } /* satisfies import('@volar/language-service').ServiceContext */
0 commit comments