@@ -21,11 +21,18 @@ final class SwiftCodeLensScanner: SyntaxVisitor {
21
21
/// The collection of CodeLenses found in the document.
22
22
private var result : [ CodeLens ] = [ ]
23
23
24
+ private let targetName : String ?
25
+
24
26
/// The map of supported commands and their client side command names
25
27
private let supportedCommands : [ SupportedCodeLensCommand : String ]
26
28
27
- private init ( snapshot: DocumentSnapshot , supportedCommands: [ SupportedCodeLensCommand : String ] ) {
29
+ private init (
30
+ snapshot: DocumentSnapshot ,
31
+ targetName: String ? ,
32
+ supportedCommands: [ SupportedCodeLensCommand : String ]
33
+ ) {
28
34
self . snapshot = snapshot
35
+ self . targetName = targetName
29
36
self . supportedCommands = supportedCommands
30
37
super. init ( viewMode: . fixedUp)
31
38
}
@@ -35,6 +42,7 @@ final class SwiftCodeLensScanner: SyntaxVisitor {
35
42
public static func findCodeLenses(
36
43
in snapshot: DocumentSnapshot ,
37
44
syntaxTreeManager: SyntaxTreeManager ,
45
+ targetName: String ? = nil ,
38
46
supportedCommands: [ SupportedCodeLensCommand : String ]
39
47
) async -> [ CodeLens ] {
40
48
guard snapshot. text. contains ( " @main " ) && !supportedCommands. isEmpty else {
@@ -43,7 +51,7 @@ final class SwiftCodeLensScanner: SyntaxVisitor {
43
51
}
44
52
45
53
let syntaxTree = await syntaxTreeManager. syntaxTree ( for: snapshot)
46
- let visitor = SwiftCodeLensScanner ( snapshot: snapshot, supportedCommands: supportedCommands)
54
+ let visitor = SwiftCodeLensScanner ( snapshot: snapshot, targetName : targetName , supportedCommands: supportedCommands)
47
55
visitor. walk ( syntaxTree)
48
56
return visitor. result
49
57
}
@@ -61,14 +69,18 @@ final class SwiftCodeLensScanner: SyntaxVisitor {
61
69
private func captureLensFromAttribute( attribute: AttributeListSyntax . Element ) {
62
70
if attribute. trimmedDescription == " @main " {
63
71
let range = self . snapshot. absolutePositionRange ( of: attribute. trimmedRange)
72
+ var targetNameToAppend : String = " "
73
+ if let targetName {
74
+ targetNameToAppend = " \( targetName) "
75
+ }
64
76
65
77
if let runCommand = supportedCommands [ SupportedCodeLensCommand . run] {
66
78
// Return commands for running/debugging the executable.
67
79
// These command names must be recognized by the client and so should not be chosen arbitrarily.
68
80
self . result. append (
69
81
CodeLens (
70
82
range: range,
71
- command: Command ( title: " Run " , command: runCommand, arguments: nil )
83
+ command: Command ( title: " Run " + targetNameToAppend , command: runCommand, arguments: nil )
72
84
)
73
85
)
74
86
}
@@ -77,7 +89,7 @@ final class SwiftCodeLensScanner: SyntaxVisitor {
77
89
self . result. append (
78
90
CodeLens (
79
91
range: range,
80
- command: Command ( title: " Debug " , command: debugCommand, arguments: nil )
92
+ command: Command ( title: " Debug " + targetNameToAppend , command: debugCommand, arguments: nil )
81
93
)
82
94
)
83
95
}
0 commit comments