1
1
import type * as ts from 'typescript/lib/tsserverlibrary'
2
- import type {
3
- TemplateContext ,
4
- TemplateSettings ,
5
- } from 'typescript-template-language-service-decorator'
2
+ import type { TemplateContext } from 'typescript-template-language-service-decorator'
6
3
7
4
import StandardScriptSourceHelper from 'typescript-template-language-service-decorator/lib/standard-script-source-helper'
8
5
9
6
import { ConfigurationManager , TwindPluginConfiguration } from './configuration'
10
7
import { TwindLanguageService } from './language-service'
11
8
import { StandardTemplateSourceHelper } from './source-helper'
12
9
import { LanguageServiceLogger } from './logger'
13
- import { getSourceMatchers } from './source-matcher'
14
10
15
11
// https://github.com/microsoft/typescript-template-language-service-decorator/blob/main/src/standard-template-source-helper.ts#L75
16
12
@@ -65,6 +61,11 @@ export class TwindPlugin {
65
61
return languageService
66
62
}
67
63
64
+ let enable = this . _configManager . config . enable
65
+ this . _configManager . onUpdatedConfig ( ( ) => {
66
+ enable = this . _configManager . config . enable
67
+ } )
68
+
68
69
const ttls = new TwindLanguageService ( this . typescript , info , this . _configManager , this . _logger )
69
70
70
71
const helper = new StandardTemplateSourceHelper (
@@ -79,46 +80,52 @@ export class TwindPlugin {
79
80
80
81
// eslint-disable-next-line @typescript-eslint/no-explicit-any
81
82
getCompletionEntryDetails : ( fileName , position , name , ...rest : any [ ] ) => {
82
- const context = helper . getTemplate ( fileName , position )
83
-
84
- if ( context ) {
85
- return ttls . getCompletionEntryDetails (
86
- context ,
87
- helper . getRelativePosition ( context , position ) ,
88
- name ,
89
- )
83
+ if ( enable ) {
84
+ const context = helper . getTemplate ( fileName , position )
85
+
86
+ if ( context ) {
87
+ return ttls . getCompletionEntryDetails (
88
+ context ,
89
+ helper . getRelativePosition ( context , position ) ,
90
+ name ,
91
+ )
92
+ }
90
93
}
91
94
92
95
// eslint-disable-next-line @typescript-eslint/no-explicit-any
93
96
return ( languageService . getCompletionsAtPosition as any ) ( fileName , position , name , ...rest )
94
97
} ,
95
98
96
99
getCompletionsAtPosition : ( fileName , position , options ) => {
97
- const context = helper . getTemplate ( fileName , position )
98
-
99
- if ( context ) {
100
- return translateCompletionInfo (
101
- context ,
102
- ttls . getCompletionsAtPosition ( context , helper . getRelativePosition ( context , position ) ) ,
103
- )
100
+ if ( enable ) {
101
+ const context = helper . getTemplate ( fileName , position )
102
+
103
+ if ( context ) {
104
+ return translateCompletionInfo (
105
+ context ,
106
+ ttls . getCompletionsAtPosition ( context , helper . getRelativePosition ( context , position ) ) ,
107
+ )
108
+ }
104
109
}
105
110
106
111
return languageService . getCompletionsAtPosition ( fileName , position , options )
107
112
} ,
108
113
109
114
getQuickInfoAtPosition : ( fileName , position ) => {
110
- const context = helper . getTemplate ( fileName , position )
111
-
112
- if ( context ) {
113
- const quickInfo = ttls . getQuickInfoAtPosition (
114
- context ,
115
- helper . getRelativePosition ( context , position ) ,
116
- )
117
-
118
- if ( quickInfo ) {
119
- return {
120
- ...quickInfo ,
121
- textSpan : translateTextSpan ( context , quickInfo . textSpan ) ,
115
+ if ( enable ) {
116
+ const context = helper . getTemplate ( fileName , position )
117
+
118
+ if ( context ) {
119
+ const quickInfo = ttls . getQuickInfoAtPosition (
120
+ context ,
121
+ helper . getRelativePosition ( context , position ) ,
122
+ )
123
+
124
+ if ( quickInfo ) {
125
+ return {
126
+ ...quickInfo ,
127
+ textSpan : translateTextSpan ( context , quickInfo . textSpan ) ,
128
+ }
122
129
}
123
130
}
124
131
}
@@ -129,14 +136,16 @@ export class TwindPlugin {
129
136
getSemanticDiagnostics : ( fileName ) => {
130
137
const diagnostics = [ ...languageService . getSemanticDiagnostics ( fileName ) ]
131
138
132
- helper . getAllTemplates ( fileName ) . forEach ( ( context ) => {
133
- for ( const diagnostic of ttls . getSemanticDiagnostics ( context ) ) {
134
- diagnostics . push ( {
135
- ...diagnostic ,
136
- start : context . node . getStart ( ) + 1 + ( diagnostic . start || 0 ) ,
137
- } )
138
- }
139
- } )
139
+ if ( enable ) {
140
+ helper . getAllTemplates ( fileName ) . forEach ( ( context ) => {
141
+ for ( const diagnostic of ttls . getSemanticDiagnostics ( context ) ) {
142
+ diagnostics . push ( {
143
+ ...diagnostic ,
144
+ start : context . node . getStart ( ) + 1 + ( diagnostic . start || 0 ) ,
145
+ } )
146
+ }
147
+ } )
148
+ }
140
149
141
150
return diagnostics
142
151
} ,
@@ -154,7 +163,7 @@ export class TwindPlugin {
154
163
155
164
public onConfigurationChanged ( config : TwindPluginConfiguration ) : void {
156
165
if ( this . _logger ) {
157
- this . _logger . log ( 'onConfigurationChanged' )
166
+ this . _logger . log ( 'onConfigurationChanged: ' + JSON . stringify ( config ) )
158
167
}
159
168
160
169
this . _configManager . updateFromPluginConfig ( config )
0 commit comments