Skip to content

Commit 6cff70a

Browse files
authored
Merge pull request #950 from ahoppen/ahoppen/no-main-file-provider-swift
Don't call into the `MainFileProvider` for Swift files
2 parents c615da1 + 1e32709 commit 6cff70a

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
@@ -132,7 +132,7 @@ extension BuildSystemManager {
132132
for document: DocumentURI,
133133
language: Language
134134
) async -> FileBuildSettings? {
135-
let mainFile = await mainFile(for: document)
135+
let mainFile = await mainFile(for: document, language: language)
136136
guard var settings = await buildSettings(for: mainFile, language: language) else {
137137
return nil
138138
}
@@ -147,7 +147,7 @@ extension BuildSystemManager {
147147

148148
public func registerForChangeNotifications(for uri: DocumentURI, language: Language) async {
149149
logger.debug("registerForChangeNotifications(\(uri.forLogging))")
150-
let mainFile = await mainFile(for: uri)
150+
let mainFile = await mainFile(for: uri, language: language)
151151
self.watchedFiles[uri] = (mainFile, language)
152152

153153
// Register for change notifications of the main file in the underlying build
@@ -239,7 +239,7 @@ extension BuildSystemManager: MainFilesDelegate {
239239
public func mainFilesChanged() async {
240240
var changedMainFileAssociations: Set<DocumentURI> = []
241241
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)
243243
if newMainFile != oldMainFile {
244244
self.watchedFiles[file] = (newMainFile, language)
245245
changedMainFileAssociations.insert(file)
@@ -268,7 +268,11 @@ extension BuildSystemManager: MainFilesDelegate {
268268
/// For Swift or normal C files, this will be the file itself. For header
269269
/// files, we pick a main file that includes the header since header files
270270
/// 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+
}
272276
if useCache, let mainFile = self.watchedFiles[uri]?.mainFile {
273277
// Performance optimization: We did already compute the main file and have
274278
// it cached. We can just return it.

0 commit comments

Comments
 (0)