Skip to content

Commit 1e32709

Browse files
committed
Don't call into the MainFileProvider for Swift files
Swift doesn’t have header and main files. A Swift file is always its own main file. Skip the call into the main file provider.
1 parent d043dc0 commit 1e32709

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Sources/SKCore/BuildSystemManager.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ extension BuildSystemManager {
151151
for document: DocumentURI,
152152
language: Language
153153
) async -> FileBuildSettings? {
154-
let mainFile = await mainFile(for: document)
154+
let mainFile = await mainFile(for: document, language: language)
155155
guard var settings = await buildSettings(for: mainFile, language: language) else {
156156
return nil
157157
}
@@ -182,7 +182,7 @@ extension BuildSystemManager {
182182

183183
public func registerForChangeNotifications(for uri: DocumentURI, language: Language) async {
184184
logger.debug("registerForChangeNotifications(\(uri.forLogging))")
185-
let mainFile = await mainFile(for: uri)
185+
let mainFile = await mainFile(for: uri, language: language)
186186
self.watchedFiles[uri] = (mainFile, language)
187187

188188
// Register for change notifications of the main file in the underlying build
@@ -274,7 +274,7 @@ extension BuildSystemManager: MainFilesDelegate {
274274
public func mainFilesChanged() async {
275275
var changedMainFileAssociations: Set<DocumentURI> = []
276276
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)
278278
if newMainFile != oldMainFile {
279279
self.watchedFiles[file] = (newMainFile, language)
280280
changedMainFileAssociations.insert(file)
@@ -303,7 +303,11 @@ extension BuildSystemManager: MainFilesDelegate {
303303
/// For Swift or normal C files, this will be the file itself. For header
304304
/// files, we pick a main file that includes the header since header files
305305
/// 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+
}
307311
if useCache, let mainFile = self.watchedFiles[uri]?.mainFile {
308312
// Performance optimization: We did already compute the main file and have
309313
// it cached. We can just return it.

0 commit comments

Comments
 (0)