File: BuildTargets.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (254 lines) | stat: -rw-r--r-- 8,754 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import LanguageServerProtocol

public typealias URI = DocumentURI

/// The workspace build targets request is sent from the client to the server to
/// ask for the list of all available build targets in the workspace.
public struct BuildTargets: RequestType, Hashable {
  public static let method: String = "workspace/buildTargets"
  public typealias Response = BuildTargetsResult

  public init() {}
}

public struct BuildTargetsResult: ResponseType, Hashable {
  public var targets: [BuildTarget]
}

public struct BuildTarget: Codable, Hashable, Sendable {
  /// The target’s unique identifier
  public var id: BuildTargetIdentifier

  /// A human readable name for this target.
  /// May be presented in the user interface.
  /// Should be unique if possible.
  /// The id.uri is used if None.
  public var displayName: String?

  /// The directory where this target belongs to. Multiple build targets are
  /// allowed to map to the same base directory, and a build target is not
  /// required to have a base directory. A base directory does not determine the
  /// sources of a target, see buildTarget/sources.
  public var baseDirectory: URI?

  /// Free-form string tags to categorize or label this build target.
  /// For example, can be used by the client to:
  /// - customize how the target should be translated into the client's project
  ///   model.
  /// - group together different but related targets in the user interface.
  /// - display icons or colors in the user interface.
  /// Pre-defined tags are listed in `BuildTargetTag` but clients and servers
  /// are free to define new tags for custom purposes.
  public var tags: [BuildTargetTag]

  /// The capabilities of this build target.
  public var capabilities: BuildTargetCapabilities

  /// The set of languages that this target contains.
  /// The ID string for each language is defined in the LSP.
  public var languageIds: [Language]

  /// The direct upstream build target dependencies of this build target
  public var dependencies: [BuildTargetIdentifier]

  public init(
    id: BuildTargetIdentifier,
    displayName: String?,
    baseDirectory: URI?,
    tags: [BuildTargetTag],
    capabilities: BuildTargetCapabilities,
    languageIds: [Language],
    dependencies: [BuildTargetIdentifier]
  ) {
    self.id = id
    self.displayName = displayName
    self.baseDirectory = baseDirectory
    self.tags = tags
    self.capabilities = capabilities
    self.languageIds = languageIds
    self.dependencies = dependencies
  }
}

public struct BuildTargetIdentifier: Codable, Hashable, Sendable {
  public var uri: URI

  public init(uri: URI) {
    self.uri = uri
  }
}

public struct BuildTargetTag: Codable, Hashable, RawRepresentable, Sendable {
  public var rawValue: String

  public init(rawValue: String) {
    self.rawValue = rawValue
  }

  /// Target contains re-usable functionality for downstream targets. May have
  /// any combination of capabilities.
  public static let library: Self = Self(rawValue: "library")

  /// Target contains source code for producing any kind of application, may
  /// have but does not require the `canRun` capability.
  public static let application: Self = Self(rawValue: "application")

  /// Target contains source code for testing purposes, may have but does not
  /// require the `canTest` capability.
  public static let test: Self = Self(rawValue: "test")

  /// Target contains source code for integration testing purposes, may have
  /// but does not require the `canTest` capability. The difference between
  /// "test" and "integration-test" is that integration tests traditionally run
  /// slower compared to normal tests and require more computing resources to
  /// execute.
  public static let integrationTest: Self = Self(rawValue: "integration-test")

  /// Target contains source code to measure performance of a program, may have
  /// but does not require the `canRun` build target capability.
  public static let benchmark: Self = Self(rawValue: "benchmark")

  /// Target should be ignored by IDEs.
  public static let noIDE: Self = Self(rawValue: "no-ide")
}

public struct BuildTargetCapabilities: Codable, Hashable, Sendable {
  /// This target can be compiled by the BSP server.
  public var canCompile: Bool

  /// This target can be tested by the BSP server.
  public var canTest: Bool

  /// This target can be run by the BSP server.
  public var canRun: Bool

  public init(canCompile: Bool, canTest: Bool, canRun: Bool) {
    self.canCompile = canCompile
    self.canTest = canTest
    self.canRun = canRun
  }
}

/// The build target sources request is sent from the client to the server to
/// query for the list of text documents and directories that are belong to a
/// build target. The sources response must not include sources that are
/// external to the workspace.
public struct BuildTargetSources: RequestType, Hashable {
  public static let method: String = "buildTarget/sources"
  public typealias Response = BuildTargetSourcesResult

  public var targets: [BuildTargetIdentifier]

  public init(targets: [BuildTargetIdentifier]) {
    self.targets = targets
  }
}

public struct BuildTargetSourcesResult: ResponseType, Hashable {
  public var items: [SourcesItem]
}

public struct SourcesItem: Codable, Hashable, Sendable {
  public var target: BuildTargetIdentifier

  /// The text documents and directories that belong to this build target.
  public var sources: [SourceItem]
}

public struct SourceItem: Codable, Hashable, Sendable {
  /// Either a text document or a directory. A directory entry must end with a
  /// forward slash "/" and a directory entry implies that every nested text
  /// document within the directory belongs to this source item.
  public var uri: URI

  /// Type of file of the source item, such as whether it is file or directory.
  public var kind: SourceItemKind

  /// Indicates if this source is automatically generated by the build and is
  /// not intended to be manually edited by the user.
  public var generated: Bool
}

public enum SourceItemKind: Int, Codable, Hashable, Sendable {
  /// The source item references a normal file.
  case file = 1

  /// The source item references a directory.
  case directory = 2
}

/// The build target output paths request is sent from the client to the server
/// to query for the list of compilation output paths for a targets sources.
public struct BuildTargetOutputPaths: RequestType, Hashable {
  public static let method: String = "buildTarget/outputPaths"
  public typealias Response = BuildTargetOutputPathsResponse

  public var targets: [BuildTargetIdentifier]

  public init(targets: [BuildTargetIdentifier]) {
    self.targets = targets
  }
}

public struct BuildTargetOutputPathsResponse: ResponseType, Hashable {
  public var items: [OutputsItem]
}

public struct OutputsItem: Codable, Hashable, Sendable {
  public var target: BuildTargetIdentifier

  /// The output paths for sources that belong to this build target.
  public var outputPaths: [URI]
}

/// The build target changed notification is sent from the server to the client
/// to signal a change in a build target. The server communicates during the
/// initialize handshake whether this method is supported or not.
public struct BuildTargetsChangedNotification: NotificationType {
  public static let method: String = "buildTarget/didChange"

  public var changes: [BuildTargetEvent]

  public init(changes: [BuildTargetEvent]) {
    self.changes = changes
  }
}

public struct BuildTargetEvent: Codable, Hashable, Sendable {
  /// The identifier for the changed build target.
  public var target: BuildTargetIdentifier

  /// The kind of change for this build target.
  public var kind: BuildTargetEventKind?

  /// Any additional metadata about what information changed.
  public var data: LSPAny?

  public init(target: BuildTargetIdentifier, kind: BuildTargetEventKind?, data: LSPAny?) {
    self.target = target
    self.kind = kind
    self.data = data
  }
}

public enum BuildTargetEventKind: Int, Codable, Hashable, Sendable {
  /// The build target is new.
  case created = 1

  /// The build target has changed.
  case changed = 2

  /// The build target has been deleted.
  case deleted = 3
}