@@ -18,7 +18,6 @@ import { expect } from "chai";
18
18
import { LanguageClientManager } from "../../../src/sourcekit-lsp/LanguageClientManager" ;
19
19
import { WorkspaceContext } from "../../../src/WorkspaceContext" ;
20
20
import { testAssetUri } from "../../fixtures" ;
21
- import { FolderContext } from "../../../src/FolderContext" ;
22
21
import { executeTaskAndWaitForResult , waitForNoRunningTasks } from "../../utilities" ;
23
22
import { getBuildAllTask , SwiftTask } from "../../../src/tasks/SwiftTaskProvider" ;
24
23
import { Version } from "../../../src/utilities/version" ;
@@ -37,38 +36,43 @@ async function waitForClientState(
37
36
return clientState ;
38
37
}
39
38
40
- suite ( "Integration, Macros Functionality Support with Sourcekit-lsp" , function ( ) {
41
- // Take around 60 seconds if running in isolation, longer than default timeout
42
- this . timeout ( 2 * 60 * 1000 ) ;
39
+ async function buildProject ( ctx : WorkspaceContext , name : string ) {
40
+ await waitForNoRunningTasks ( ) ;
41
+ const folderContext = await folderInRootWorkspace ( name , ctx ) ;
42
+ const task = ( await getBuildAllTask ( folderContext ) ) as SwiftTask ;
43
+ const { exitCode, output } = await executeTaskAndWaitForResult ( task ) ;
44
+ expect ( exitCode , `${ output } ` ) . to . equal ( 0 ) ;
45
+ }
43
46
47
+ suite ( "Language Client Integration Suite" , function ( ) {
44
48
let clientManager : LanguageClientManager ;
45
49
let workspaceContext : WorkspaceContext ;
46
- let folderContext : FolderContext ;
47
50
48
51
activateExtensionForSuite ( {
49
52
async setup ( ctx ) {
53
+ this . timeout ( 5 * 60 * 1000 ) ;
54
+
50
55
workspaceContext = ctx ;
51
- // Expand Macro support in Swift started from 6.1
52
- if ( workspaceContext . swiftVersion . isLessThan ( new Version ( 6 , 1 , 0 ) ) ) {
53
- this . skip ( ) ;
54
- }
55
56
56
57
// Wait for a clean starting point, and build all tasks for the fixture
57
- await waitForNoRunningTasks ( ) ;
58
- folderContext = await folderInRootWorkspace ( "swift-macro" , workspaceContext ) ;
59
- await workspaceContext . focusFolder ( folderContext ) ;
60
- const tasks = ( await getBuildAllTask ( folderContext ) ) as SwiftTask ;
61
- const { exitCode, output } = await executeTaskAndWaitForResult ( tasks ) ;
62
- expect ( exitCode , `${ output } ` ) . to . equal ( 0 ) ;
58
+ if ( workspaceContext . swiftVersion . isGreaterThanOrEqual ( new Version ( 6 , 1 , 0 ) ) ) {
59
+ await buildProject ( ctx , "swift-macro" ) ;
60
+ }
61
+ await buildProject ( ctx , "defaultPackage" ) ;
63
62
64
63
// Ensure lsp client is ready
65
- clientManager = workspaceContext . languageClientManager ;
64
+ clientManager = ctx . languageClientManager ;
66
65
const clientState = await waitForClientState ( clientManager , langclient . State . Running ) ;
67
66
expect ( clientState ) . to . equals ( langclient . State . Running ) ;
68
67
} ,
69
68
} ) ;
70
69
71
70
test ( "Expand Macro" , async function ( ) {
71
+ // Expand Macro support in Swift started from 6.1
72
+ if ( workspaceContext . swiftVersion . isLessThan ( new Version ( 6 , 1 , 0 ) ) ) {
73
+ this . skip ( ) ;
74
+ }
75
+
72
76
// Focus on the file of interest
73
77
const uri = testAssetUri ( "swift-macro/Sources/swift-macroClient/main.swift" ) ;
74
78
await vscode . window . showTextDocument ( uri ) ;
@@ -128,4 +132,64 @@ suite("Integration, Macros Functionality Support with Sourcekit-lsp", function (
128
132
const content = referenceDocument . getText ( ) ;
129
133
expect ( content ) . to . include ( expectedMacro ) ;
130
134
} ) ;
135
+
136
+ suite ( "Symbols" , ( ) => {
137
+ const uri = testAssetUri ( "defaultPackage/Sources/PackageExe/main.swift" ) ;
138
+ const expectedDefinitionUri = testAssetUri (
139
+ "defaultPackage/Sources/PackageLib/PackageLib.swift"
140
+ ) ;
141
+ // Position of the symbol 'a' in main.swift
142
+ const position = new vscode . Position ( 2 , 6 ) ;
143
+
144
+ test ( "Goto Definition" , async function ( ) {
145
+ // Focus on the file of interest
146
+ const editor = await vscode . window . showTextDocument ( uri ) ;
147
+ const document = editor . document ;
148
+
149
+ // Position of the symbol 'a' in main.swift
150
+ const definitionLocations = await vscode . commands . executeCommand < vscode . Location [ ] > (
151
+ "vscode.executeDefinitionProvider" ,
152
+ document . uri ,
153
+ position
154
+ ) ;
155
+
156
+ expect ( definitionLocations ) . to . have . lengthOf (
157
+ 1 ,
158
+ "There should be one definition of 'a'."
159
+ ) ;
160
+
161
+ const definition = definitionLocations [ 0 ] ;
162
+
163
+ // Assert that the definition is in PackageLib.swift at line 0
164
+ expect ( definition . uri . toString ( ) ) . to . equal ( expectedDefinitionUri . toString ( ) ) ;
165
+ expect ( definition . range . start . line ) . to . equal ( 0 ) ;
166
+ } ) ;
167
+
168
+ test ( "Find All References" , async function ( ) {
169
+ // Focus on the file of interest
170
+ const editor = await vscode . window . showTextDocument ( uri ) ;
171
+ const document = editor . document ;
172
+
173
+ const referenceLocations = await vscode . commands . executeCommand < vscode . Location [ ] > (
174
+ "vscode.executeReferenceProvider" ,
175
+ document . uri ,
176
+ position
177
+ ) ;
178
+
179
+ // We expect 2 references - one in `main.swift` and one in `PackageLib.swift`
180
+ expect ( referenceLocations ) . to . have . lengthOf (
181
+ 2 ,
182
+ "There should be two references to 'a'."
183
+ ) ;
184
+
185
+ // Extract reference URIs and sort them to have a predictable order
186
+ const referenceUris = referenceLocations . map ( ref => ref . uri . toString ( ) ) . sort ( ) ;
187
+ const expectedUris = [
188
+ uri . toString ( ) , // Reference in main.swift
189
+ expectedDefinitionUri . toString ( ) , // Reference in PackageLib.swift
190
+ ] . sort ( ) ;
191
+
192
+ expect ( referenceUris ) . to . deep . equal ( expectedUris ) ;
193
+ } ) ;
194
+ } ) ;
131
195
} ) ;
0 commit comments