@@ -27,7 +27,7 @@ interface CodeActionMatcher {
2727
2828const { languageService, languageServiceHost, updateProject, getCurrentFile } = sharedLanguageService
2929
30- const fakeProxy = { } as Pick < typeof languageService , 'getApplicableRefactors' | 'getEditsForRefactor' >
30+ export const fakeProxy = { } as Pick < typeof languageService , 'getApplicableRefactors' | 'getEditsForRefactor' >
3131
3232codeActionsDecorateProxy ( fakeProxy as typeof languageService , languageService , languageServiceHost , defaultConfigFunc )
3333
@@ -82,7 +82,7 @@ export const fourslashLikeTester = (contents: string, fileName = entrypoint, { d
8282
8383 const ranges = positive . reduce < number [ ] [ ] > (
8484 ( prevRanges , pos ) => {
85- const lastPrev = prevRanges [ prevRanges . length - 1 ] !
85+ const lastPrev = prevRanges . at ( - 1 ) !
8686 if ( lastPrev . length < 2 ) {
8787 lastPrev . push ( pos )
8888 return prevRanges
@@ -92,58 +92,68 @@ export const fourslashLikeTester = (contents: string, fileName = entrypoint, { d
9292 [ [ ] ] ,
9393 )
9494 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 )
123112 }
124- }
125- if ( insertTexts ) {
126- for ( const insertText of insertTexts ) {
113+ if ( insertTexts ) {
127114 expect (
128115 result . entries . map ( entry => entry . insertText ) ,
129116 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+ }
131123 }
132124 }
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+ }
136144 }
137145 }
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+ }
142150 }
143151 }
152+ } finally {
153+ languageService . getSemanticDiagnostics = oldGetSemanticDiagnostics
144154 }
145155 } ,
146- codeAction : ( marker : number | number [ ] , matcher : CodeActionMatcher , meta ?, { compareContent = false } = { } ) => {
156+ codeAction ( marker : number | number [ ] , matcher : CodeActionMatcher , meta ?, { compareContent = false } = { } ) {
147157 for ( const mark of Array . isArray ( marker ) ? marker : [ marker ] ) {
148158 if ( ! ranges [ mark ] ) throw new Error ( `No range with index ${ mark } found, highest index is ${ ranges . length - 1 } ` )
149159 const start = ranges [ mark ] ! [ 0 ] !
@@ -192,10 +202,10 @@ export const fileContentsSpecialPositions = (contents: string, fileName = entryp
192202 let mainMatch = currentMatch [ 1 ] !
193203 if ( addOnly ) mainMatch = mainMatch . slice ( 0 , - 1 )
194204 const possiblyNum = + mainMatch
195- if ( ! Number . isNaN ( possiblyNum ) ) {
196- addArr [ 2 ] [ possiblyNum ] = offset
197- } else {
205+ if ( Number . isNaN ( possiblyNum ) ) {
198206 addArr [ mainMatch === 't' ? '0' : '1' ] . push ( offset )
207+ } else {
208+ addArr [ 2 ] [ possiblyNum ] = offset
199209 }
200210 replacement . lastIndex -= matchLength
201211 }
0 commit comments