Files
swift-mirror/test/SourceKit/Macros/macro_semantic_token.swift
2024-01-11 08:19:15 -08:00

29 lines
1.6 KiB
Swift

@freestanding(declaration)
macro anonymousTypes(_: () -> String) = #externalMacro(module: "MacroDefinition", type: "DefineAnonymousTypesMacro")
#anonymousTypes { "hello" }
// REQUIRES: swift_swift_parser, executable_test
// RUN: %empty-directory(%t)
//##-- Prepare the macro plugin.
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/../../Macros/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath
// Check the output of the the `#anonymousTypes` macro
// RUN: %sourcekitd-test -req=semantic-tokens @__swiftmacro_9MacroUser33_8C2BB8A10AE555140C0EDFDEB4A9572DLl14anonymousTypesfMf_.swift -primary-file %s -- -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser %s | %FileCheck %s --check-prefix IN_BUFFER
// Check that we get some semantic tokens. Checking exact offsets is brittle.
// IN_BUFFER: source.lang.swift.ref.struct
// IN_BUFFER: key.kind: source.lang.swift.ref.class
// Check that we don't get semantic tokens inside the buffer when requesting semantic tokens for the outer file
// RUN: %sourcekitd-test -req=semantic-tokens %s -- -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser %s | %FileCheck %s --check-prefix PRIMARY_FILE
// Reference to String in line 2
// PRIMARY_FILE: key.kind: source.lang.swift.ref.struct
// Reference to macro in line 4
// PRIMARY_FILE: key.kind: source.lang.swift.ref.macro
// There should be no other references
// PRIMARY_FILE-NOT: key.kind