Merge pull request #7692 from mq200/fix-added-folders-not-triggering-reindex
refresh workspace dirs when folders are added
This commit is contained in:
commit
a9f9ee2f3f
4 changed files with 57 additions and 1 deletions
|
|
@ -825,7 +825,6 @@ export class Core {
|
|||
if (data?.shouldClearIndexes) {
|
||||
await this.codeBaseIndexer.clearIndexes();
|
||||
}
|
||||
|
||||
const dirs = data?.dirs ?? (await this.ide.getWorkspaceDirs());
|
||||
await this.codeBaseIndexer.refreshCodebaseIndex(dirs);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -29,7 +29,9 @@ import java.nio.charset.StandardCharsets
|
|||
import java.nio.file.Paths
|
||||
import javax.swing.*
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.module.ModuleManager
|
||||
import com.intellij.openapi.project.ModuleListener
|
||||
import com.intellij.openapi.roots.ModuleRootManager
|
||||
import com.intellij.openapi.vfs.VirtualFileManager
|
||||
import com.intellij.openapi.vfs.newvfs.BulkFileListener
|
||||
|
|
@ -39,6 +41,7 @@ import com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent
|
|||
import com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent
|
||||
import com.intellij.ide.ui.LafManagerListener
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.util.Function
|
||||
|
||||
fun showTutorial(project: Project) {
|
||||
val tutorialFileName = getTutorialFileName()
|
||||
|
|
@ -193,6 +196,41 @@ class ContinuePluginStartupActivity : StartupActivity, DumbAware {
|
|||
}
|
||||
})
|
||||
|
||||
// Handle workspace directories changes
|
||||
connection.subscribe(
|
||||
ModuleListener.TOPIC,
|
||||
object : ModuleListener {
|
||||
override fun modulesAdded(project: Project, modules: MutableList<out Module>) {
|
||||
|
||||
val allModulePaths = ModuleManager.getInstance(project).modules
|
||||
.flatMap { module -> ModuleRootManager.getInstance(module).contentRoots.mapNotNull { it.toUriOrNull() } }
|
||||
|
||||
val topLevelModulePaths = allModulePaths
|
||||
.filter { modulePath -> allModulePaths.none { it != modulePath && modulePath.startsWith(it) } }
|
||||
|
||||
continuePluginService.workspacePaths = topLevelModulePaths.toTypedArray();
|
||||
}
|
||||
|
||||
override fun moduleRemoved(project: Project, module: Module) {
|
||||
val removedPaths = ModuleRootManager.getInstance(module).contentRoots.mapNotNull { it.toUriOrNull() } ;
|
||||
continuePluginService.workspacePaths = continuePluginService.workspacePaths?.toList()?.filter { path -> removedPaths.none {removedPath -> path == removedPath }}?.toTypedArray();
|
||||
}
|
||||
|
||||
override fun modulesRenamed(
|
||||
project: Project,
|
||||
modules: MutableList<out Module>,
|
||||
oldNameProvider: Function<in Module, String>
|
||||
) {
|
||||
val allModulePaths = ModuleManager.getInstance(project).modules
|
||||
.flatMap { module -> ModuleRootManager.getInstance(module).contentRoots.mapNotNull { it.toUriOrNull() } }
|
||||
|
||||
val topLevelModulePaths = allModulePaths
|
||||
.filter { modulePath -> allModulePaths.none { it != modulePath && modulePath.startsWith(it) } }
|
||||
|
||||
continuePluginService.workspacePaths = topLevelModulePaths.toTypedArray()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, object : FileEditorManagerListener {
|
||||
override fun fileClosed(source: FileEditorManager, file: VirtualFile) {
|
||||
|
|
|
|||
|
|
@ -503,6 +503,21 @@ export class VsCodeExtension {
|
|||
});
|
||||
});
|
||||
|
||||
vscode.workspace.onDidChangeWorkspaceFolders(async (event) => {
|
||||
const dirs = vscode.workspace.workspaceFolders?.map(
|
||||
(folder) => folder.uri,
|
||||
);
|
||||
|
||||
this.ideUtils.setWokspaceDirectories(dirs);
|
||||
|
||||
this.core.invoke("index/forceReIndex", {
|
||||
dirs: [
|
||||
...event.added.map((folder) => folder.uri.toString()),
|
||||
...event.removed.map((folder) => folder.uri.toString()),
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
vscode.workspace.onDidOpenTextDocument(async (event) => {
|
||||
console.log("onDidOpenTextDocument");
|
||||
const ast = await getAst(event.fileName, event.getText());
|
||||
|
|
|
|||
|
|
@ -74,6 +74,10 @@ export class VsCodeIdeUtils {
|
|||
return this._workspaceDirectories;
|
||||
}
|
||||
|
||||
setWokspaceDirectories(dirs: vscode.Uri[] | undefined): void {
|
||||
this._workspaceDirectories = dirs;
|
||||
}
|
||||
|
||||
getUniqueId() {
|
||||
return getUniqueId();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue