@@ -48,7 +48,14 @@ fileprivate enum Cachable<Value> {
48
48
///
49
49
/// Provides build settings from a `CompilationDatabase` found by searching a project. For now, only
50
50
/// one compilation database, located at the project root.
51
- package actor CompilationDatabaseBuildSystem {
51
+ package actor CompilationDatabaseBuildSystem : BuiltInBuildSystem {
52
+ static package func projectRoot( for workspaceFolder: AbsolutePath , options: SourceKitLSPOptions ) -> AbsolutePath ? {
53
+ if tryLoadCompilationDatabase ( directory: workspaceFolder) != nil {
54
+ return workspaceFolder
55
+ }
56
+ return nil
57
+ }
58
+
52
59
/// The compilation database.
53
60
var compdb : CompilationDatabase ? = nil {
54
61
didSet {
@@ -58,14 +65,12 @@ package actor CompilationDatabaseBuildSystem {
58
65
}
59
66
}
60
67
61
- package let connectionToSourceKitLSP : any Connection
68
+ private let connectionToSourceKitLSP : any Connection
69
+ private let searchPaths : [ RelativePath ]
70
+ private let fileSystem : FileSystem
62
71
63
72
package let projectRoot : AbsolutePath
64
73
65
- let searchPaths : [ RelativePath ]
66
-
67
- let fileSystem : FileSystem
68
-
69
74
private var _indexStorePath : Cachable < AbsolutePath ? > = . noValue
70
75
package var indexStorePath : AbsolutePath ? {
71
76
_indexStorePath. get {
@@ -87,6 +92,12 @@ package actor CompilationDatabaseBuildSystem {
87
92
}
88
93
}
89
94
95
+ package var indexDatabasePath : AbsolutePath ? {
96
+ indexStorePath? . parentDirectory. appending ( component: " IndexDatabase " )
97
+ }
98
+
99
+ package nonisolated var supportsPreparation : Bool { false }
100
+
90
101
package init ? (
91
102
projectRoot: AbsolutePath ,
92
103
searchPaths: [ RelativePath ] ,
@@ -103,21 +114,6 @@ package actor CompilationDatabaseBuildSystem {
103
114
return nil
104
115
}
105
116
}
106
- }
107
-
108
- extension CompilationDatabaseBuildSystem : BuiltInBuildSystem {
109
- static package func projectRoot( for workspaceFolder: AbsolutePath , options: SourceKitLSPOptions ) -> AbsolutePath ? {
110
- if tryLoadCompilationDatabase ( directory: workspaceFolder) != nil {
111
- return workspaceFolder
112
- }
113
- return nil
114
- }
115
-
116
- package nonisolated var supportsPreparation : Bool { false }
117
-
118
- package var indexDatabasePath : AbsolutePath ? {
119
- indexStorePath? . parentDirectory. appending ( component: " IndexDatabase " )
120
- }
121
117
122
118
package func buildTargets( request: WorkspaceBuildTargetsRequest ) async throws -> WorkspaceBuildTargetsResponse {
123
119
return WorkspaceBuildTargetsResponse ( targets: [
@@ -135,10 +131,7 @@ extension CompilationDatabaseBuildSystem: BuiltInBuildSystem {
135
131
}
136
132
137
133
package func buildTargetSources( request: BuildTargetSourcesRequest ) async throws -> BuildTargetSourcesResponse {
138
- guard request. targets. contains ( . dummy) else {
139
- return BuildTargetSourcesResponse ( items: [ ] )
140
- }
141
- guard let compdb else {
134
+ guard request. targets. contains ( . dummy) , let compdb else {
142
135
return BuildTargetSourcesResponse ( items: [ ] )
143
136
}
144
137
return BuildTargetSourcesResponse ( items: [ SourcesItem ( target: . dummy, sources: compdb. sourceItems) ] )
@@ -157,7 +150,7 @@ extension CompilationDatabaseBuildSystem: BuiltInBuildSystem {
157
150
package func sourceKitOptions(
158
151
request: TextDocumentSourceKitOptionsRequest
159
152
) async throws -> TextDocumentSourceKitOptionsResponse ? {
160
- guard let db = database ( for : request . textDocument . uri ) , let cmd = db [ request. textDocument. uri] . first else {
153
+ guard let compdb , let cmd = compdb [ request. textDocument. uri] . first else {
161
154
return nil
162
155
}
163
156
return TextDocumentSourceKitOptionsResponse (
@@ -166,36 +159,10 @@ extension CompilationDatabaseBuildSystem: BuiltInBuildSystem {
166
159
)
167
160
}
168
161
169
- package func waitForUpBuildSystemUpdates ( request: WorkspaceWaitForBuildSystemUpdatesRequest ) async -> VoidResponse {
162
+ package func waitForBuildSystemUpdates ( request: WorkspaceWaitForBuildSystemUpdatesRequest ) async -> VoidResponse {
170
163
return VoidResponse ( )
171
164
}
172
165
173
- private func database( for uri: DocumentURI ) -> CompilationDatabase ? {
174
- if let url = uri. fileURL, let path = try ? AbsolutePath ( validating: url. path) {
175
- return database ( for: path)
176
- }
177
- return compdb
178
- }
179
-
180
- private func database( for path: AbsolutePath ) -> CompilationDatabase ? {
181
- if compdb == nil {
182
- var dir = path
183
- while !dir. isRoot {
184
- dir = dir. parentDirectory
185
- if let db = tryLoadCompilationDatabase ( directory: dir, additionalSearchPaths: searchPaths, fileSystem) {
186
- compdb = db
187
- break
188
- }
189
- }
190
- }
191
-
192
- if compdb == nil {
193
- logger. error ( " Could not open compilation database for \( path) " )
194
- }
195
-
196
- return compdb
197
- }
198
-
199
166
private func fileEventShouldTriggerCompilationDatabaseReload( event: FileEvent ) -> Bool {
200
167
switch event. uri. fileURL? . lastPathComponent {
201
168
case " compile_commands.json " , " compile_flags.txt " :
0 commit comments