22// will be required from ./node_modules/typescript-essential-plugins/index.js
33const originalPluginFactory = require ( 'typescript-essential-plugins' )
44
5- const plugin = ( context => {
5+ const plugin = ( ( context , { typescript : tsModule } = { } ) => {
6+ if ( ! context ) throw new Error ( 'Not recieve context' )
67 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' ] !
910 const patchConfig = config => {
1011 return {
1112 ...config ,
@@ -17,13 +18,14 @@ const plugin = (context => {
1718 }
1819
1920 if ( typescript && configurationHost ) {
21+ const ts = tsModule ?? typescript [ 'module' ]
2022 const plugin = originalPluginFactory ( {
21- typescript : typescript . module ,
23+ typescript : ts ,
2224 } )
2325 // todo support vue-specific settings
2426 const originalLsMethods = { ...typescript . languageService }
2527
26- void configurationHost . getConfiguration < any > ( 'tsEssentialPlugins' ) . then ( _configuration => {
28+ void configurationHost . getConfiguration ! < any > ( 'tsEssentialPlugins' ) . then ( _configuration => {
2729 // if (typescript.languageService[thisPluginMarker]) return
2830 const config = patchConfig ( _configuration )
2931 if ( ! config . enablePlugin ) return
@@ -39,8 +41,8 @@ const plugin = (context => {
3941 }
4042 } )
4143
42- configurationHost . onDidChangeConfiguration ( ( ) => {
43- void configurationHost . getConfiguration < any > ( 'tsEssentialPlugins' ) . then ( config => {
44+ configurationHost . onDidChangeConfiguration ! ( ( ) => {
45+ void configurationHost . getConfiguration ! < any > ( 'tsEssentialPlugins' ) . then ( config => {
4446 config = patchConfig ( config )
4547 plugin . onConfigurationChanged ?.( config )
4648 // temporary workaround
@@ -54,17 +56,17 @@ const plugin = (context => {
5456 console . warn ( 'Failed to activate tsEssentialPlugins, because of no typescript or configurationHost context' )
5557 }
5658 return { }
57- } ) satisfies import ( '@volar/language-service' ) . LanguageServicePlugin
59+ } ) satisfies import ( '@volar/language-service' ) . Service
5860
5961module . exports = {
6062 plugins : [
61- c => {
63+ ( ... args ) => {
6264 try {
63- return plugin ( c )
65+ return plugin ( ... ( args as [ any ] ) )
6466 } catch ( err ) {
6567 console . log ( 'TS Essentials error' , err )
6668 return { }
6769 }
6870 } ,
6971 ] ,
70- }
72+ } /* satisfies import('@volar/language-service').ServiceContext */
0 commit comments