@@ -151,7 +151,7 @@ extension BuildSystemManager {
151
151
for document: DocumentURI ,
152
152
language: Language
153
153
) async -> FileBuildSettings ? {
154
- let mainFile = await mainFile ( for: document)
154
+ let mainFile = await mainFile ( for: document, language : language )
155
155
guard var settings = await buildSettings ( for: mainFile, language: language) else {
156
156
return nil
157
157
}
@@ -182,7 +182,7 @@ extension BuildSystemManager {
182
182
183
183
public func registerForChangeNotifications( for uri: DocumentURI , language: Language ) async {
184
184
logger. debug ( " registerForChangeNotifications( \( uri. forLogging) ) " )
185
- let mainFile = await mainFile ( for: uri)
185
+ let mainFile = await mainFile ( for: uri, language : language )
186
186
self . watchedFiles [ uri] = ( mainFile, language)
187
187
188
188
// Register for change notifications of the main file in the underlying build
@@ -274,7 +274,7 @@ extension BuildSystemManager: MainFilesDelegate {
274
274
public func mainFilesChanged( ) async {
275
275
var changedMainFileAssociations : Set < DocumentURI > = [ ]
276
276
for (file, ( oldMainFile, language) ) in self . watchedFiles {
277
- let newMainFile = await self . mainFile ( for: file, useCache: false )
277
+ let newMainFile = await self . mainFile ( for: file, language : language , useCache: false )
278
278
if newMainFile != oldMainFile {
279
279
self . watchedFiles [ file] = ( newMainFile, language)
280
280
changedMainFileAssociations. insert ( file)
@@ -303,7 +303,11 @@ extension BuildSystemManager: MainFilesDelegate {
303
303
/// For Swift or normal C files, this will be the file itself. For header
304
304
/// files, we pick a main file that includes the header since header files
305
305
/// don't have build settings by themselves.
306
- private func mainFile( for uri: DocumentURI , useCache: Bool = true ) async -> DocumentURI {
306
+ private func mainFile( for uri: DocumentURI , language: Language , useCache: Bool = true ) async -> DocumentURI {
307
+ if language == . swift {
308
+ // Swift doesn't have main files. Skip the main file provider query.
309
+ return uri
310
+ }
307
311
if useCache, let mainFile = self . watchedFiles [ uri] ? . mainFile {
308
312
// Performance optimization: We did already compute the main file and have
309
313
// it cached. We can just return it.
0 commit comments