@@ -132,7 +132,7 @@ extension BuildSystemManager {
132
132
for document: DocumentURI ,
133
133
language: Language
134
134
) async -> FileBuildSettings ? {
135
- let mainFile = await mainFile ( for: document)
135
+ let mainFile = await mainFile ( for: document, language : language )
136
136
guard var settings = await buildSettings ( for: mainFile, language: language) else {
137
137
return nil
138
138
}
@@ -147,7 +147,7 @@ extension BuildSystemManager {
147
147
148
148
public func registerForChangeNotifications( for uri: DocumentURI , language: Language ) async {
149
149
logger. debug ( " registerForChangeNotifications( \( uri. forLogging) ) " )
150
- let mainFile = await mainFile ( for: uri)
150
+ let mainFile = await mainFile ( for: uri, language : language )
151
151
self . watchedFiles [ uri] = ( mainFile, language)
152
152
153
153
// Register for change notifications of the main file in the underlying build
@@ -239,7 +239,7 @@ extension BuildSystemManager: MainFilesDelegate {
239
239
public func mainFilesChanged( ) async {
240
240
var changedMainFileAssociations : Set < DocumentURI > = [ ]
241
241
for (file, ( oldMainFile, language) ) in self . watchedFiles {
242
- let newMainFile = await self . mainFile ( for: file, useCache: false )
242
+ let newMainFile = await self . mainFile ( for: file, language : language , useCache: false )
243
243
if newMainFile != oldMainFile {
244
244
self . watchedFiles [ file] = ( newMainFile, language)
245
245
changedMainFileAssociations. insert ( file)
@@ -268,7 +268,11 @@ extension BuildSystemManager: MainFilesDelegate {
268
268
/// For Swift or normal C files, this will be the file itself. For header
269
269
/// files, we pick a main file that includes the header since header files
270
270
/// don't have build settings by themselves.
271
- private func mainFile( for uri: DocumentURI , useCache: Bool = true ) async -> DocumentURI {
271
+ private func mainFile( for uri: DocumentURI , language: Language , useCache: Bool = true ) async -> DocumentURI {
272
+ if language == . swift {
273
+ // Swift doesn't have main files. Skip the main file provider query.
274
+ return uri
275
+ }
272
276
if useCache, let mainFile = self . watchedFiles [ uri] ? . mainFile {
273
277
// Performance optimization: We did already compute the main file and have
274
278
// it cached. We can just return it.
0 commit comments