@@ -27,7 +27,7 @@ interface CodeActionMatcher {
27
27
28
28
const { languageService, languageServiceHost, updateProject, getCurrentFile } = sharedLanguageService
29
29
30
- const fakeProxy = { } as Pick < typeof languageService , 'getApplicableRefactors' | 'getEditsForRefactor' >
30
+ export const fakeProxy = { } as Pick < typeof languageService , 'getApplicableRefactors' | 'getEditsForRefactor' >
31
31
32
32
codeActionsDecorateProxy ( fakeProxy as typeof languageService , languageService , languageServiceHost , defaultConfigFunc )
33
33
@@ -82,7 +82,7 @@ export const fourslashLikeTester = (contents: string, fileName = entrypoint, { d
82
82
83
83
const ranges = positive . reduce < number [ ] [ ] > (
84
84
( prevRanges , pos ) => {
85
- const lastPrev = prevRanges [ prevRanges . length - 1 ] !
85
+ const lastPrev = prevRanges . at ( - 1 ) !
86
86
if ( lastPrev . length < 2 ) {
87
87
lastPrev . push ( pos )
88
88
return prevRanges
@@ -92,58 +92,68 @@ export const fourslashLikeTester = (contents: string, fileName = entrypoint, { d
92
92
[ [ ] ] ,
93
93
)
94
94
return {
95
- completion : ( marker : number | number [ ] , matcher : CompletionMatcher , meta ?) => {
96
- for ( const mark of Array . isArray ( marker ) ? marker : [ marker ] ) {
97
- if ( numberedPositions [ mark ] === undefined ) throw new Error ( `No marker ${ mark } found` )
98
- const result = getCompletionsAtPosition ( numberedPositions [ mark ] ! , { shouldHave : true } ) !
99
- const message = ` at marker ${ mark } `
100
- const { exact, includes, excludes } = matcher
101
- if ( exact ) {
102
- const { names, all, insertTexts } = exact
103
- if ( names ) {
104
- expect ( result ?. entryNames , message ) . toEqual ( names )
105
- }
106
- if ( insertTexts ) {
107
- expect (
108
- result . entries . map ( entry => entry . insertText ) ,
109
- message ,
110
- ) . toEqual ( insertTexts )
111
- }
112
- if ( all ) {
113
- for ( const entry of result . entries ) {
114
- expect ( entry , entry . name + message ) . toContain ( all )
115
- }
116
- }
117
- }
118
- if ( includes ) {
119
- const { names, all, insertTexts } = includes
120
- if ( names ) {
121
- for ( const name of names ) {
122
- expect ( result ?. entryNames , message ) . toContain ( name )
95
+ completion ( marker : number | number [ ] , matcher : CompletionMatcher , meta ?) {
96
+ const oldGetSemanticDiagnostics = languageService . getSemanticDiagnostics
97
+ languageService . getSemanticDiagnostics = ( ) => {
98
+ throw new Error ( 'getSemanticDiagnostics should not be called because of performance reasons' )
99
+ // return []
100
+ }
101
+
102
+ try {
103
+ for ( const mark of Array . isArray ( marker ) ? marker : [ marker ] ) {
104
+ if ( numberedPositions [ mark ] === undefined ) throw new Error ( `No marker ${ mark } found` )
105
+ const result = getCompletionsAtPosition ( numberedPositions [ mark ] ! , { shouldHave : true } ) !
106
+ const message = ` at marker ${ mark } `
107
+ const { exact, includes, excludes } = matcher
108
+ if ( exact ) {
109
+ const { names, all, insertTexts } = exact
110
+ if ( names ) {
111
+ expect ( result ?. entryNames , message ) . toEqual ( names )
123
112
}
124
- }
125
- if ( insertTexts ) {
126
- for ( const insertText of insertTexts ) {
113
+ if ( insertTexts ) {
127
114
expect (
128
115
result . entries . map ( entry => entry . insertText ) ,
129
116
message ,
130
- ) . toContain ( insertText )
117
+ ) . toEqual ( insertTexts )
118
+ }
119
+ if ( all ) {
120
+ for ( const entry of result . entries ) {
121
+ expect ( entry , entry . name + message ) . toContain ( all )
122
+ }
131
123
}
132
124
}
133
- if ( all ) {
134
- for ( const entry of result . entries . filter ( e => names ?. includes ( e . name ) ) ) {
135
- expect ( entry , entry . name + message ) . toContain ( all )
125
+ if ( includes ) {
126
+ const { names, all, insertTexts } = includes
127
+ if ( names ) {
128
+ for ( const name of names ) {
129
+ expect ( result ?. entryNames , message ) . toContain ( name )
130
+ }
131
+ }
132
+ if ( insertTexts ) {
133
+ for ( const insertText of insertTexts ) {
134
+ expect (
135
+ result . entries . map ( entry => entry . insertText ) ,
136
+ message ,
137
+ ) . toContain ( insertText )
138
+ }
139
+ }
140
+ if ( all ) {
141
+ for ( const entry of result . entries . filter ( e => names ?. includes ( e . name ) ) ) {
142
+ expect ( entry , entry . name + message ) . toContain ( all )
143
+ }
136
144
}
137
145
}
138
- }
139
- if ( excludes ) {
140
- for ( const exclude of excludes ) {
141
- expect ( result ?. entryNames , message ) . not . toContain ( exclude )
146
+ if ( excludes ) {
147
+ for ( const exclude of excludes ) {
148
+ expect ( result ?. entryNames , message ) . not . toContain ( exclude )
149
+ }
142
150
}
143
151
}
152
+ } finally {
153
+ languageService . getSemanticDiagnostics = oldGetSemanticDiagnostics
144
154
}
145
155
} ,
146
- codeAction : ( marker : number | number [ ] , matcher : CodeActionMatcher , meta ?, { compareContent = false } = { } ) => {
156
+ codeAction ( marker : number | number [ ] , matcher : CodeActionMatcher , meta ?, { compareContent = false } = { } ) {
147
157
for ( const mark of Array . isArray ( marker ) ? marker : [ marker ] ) {
148
158
if ( ! ranges [ mark ] ) throw new Error ( `No range with index ${ mark } found, highest index is ${ ranges . length - 1 } ` )
149
159
const start = ranges [ mark ] ! [ 0 ] !
@@ -192,10 +202,10 @@ export const fileContentsSpecialPositions = (contents: string, fileName = entryp
192
202
let mainMatch = currentMatch [ 1 ] !
193
203
if ( addOnly ) mainMatch = mainMatch . slice ( 0 , - 1 )
194
204
const possiblyNum = + mainMatch
195
- if ( ! Number . isNaN ( possiblyNum ) ) {
196
- addArr [ 2 ] [ possiblyNum ] = offset
197
- } else {
205
+ if ( Number . isNaN ( possiblyNum ) ) {
198
206
addArr [ mainMatch === 't' ? '0' : '1' ] . push ( offset )
207
+ } else {
208
+ addArr [ 2 ] [ possiblyNum ] = offset
199
209
}
200
210
replacement . lastIndex -= matchLength
201
211
}
0 commit comments