@@ -22,51 +22,45 @@ import { executeTaskAndWaitForResult, waitForNoRunningTasks } from "../../utilit
22
22
import { getBuildAllTask , SwiftTask } from "../../../src/tasks/SwiftTaskProvider" ;
23
23
import { Version } from "../../../src/utilities/version" ;
24
24
import { 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" ;
38
27
39
28
async function buildProject ( ctx : WorkspaceContext , name : string ) {
40
29
await waitForNoRunningTasks ( ) ;
41
30
const folderContext = await folderInRootWorkspace ( name , ctx ) ;
42
31
const task = ( await getBuildAllTask ( folderContext ) ) as SwiftTask ;
43
32
const { exitCode, output } = await executeTaskAndWaitForResult ( task ) ;
44
33
expect ( exitCode , `${ output } ` ) . to . equal ( 0 ) ;
34
+ return folderContext ;
45
35
}
46
36
47
37
suite ( "Language Client Integration Suite @slow" , function ( ) {
38
+ this . timeout ( 5 * 60 * 1000 ) ;
39
+
48
40
let clientManager : LanguageClientManager ;
49
41
let workspaceContext : WorkspaceContext ;
42
+ let macroFolderContext : FolderContext ;
50
43
51
44
activateExtensionForSuite ( {
52
45
async setup ( ctx ) {
53
- this . timeout ( 5 * 60 * 1000 ) ;
54
-
55
46
workspaceContext = ctx ;
56
47
57
48
// Wait for a clean starting point, and build all tasks for the fixture
58
49
if ( workspaceContext . swiftVersion . isGreaterThanOrEqual ( new Version ( 6 , 1 , 0 ) ) ) {
59
- await buildProject ( ctx , "swift-macro" ) ;
50
+ macroFolderContext = await buildProject ( ctx , "swift-macro" ) ;
60
51
}
61
52
await buildProject ( ctx , "defaultPackage" ) ;
62
53
63
54
// Ensure lsp client is ready
64
55
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 ) ;
67
57
} ,
68
58
} ) ;
69
59
60
+ setup ( async ( ) => {
61
+ await waitForIndex ( workspaceContext . languageClientManager ) ;
62
+ } ) ;
63
+
70
64
test ( "Expand Macro" , async function ( ) {
71
65
// Expand Macro support in Swift started from 6.1
72
66
if ( workspaceContext . swiftVersion . isLessThan ( new Version ( 6 , 1 , 0 ) ) ) {
@@ -76,12 +70,15 @@ suite("Language Client Integration Suite @slow", function () {
76
70
// Focus on the file of interest
77
71
const uri = testAssetUri ( "swift-macro/Sources/swift-macroClient/main.swift" ) ;
78
72
await vscode . window . showTextDocument ( uri ) ;
73
+ await workspaceContext . focusFolder ( macroFolderContext ) ;
79
74
80
75
// Beginning of macro, #
81
76
const position = new vscode . Position ( 5 , 21 ) ;
82
77
83
78
// 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 ) ;
85
82
86
83
// Execute the code action provider command
87
84
const codeActions = await vscode . commands . executeCommand < vscode . CodeAction [ ] > (
@@ -90,8 +87,6 @@ suite("Language Client Integration Suite @slow", function () {
90
87
range
91
88
) ;
92
89
93
- const expectedMacro = '(a + b, "a + b")' ;
94
-
95
90
// Find the "expand.macro.command" action
96
91
const expandMacroAction = codeActions . find (
97
92
action => action . command ?. command === "expand.macro.command"
@@ -129,6 +124,7 @@ suite("Language Client Integration Suite @slow", function () {
129
124
expect ( referenceDocument ) . to . not . be . undefined ;
130
125
131
126
// Assert that the content contains the expected result
127
+ const expectedMacro = '(a + b, "a + b")' ;
132
128
const content = referenceDocument . getText ( ) ;
133
129
expect ( content ) . to . include ( expectedMacro ) ;
134
130
} ) ;
0 commit comments