Skip to content

Commit a9f9ee2

Browse files
authored
Merge pull request #7692 from mq200/fix-added-folders-not-triggering-reindex
refresh workspace dirs when folders are added
2 parents f749116 + e73ee07 commit a9f9ee2

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

core/core.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,6 @@ export class Core {
825825
if (data?.shouldClearIndexes) {
826826
await this.codeBaseIndexer.clearIndexes();
827827
}
828-
829828
const dirs = data?.dirs ?? (await this.ide.getWorkspaceDirs());
830829
await this.codeBaseIndexer.refreshCodebaseIndex(dirs);
831830
});

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginStartupActivity.kt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ import java.nio.charset.StandardCharsets
2929
import java.nio.file.Paths
3030
import javax.swing.*
3131
import com.intellij.openapi.components.service
32+
import com.intellij.openapi.module.Module
3233
import com.intellij.openapi.module.ModuleManager
34+
import com.intellij.openapi.project.ModuleListener
3335
import com.intellij.openapi.roots.ModuleRootManager
3436
import com.intellij.openapi.vfs.VirtualFileManager
3537
import com.intellij.openapi.vfs.newvfs.BulkFileListener
@@ -39,6 +41,7 @@ import com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent
3941
import com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent
4042
import com.intellij.ide.ui.LafManagerListener
4143
import com.intellij.openapi.vfs.VirtualFile
44+
import com.intellij.util.Function
4245

4346
fun showTutorial(project: Project) {
4447
val tutorialFileName = getTutorialFileName()
@@ -193,6 +196,41 @@ class ContinuePluginStartupActivity : StartupActivity, DumbAware {
193196
}
194197
})
195198

199+
// Handle workspace directories changes
200+
connection.subscribe(
201+
ModuleListener.TOPIC,
202+
object : ModuleListener {
203+
override fun modulesAdded(project: Project, modules: MutableList<out Module>) {
204+
205+
val allModulePaths = ModuleManager.getInstance(project).modules
206+
.flatMap { module -> ModuleRootManager.getInstance(module).contentRoots.mapNotNull { it.toUriOrNull() } }
207+
208+
val topLevelModulePaths = allModulePaths
209+
.filter { modulePath -> allModulePaths.none { it != modulePath && modulePath.startsWith(it) } }
210+
211+
continuePluginService.workspacePaths = topLevelModulePaths.toTypedArray();
212+
}
213+
214+
override fun moduleRemoved(project: Project, module: Module) {
215+
val removedPaths = ModuleRootManager.getInstance(module).contentRoots.mapNotNull { it.toUriOrNull() } ;
216+
continuePluginService.workspacePaths = continuePluginService.workspacePaths?.toList()?.filter { path -> removedPaths.none {removedPath -> path == removedPath }}?.toTypedArray();
217+
}
218+
219+
override fun modulesRenamed(
220+
project: Project,
221+
modules: MutableList<out Module>,
222+
oldNameProvider: Function<in Module, String>
223+
) {
224+
val allModulePaths = ModuleManager.getInstance(project).modules
225+
.flatMap { module -> ModuleRootManager.getInstance(module).contentRoots.mapNotNull { it.toUriOrNull() } }
226+
227+
val topLevelModulePaths = allModulePaths
228+
.filter { modulePath -> allModulePaths.none { it != modulePath && modulePath.startsWith(it) } }
229+
230+
continuePluginService.workspacePaths = topLevelModulePaths.toTypedArray()
231+
}
232+
}
233+
)
196234

197235
connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, object : FileEditorManagerListener {
198236
override fun fileClosed(source: FileEditorManager, file: VirtualFile) {

extensions/vscode/src/extension/VsCodeExtension.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,21 @@ export class VsCodeExtension {
503503
});
504504
});
505505

506+
vscode.workspace.onDidChangeWorkspaceFolders(async (event) => {
507+
const dirs = vscode.workspace.workspaceFolders?.map(
508+
(folder) => folder.uri,
509+
);
510+
511+
this.ideUtils.setWokspaceDirectories(dirs);
512+
513+
this.core.invoke("index/forceReIndex", {
514+
dirs: [
515+
...event.added.map((folder) => folder.uri.toString()),
516+
...event.removed.map((folder) => folder.uri.toString()),
517+
],
518+
});
519+
});
520+
506521
vscode.workspace.onDidOpenTextDocument(async (event) => {
507522
console.log("onDidOpenTextDocument");
508523
const ast = await getAst(event.fileName, event.getText());

extensions/vscode/src/util/ideUtils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ export class VsCodeIdeUtils {
7474
return this._workspaceDirectories;
7575
}
7676

77+
setWokspaceDirectories(dirs: vscode.Uri[] | undefined): void {
78+
this._workspaceDirectories = dirs;
79+
}
80+
7781
getUniqueId() {
7882
return getUniqueId();
7983
}

0 commit comments

Comments
 (0)