@@ -22,51 +22,45 @@ import { executeTaskAndWaitForResult, waitForNoRunningTasks } from "../../utilit
2222import { getBuildAllTask , SwiftTask } from "../../../src/tasks/SwiftTaskProvider" ;
2323import { Version } from "../../../src/utilities/version" ;
2424import { activateExtensionForSuite , folderInRootWorkspace } from "../utilities/testutilities" ;
25-
26- async function waitForClientState (
27- languageClientManager : LanguageClientManager ,
28- expectedState : langclient . State
29- ) : Promise < langclient . State > {
30- let clientState = undefined ;
31- while ( clientState !== expectedState ) {
32- clientState = await languageClientManager . useLanguageClient ( async client => client . state ) ;
33- console . warn ( "Language client is not ready yet. Retrying in 100 ms..." ) ;
34- await new Promise ( resolve => setTimeout ( resolve , 100 ) ) ;
35- }
36- return clientState ;
37- }
25+ import { FolderContext } from "../../../src/FolderContext" ;
26+ import { waitForClientState , waitForCodeActions , waitForIndex } from "../utilities/lsputilities" ;
3827
3928async function buildProject ( ctx : WorkspaceContext , name : string ) {
4029 await waitForNoRunningTasks ( ) ;
4130 const folderContext = await folderInRootWorkspace ( name , ctx ) ;
4231 const task = ( await getBuildAllTask ( folderContext ) ) as SwiftTask ;
4332 const { exitCode, output } = await executeTaskAndWaitForResult ( task ) ;
4433 expect ( exitCode , `${ output } ` ) . to . equal ( 0 ) ;
34+ return folderContext ;
4535}
4636
4737suite ( "Language Client Integration Suite @slow" , function ( ) {
38+ this . timeout ( 5 * 60 * 1000 ) ;
39+
4840 let clientManager : LanguageClientManager ;
4941 let workspaceContext : WorkspaceContext ;
42+ let macroFolderContext : FolderContext ;
5043
5144 activateExtensionForSuite ( {
5245 async setup ( ctx ) {
53- this . timeout ( 5 * 60 * 1000 ) ;
54-
5546 workspaceContext = ctx ;
5647
5748 // Wait for a clean starting point, and build all tasks for the fixture
5849 if ( workspaceContext . swiftVersion . isGreaterThanOrEqual ( new Version ( 6 , 1 , 0 ) ) ) {
59- await buildProject ( ctx , "swift-macro" ) ;
50+ macroFolderContext = await buildProject ( ctx , "swift-macro" ) ;
6051 }
6152 await buildProject ( ctx , "defaultPackage" ) ;
6253
6354 // Ensure lsp client is ready
6455 clientManager = ctx . languageClientManager ;
65- const clientState = await waitForClientState ( clientManager , langclient . State . Running ) ;
66- expect ( clientState ) . to . equals ( langclient . State . Running ) ;
56+ await waitForClientState ( clientManager , langclient . State . Running ) ;
6757 } ,
6858 } ) ;
6959
60+ setup ( async ( ) => {
61+ await waitForIndex ( workspaceContext . languageClientManager ) ;
62+ } ) ;
63+
7064 test ( "Expand Macro" , async function ( ) {
7165 // Expand Macro support in Swift started from 6.1
7266 if ( workspaceContext . swiftVersion . isLessThan ( new Version ( 6 , 1 , 0 ) ) ) {
@@ -76,12 +70,15 @@ suite("Language Client Integration Suite @slow", function () {
7670 // Focus on the file of interest
7771 const uri = testAssetUri ( "swift-macro/Sources/swift-macroClient/main.swift" ) ;
7872 await vscode . window . showTextDocument ( uri ) ;
73+ await workspaceContext . focusFolder ( macroFolderContext ) ;
7974
8075 // Beginning of macro, #
8176 const position = new vscode . Position ( 5 , 21 ) ;
8277
8378 // Create a range starting and ending at the specified position
84- const range = new vscode . Range ( position , position ) ;
79+ const range = new vscode . Selection ( position , position . with ( { character : 22 } ) ) ;
80+
81+ await waitForCodeActions ( workspaceContext . languageClientManager , uri , range ) ;
8582
8683 // Execute the code action provider command
8784 const codeActions = await vscode . commands . executeCommand < vscode . CodeAction [ ] > (
@@ -90,8 +87,6 @@ suite("Language Client Integration Suite @slow", function () {
9087 range
9188 ) ;
9289
93- const expectedMacro = '(a + b, "a + b")' ;
94-
9590 // Find the "expand.macro.command" action
9691 const expandMacroAction = codeActions . find (
9792 action => action . command ?. command === "expand.macro.command"
@@ -129,6 +124,7 @@ suite("Language Client Integration Suite @slow", function () {
129124 expect ( referenceDocument ) . to . not . be . undefined ;
130125
131126 // Assert that the content contains the expected result
127+ const expectedMacro = '(a + b, "a + b")' ;
132128 const content = referenceDocument . getText ( ) ;
133129 expect ( content ) . to . include ( expectedMacro ) ;
134130 } ) ;
0 commit comments