@@ -246,5 +246,136 @@ export interface BrowserRouterProps {
246246 }
247247 } ) ;
248248 } ) ;
249+
250+ describe ( "test of src/services/completions.ts#getCompletionData (#37546)" , ( ) => {
251+
252+ // check jsdoc tag (not strictly)
253+ const checkJsdocTagNoStrict = ( completionInfo ?: protocol . CompletionInfo ) => {
254+ return completionInfo ?. entries ?. every ( entry => / @ \w + / . test ( entry . name ) ) ;
255+ } ;
256+ // shorthands
257+ const execCompletionsRequest = ( requestArgs : protocol . CompletionsRequestArgs ) => {
258+ return executeSessionRequest < protocol . CompletionsRequest , protocol . CompletionInfoResponse > ( session , protocol . CommandTypes . CompletionInfo , requestArgs ) ;
259+ } ;
260+ const execEditRequest = ( edit : protocol . CodeEdit ) => {
261+ return executeSessionRequest < protocol . UpdateOpenRequest , protocol . Response > ( session , protocol . CommandTypes . UpdateOpen , {
262+ changedFiles : [ {
263+ fileName : dummy . path ,
264+ textChanges : [ edit ]
265+ } ]
266+ } ) ;
267+ } ;
268+ const dummy : File = {
269+ path : "/dummy.ts" ,
270+ content : `/** */
271+ function dummy(a: string) {}
272+ `
273+ } ;
274+
275+ let session : TestSession ;
276+ let requestArgs ! : protocol . CompletionsRequestArgs ;
277+ before ( ( ) => {
278+ session = createSession ( createServerHost ( [ dummy ] ) ) ;
279+ openFilesForSession ( [ dummy ] , session ) ;
280+ requestArgs = {
281+ file : dummy . path ,
282+ line : 1 ,
283+ offset : 4 ,
284+ includeExternalModuleExports : true ,
285+ includeInsertTextCompletions : true
286+ } ;
287+ } ) ;
288+
289+ // /**|c| */
290+ // function dummy(a: string) {}
291+ //
292+ // ^--offset=1
293+ it ( "completionInfo request will be failed [/**|c| */]" , ( ) => {
294+ // "success":false,"message":"No content available."
295+ assert . equal ( execCompletionsRequest ( requestArgs ) , undefined ) ;
296+ } ) ;
297+
298+ // /** |c|*/
299+ // function dummy(a: string) {}
300+ //
301+ // ^--offset=1
302+ it ( "CompletionInfo.entries is CompletionDataKind.JsDocTag [/** |c|*/]" , ( ) => {
303+ requestArgs . offset = 5 ;
304+ const response = execCompletionsRequest ( requestArgs ) ;
305+ assert . equal ( checkJsdocTagNoStrict ( response ) , true ) ;
306+ } ) ;
307+
308+ // /**
309+ // +|c|
310+ // */
311+ // function dummy(a: string) {}
312+ //
313+ // ^--offset=1
314+ it ( "completionInfo request will be failed [ +|c|]" , ( ) => {
315+ execEditRequest ( {
316+ newText : "\n + \n" ,
317+ start : { line : 1 , offset : 4 } ,
318+ end : { line : 1 , offset : 4 }
319+ } ) ;
320+ requestArgs . line = 2 ;
321+ requestArgs . offset = 3 ;
322+ assert . equal ( execCompletionsRequest ( requestArgs ) , undefined ) ;
323+ } ) ;
324+
325+ // /**
326+ // +@|c|
327+ // */
328+ // function dummy(a: string) {}
329+ //
330+ // ^--offset=1
331+ it ( "completionInfo request will be failed [ +@|c|]" , ( ) => {
332+ execEditRequest ( {
333+ newText : "+@" ,
334+ start : { line : 2 , offset : 2 } ,
335+ end : { line : 2 , offset : 2 }
336+ } ) ;
337+ requestArgs . offset = 4 ;
338+ requestArgs . triggerCharacter = "@" ;
339+ assert . equal ( execCompletionsRequest ( requestArgs ) , undefined ) ;
340+ } ) ;
341+
342+ // /**
343+ // *|c|
344+ // */
345+ // function dummy(a: string) {}
346+ //
347+ // ^--offset=1
348+ it ( "CompletionInfo.entries is CompletionDataKind.JsDocTag [ *|c|]" , ( ) => {
349+ execEditRequest ( {
350+ newText : "*" ,
351+ start : { line : 2 , offset : 2 } ,
352+ end : { line : 2 , offset : 3 }
353+ } ) ;
354+ requestArgs . offset = 3 ;
355+ requestArgs . triggerCharacter = undefined ;
356+ const response = execCompletionsRequest ( requestArgs ) ;
357+ assert . equal ( checkJsdocTagNoStrict ( response ) , true ) ;
358+ } ) ;
359+
360+ // /**
361+ // *@|c|
362+ // */
363+ // function dummy(a: string) {}
364+ //
365+ // ^--offset=1
366+ it ( "CompletionInfo.entries is CompletionDataKind.JsDocTagName [ *@|c|]" , ( ) => {
367+ execEditRequest ( {
368+ newText : "*@" ,
369+ start : { line : 2 , offset : 2 } ,
370+ end : { line : 2 , offset : 2 }
371+ } ) ;
372+ requestArgs . offset = 4 ;
373+ requestArgs . triggerCharacter = "@" ;
374+ const response = execCompletionsRequest ( requestArgs ) ;
375+ assert . equal (
376+ response ?. entries ?. every ( entry => / \w + / . test ( entry . name ) ) , true
377+ ) ;
378+ } ) ;
379+ } ) ;
249380 } ) ;
250381}
0 commit comments