@@ -18,7 +18,6 @@ import { expect } from "chai";
1818import { LanguageClientManager } from "../../../src/sourcekit-lsp/LanguageClientManager" ;
1919import { WorkspaceContext } from "../../../src/WorkspaceContext" ;
2020import { testAssetUri } from "../../fixtures" ;
21- import { FolderContext } from "../../../src/FolderContext" ;
2221import { executeTaskAndWaitForResult , waitForNoRunningTasks } from "../../utilities/tasks" ;
2322import { getBuildAllTask , SwiftTask } from "../../../src/tasks/SwiftTaskProvider" ;
2423import { Version } from "../../../src/utilities/version" ;
@@ -37,38 +36,43 @@ async function waitForClientState(
3736 return clientState ;
3837}
3938
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+ }
4346
47+ suite ( "Language Client Integration Suite @slow" , function ( ) {
4448 let clientManager : LanguageClientManager ;
4549 let workspaceContext : WorkspaceContext ;
46- let folderContext : FolderContext ;
4750
4851 activateExtensionForSuite ( {
4952 async setup ( ctx ) {
53+ this . timeout ( 5 * 60 * 1000 ) ;
54+
5055 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- }
5556
5657 // 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" ) ;
6362
6463 // Ensure lsp client is ready
65- clientManager = workspaceContext . languageClientManager ;
64+ clientManager = ctx . languageClientManager ;
6665 const clientState = await waitForClientState ( clientManager , langclient . State . Running ) ;
6766 expect ( clientState ) . to . equals ( langclient . State . Running ) ;
6867 } ,
6968 } ) ;
7069
7170 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+
7276 // Focus on the file of interest
7377 const uri = testAssetUri ( "swift-macro/Sources/swift-macroClient/main.swift" ) ;
7478 await vscode . window . showTextDocument ( uri ) ;
@@ -128,4 +132,68 @@ suite("Integration, Macros Functionality Support with Sourcekit-lsp", function (
128132 const content = referenceDocument . getText ( ) ;
129133 expect ( content ) . to . include ( expectedMacro ) ;
130134 } ) ;
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+ } ) ;
131199} ) ;
0 commit comments