Skip to content

Commit a3086d7

Browse files
committed
If a build server doesn’t specify -index-store-path in the SourceKit options, add it during background indexing
1 parent 1727a7b commit a3086d7

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

Documentation/Configuration File.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ The structure of the file is currently not guaranteed to be stable. Options may
3737
- `buildSettingsTimeout: integer`: Number of milliseconds to wait for build settings from the build system before using fallback build settings.
3838
- `clangdOptions: string[]`: Extra command line arguments passed to `clangd` when launching it.
3939
- `index`: Options related to indexing.
40-
- `indexStorePath: string`: Directory in which a separate compilation stores the index store. By default, inferred from the build system.
41-
- `indexDatabasePath: string`: Directory in which the indexstore-db should be stored. By default, inferred from the build system.
4240
- `indexPrefixMap: [string: string]`: Path remappings for remapping index data for local use.
4341
- `updateIndexStoreTimeout: integer`: Number of seconds to wait for an update index store task to finish before killing it.
4442
- `logging`: Options related to logging, changing SourceKit-LSP’s logging behavior on non-Apple platforms. On Apple platforms, logging is done through the [system log](Diagnose%20Bundle.md#Enable%20Extended%20Logging). These options can only be set globally and not per workspace.

Sources/BuildSystemIntegration/FixedCompilationDatabaseBuildSystem.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import LanguageServerProtocol
2424
#endif
2525

2626
func lastIndexStorePathArgument(in compilerArgs: [String]) -> String? {
27-
for i in compilerArgs.indices.reversed() {
28-
if compilerArgs[i] == "-index-store-path" && i + 1 < compilerArgs.count {
29-
return compilerArgs[i + 1]
30-
}
27+
if let indexStorePathIndex = compilerArgs.lastIndex(of: "-index-store-path"),
28+
indexStorePathIndex + 1 < compilerArgs.count
29+
{
30+
return compilerArgs[indexStorePathIndex + 1]
3131
}
3232
return nil
3333
}

Sources/SemanticIndex/UpdateIndexStoreTaskDescription.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ package struct UpdateIndexStoreTaskDescription: IndexTaskDescription {
311311
return
312312
}
313313

314-
let args =
314+
var args =
315315
try [swiftc.filePath] + buildSettings.compilerArguments + [
316316
"-index-file",
317317
"-index-file-path", uri.pseudoPath,
@@ -320,6 +320,25 @@ package struct UpdateIndexStoreTaskDescription: IndexTaskDescription {
320320
// Fake an output path so that we get a different unit file for every Swift file we background index
321321
"-index-unit-output-path", uri.pseudoPath + ".o",
322322
]
323+
guard let buildSystemIndexStorePath = await self.buildSystemManager.initializationData?.indexStorePath else {
324+
struct NoIndexStorePathError: Error {}
325+
throw NoIndexStorePathError()
326+
}
327+
if let indexStorePathIndex = args.lastIndex(of: "-index-store-path"), indexStorePathIndex + 1 < args.count {
328+
let indexStorePath = args[indexStorePathIndex + 1]
329+
if indexStorePath != buildSystemIndexStorePath {
330+
logger.error(
331+
"""
332+
Compiler arguments for \(uri) specify index store path \(indexStorePath) but build system specified an \
333+
incompatible index store path \(buildSystemIndexStorePath). Overriding with the path specified by the build \
334+
system.
335+
"""
336+
)
337+
args[indexStorePathIndex + 1] = buildSystemIndexStorePath
338+
}
339+
} else {
340+
args += ["-index-store-path", buildSystemIndexStorePath]
341+
}
323342

324343
try await runIndexingProcess(
325344
indexFile: uri,

config.schema.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,6 @@
126126
"description" : "Options related to indexing.",
127127
"markdownDescription" : "Options related to indexing.",
128128
"properties" : {
129-
"indexDatabasePath" : {
130-
"description" : "Directory in which the indexstore-db should be stored. By default, inferred from the build system.",
131-
"markdownDescription" : "Directory in which the indexstore-db should be stored. By default, inferred from the build system.",
132-
"type" : "string"
133-
},
134129
"indexPrefixMap" : {
135130
"additionalProperties" : {
136131
"type" : "string"
@@ -139,11 +134,6 @@
139134
"markdownDescription" : "Path remappings for remapping index data for local use.",
140135
"type" : "object"
141136
},
142-
"indexStorePath" : {
143-
"description" : "Directory in which a separate compilation stores the index store. By default, inferred from the build system.",
144-
"markdownDescription" : "Directory in which a separate compilation stores the index store. By default, inferred from the build system.",
145-
"type" : "string"
146-
},
147137
"updateIndexStoreTimeout" : {
148138
"description" : "Number of seconds to wait for an update index store task to finish before killing it.",
149139
"markdownDescription" : "Number of seconds to wait for an update index store task to finish before killing it.",

0 commit comments

Comments
 (0)