@@ -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/tasks" ;
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 @slow" , 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,68 @@ 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
+ const snippetUri = testAssetUri ( "defaultPackage/Snippets/hello.swift" ) ;
142
+ // Position of the symbol 'a' in main.swift
143
+ const position = new vscode . Position ( 2 , 6 ) ;
144
+
145
+ test ( "Goto Definition" , async function ( ) {
146
+ // Focus on the file of interest
147
+ const editor = await vscode . window . showTextDocument ( uri ) ;
148
+ const document = editor . document ;
149
+
150
+ // Position of the symbol 'a' in main.swift
151
+ const definitionLocations = await vscode . commands . executeCommand < vscode . Location [ ] > (
152
+ "vscode.executeDefinitionProvider" ,
153
+ document . uri ,
154
+ position
155
+ ) ;
156
+
157
+ expect ( definitionLocations ) . to . have . lengthOf (
158
+ 1 ,
159
+ "There should be one definition of 'a'."
160
+ ) ;
161
+
162
+ const definition = definitionLocations [ 0 ] ;
163
+
164
+ // Assert that the definition is in PackageLib.swift at line 0
165
+ expect ( definition . uri . toString ( ) ) . to . equal ( expectedDefinitionUri . toString ( ) ) ;
166
+ expect ( definition . range . start . line ) . to . equal ( 0 ) ;
167
+ } ) ;
168
+
169
+ test ( "Find All References" , async function ( ) {
170
+ // Focus on the file of interest
171
+ const editor = await vscode . window . showTextDocument ( uri ) ;
172
+ const document = editor . document ;
173
+
174
+ const referenceLocations = await vscode . commands . executeCommand < vscode . Location [ ] > (
175
+ "vscode.executeReferenceProvider" ,
176
+ document . uri ,
177
+ position
178
+ ) ;
179
+
180
+ // We expect 2 references - one in `main.swift` and one in `PackageLib.swift`
181
+ expect ( referenceLocations ) . to . have . lengthOf (
182
+ 3 ,
183
+ "There should be two references to 'a'."
184
+ ) ;
185
+
186
+ // Extract reference URIs and sort them to have a predictable order
187
+ const referenceUris = referenceLocations . map ( ref => ref . uri . toString ( ) ) ;
188
+ const expectedUris = [
189
+ snippetUri . toString ( ) ,
190
+ uri . toString ( ) , // Reference in main.swift
191
+ expectedDefinitionUri . toString ( ) , // Reference in PackageLib.swift
192
+ ] ;
193
+
194
+ for ( const uri of expectedUris ) {
195
+ expect ( referenceUris ) . to . contain ( uri ) ;
196
+ }
197
+ } ) ;
198
+ } ) ;
131
199
} ) ;
0 commit comments