@@ -30,7 +30,6 @@ class SourcePath(
30
30
private val parseDataWriteLock = ReentrantLock ()
31
31
32
32
private val indexAsync = AsyncExecutor ()
33
- private var indexInitialized: Boolean = false
34
33
var indexEnabled: Boolean by indexingConfig::enabled
35
34
val index = SymbolIndex ()
36
35
@@ -105,7 +104,7 @@ class SourcePath(
105
104
compiledFile = parsed
106
105
}
107
106
108
- refreshIndexes(container, listOfNotNull(oldFile), listOfNotNull(this ))
107
+ refreshWorkspaceIndexes( listOfNotNull(oldFile), listOfNotNull(this ))
109
108
}
110
109
111
110
private fun doCompileIfChanged () {
@@ -163,7 +162,7 @@ class SourcePath(
163
162
}
164
163
165
164
fun delete (uri : URI ) {
166
- files[uri]?.let { refreshIndexes(files[uri]?.compiledContainer !! , listOf (it), listOf ()) }
165
+ files[uri]?.let { refreshWorkspaceIndexes( listOf (it), listOf ()) }
167
166
168
167
files.remove(uri)
169
168
}
@@ -231,7 +230,7 @@ class SourcePath(
231
230
232
231
// Only index normal files, not build files
233
232
if (kind == CompilationKind .DEFAULT ) {
234
- refreshIndexes(container, oldFiles, parse.keys.toList())
233
+ refreshWorkspaceIndexes( oldFiles, parse.keys.toList())
235
234
}
236
235
237
236
return context
@@ -247,27 +246,47 @@ class SourcePath(
247
246
return CompositeBindingContext .create(combined)
248
247
}
249
248
249
+ fun compileAllFiles () {
250
+ // TODO: Investigate the possibility of compiling all files at once, instead of iterating here
251
+ // At the moment, compiling all files at once sometimes leads to an internal error from the TopDownAnalyzer
252
+ files.keys.forEach {
253
+ compileFiles(listOf (it))
254
+ }
255
+ }
256
+
257
+ fun refreshDependencyIndexes () {
258
+ compileAllFiles()
259
+
260
+ val container = files.values.first { it.compiledContainer != null }.compiledContainer
261
+ if (container != null ) {
262
+ refreshDependencyIndexes(container)
263
+ }
264
+ }
265
+
250
266
/* *
251
267
* Refreshes the indexes. If already done, refreshes only the declarations in the files that were changed.
252
268
*/
253
- private fun refreshIndexes ( container : ComponentProvider , oldFiles : List <SourceFile >, newFiles : List <SourceFile >) = indexAsync.execute {
269
+ private fun refreshWorkspaceIndexes ( oldFiles : List <SourceFile >, newFiles : List <SourceFile >) = indexAsync.execute {
254
270
if (indexEnabled) {
255
- val module = container.getService(ModuleDescriptor ::class .java)
256
271
val oldDeclarations = getDeclarationDescriptors(oldFiles)
257
272
val newDeclarations = getDeclarationDescriptors(newFiles)
258
273
259
- // Index all the declarations except any new declarations that were just compiled
260
- // TODO: Move this logic to a different place when re-indexing is triggered on configuration changes
261
- if (! indexInitialized) {
262
- indexInitialized = true
263
- index.refresh(module, newDeclarations)
264
- }
265
-
266
274
// Index the new declarations in the Kotlin source files that were just compiled, removing the old ones
267
275
index.updateIndexes(oldDeclarations, newDeclarations)
268
276
}
269
277
}
270
278
279
+ /* *
280
+ * Refreshes the indexes. If already done, refreshes only the declarations in the files that were changed.
281
+ */
282
+ private fun refreshDependencyIndexes (container : ComponentProvider ) = indexAsync.execute {
283
+ if (indexEnabled) {
284
+ val module = container.getService(ModuleDescriptor ::class .java)
285
+ val declarations = getDeclarationDescriptors(files.values)
286
+ index.refresh(module, declarations)
287
+ }
288
+ }
289
+
271
290
// Gets all the declaration descriptors for the collection of files
272
291
private fun getDeclarationDescriptors (files : Collection <SourceFile >) =
273
292
files.flatMap { file ->
0 commit comments