diff --git a/assets/test/swift-macro/Package.swift b/assets/test/swift-macro/Package.swift deleted file mode 100644 index 046839911..000000000 --- a/assets/test/swift-macro/Package.swift +++ /dev/null @@ -1,42 +0,0 @@ -// swift-tools-version:5.9 -// The swift-tools-version declares the minimum version of Swift required to build this package. - -import PackageDescription -import CompilerPluginSupport - -let package = Package( - name: "swift-macro", - platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .macCatalyst(.v13)], - products: [ - // Products define the executables and libraries a package produces, making them visible to other packages. - .library( - name: "swift-macro", - targets: ["swift-macro"] - ), - .executable( - name: "swift-macroClient", - targets: ["swift-macroClient"] - ), - ], - dependencies: [ - .package(url: "https://github.com/swiftlang/swift-syntax.git", from: "600.0.1"), - ], - targets: [ - // Targets are the basic building blocks of a package, defining a module or a test suite. - // Targets can depend on other targets in this package and products from dependencies. - // Macro implementation that performs the source transformation of a macro. - .macro( - name: "swift-macroMacros", - dependencies: [ - .product(name: "SwiftSyntaxMacros", package: "swift-syntax"), - .product(name: "SwiftCompilerPlugin", package: "swift-syntax") - ] - ), - - // Library that exposes a macro as part of its API, which is used in client programs. - .target(name: "swift-macro", dependencies: ["swift-macroMacros"]), - - // A client of the library, which is able to use the macro in its own code. - .executableTarget(name: "swift-macroClient", dependencies: ["swift-macro"]), - ] -) diff --git a/assets/test/swift-macro/Sources/swift-macro/swift_macro.swift b/assets/test/swift-macro/Sources/swift-macro/swift_macro.swift deleted file mode 100644 index 0e0da12b8..000000000 --- a/assets/test/swift-macro/Sources/swift-macro/swift_macro.swift +++ /dev/null @@ -1,11 +0,0 @@ -// The Swift Programming Language -// https://docs.swift.org/swift-book - -/// A macro that produces both a value and a string containing the -/// source code that generated the value. For example, -/// -/// #stringify(x + y) -/// -/// produces a tuple `(x + y, "x + y")`. -@freestanding(expression) -public macro stringify(_ value: T) -> (T, String) = #externalMacro(module: "swift_macroMacros", type: "StringifyMacro") diff --git a/assets/test/swift-macro/Sources/swift-macroClient/main.swift b/assets/test/swift-macro/Sources/swift-macroClient/main.swift deleted file mode 100644 index f80e10e00..000000000 --- a/assets/test/swift-macro/Sources/swift-macroClient/main.swift +++ /dev/null @@ -1,8 +0,0 @@ -import swift_macro - -let a = 17 -let b = 25 - -let (result, code) = #stringify(a + b) - -print("The value \(result) was produced by the code \"\(code)\"") diff --git a/assets/test/swift-macro/Sources/swift-macroMacros/swift_macroMacro.swift b/assets/test/swift-macro/Sources/swift-macroMacros/swift_macroMacro.swift deleted file mode 100644 index 5f242ce91..000000000 --- a/assets/test/swift-macro/Sources/swift-macroMacros/swift_macroMacro.swift +++ /dev/null @@ -1,33 +0,0 @@ -import SwiftCompilerPlugin -import SwiftSyntax -import SwiftSyntaxBuilder -import SwiftSyntaxMacros - -/// Implementation of the `stringify` macro, which takes an expression -/// of any type and produces a tuple containing the value of that expression -/// and the source code that produced the value. For example -/// -/// #stringify(x + y) -/// -/// will expand to -/// -/// (x + y, "x + y") -public struct StringifyMacro: ExpressionMacro { - public static func expansion( - of node: some FreestandingMacroExpansionSyntax, - in context: some MacroExpansionContext - ) -> ExprSyntax { - guard let argument = node.arguments.first?.expression else { - fatalError("compiler bug: the macro does not have any arguments") - } - - return "(\(argument), \(literal: argument.description))" - } -} - -@main -struct swift_macroPlugin: CompilerPlugin { - let providingMacros: [Macro.Type] = [ - StringifyMacro.self, - ] -} diff --git a/test/integration-tests/language/LanguageClientIntegration.test.ts b/test/integration-tests/language/LanguageClientIntegration.test.ts index 3a2816b80..3caab8c8d 100644 --- a/test/integration-tests/language/LanguageClientIntegration.test.ts +++ b/test/integration-tests/language/LanguageClientIntegration.test.ts @@ -20,10 +20,8 @@ import { WorkspaceContext } from "../../../src/WorkspaceContext"; import { testAssetUri } from "../../fixtures"; import { executeTaskAndWaitForResult, waitForNoRunningTasks } from "../../utilities/tasks"; import { getBuildAllTask, SwiftTask } from "../../../src/tasks/SwiftTaskProvider"; -import { Version } from "../../../src/utilities/version"; import { activateExtensionForSuite, folderInRootWorkspace } from "../utilities/testutilities"; -import { FolderContext } from "../../../src/FolderContext"; -import { waitForClientState, waitForCodeActions, waitForIndex } from "../utilities/lsputilities"; +import { waitForClientState, waitForIndex } from "../utilities/lsputilities"; async function buildProject(ctx: WorkspaceContext, name: string) { await waitForNoRunningTasks(); @@ -35,20 +33,15 @@ async function buildProject(ctx: WorkspaceContext, name: string) { } suite("Language Client Integration Suite @slow", function () { - this.timeout(5 * 60 * 1000); + this.timeout(2 * 60 * 1000); let clientManager: LanguageClientManager; let workspaceContext: WorkspaceContext; - let macroFolderContext: FolderContext; activateExtensionForSuite({ async setup(ctx) { workspaceContext = ctx; - // Wait for a clean starting point, and build all tasks for the fixture - if (workspaceContext.swiftVersion.isGreaterThanOrEqual(new Version(6, 1, 0))) { - macroFolderContext = await buildProject(ctx, "swift-macro"); - } await buildProject(ctx, "defaultPackage"); // Ensure lsp client is ready @@ -61,74 +54,6 @@ suite("Language Client Integration Suite @slow", function () { await waitForIndex(workspaceContext.languageClientManager); }); - test("Expand Macro", async function () { - // Expand Macro support in Swift started from 6.1 - if (workspaceContext.swiftVersion.isLessThan(new Version(6, 1, 0))) { - this.skip(); - } - - // Focus on the file of interest - const uri = testAssetUri("swift-macro/Sources/swift-macroClient/main.swift"); - await vscode.window.showTextDocument(uri); - await workspaceContext.focusFolder(macroFolderContext); - - // Beginning of macro, # - const position = new vscode.Position(5, 21); - - // Create a range starting and ending at the specified position - const range = new vscode.Selection(position, position.with({ character: 22 })); - - await waitForCodeActions(workspaceContext.languageClientManager, uri, range); - - // Execute the code action provider command - const codeActions = await vscode.commands.executeCommand( - "vscode.executeCodeActionProvider", - uri, - range - ); - - // Find the "expand.macro.command" action - const expandMacroAction = codeActions.find( - action => action.command?.command === "expand.macro.command" - ); - - // Assert that the expand macro command is available - expect(expandMacroAction).is.not.undefined; - - // Set up a promise that resolves when the expected document is opened - const expandedMacroUriPromise = new Promise((resolve, reject) => { - const disposable = vscode.workspace.onDidOpenTextDocument(openedDocument => { - if (openedDocument.uri.scheme === "sourcekit-lsp") { - disposable.dispose(); // Stop listening once we find the desired document - resolve(openedDocument); - } - }); - - // Set a timeout to reject the promise if the document is not found - setTimeout(() => { - disposable.dispose(); - reject(new Error("Timed out waiting for sourcekit-lsp document to be opened.")); - }, 10000); // Wait up to 10 seconds for the document - }); - - // Run expand macro action - const command = expandMacroAction!.command!; - expect(command.arguments).is.not.undefined; - const commandArgs = command.arguments!; - await vscode.commands.executeCommand(command.command, ...commandArgs); - - // Wait for the expanded macro document to be opened - const referenceDocument = await expandedMacroUriPromise; - - // Verify that the reference document was successfully opened - expect(referenceDocument).to.not.be.undefined; - - // Assert that the content contains the expected result - const expectedMacro = '(a + b, "a + b")'; - const content = referenceDocument.getText(); - expect(content).to.include(expectedMacro); - }); - suite("Symbols", () => { const uri = testAssetUri("defaultPackage/Sources/PackageExe/main.swift"); const expectedDefinitionUri = testAssetUri(