diff --git a/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/lsp/ApolloLspAppService.kt b/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/lsp/ApolloLspAppService.kt index ecb9f8c3665..6f99081391a 100644 --- a/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/lsp/ApolloLspAppService.kt +++ b/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/lsp/ApolloLspAppService.kt @@ -12,6 +12,10 @@ import com.intellij.openapi.application.runWriteAction import com.intellij.openapi.components.Service import com.intellij.openapi.fileTypes.ex.FileTypeManagerEx import com.intellij.openapi.project.Project +import com.intellij.openapi.project.guessProjectDir +import com.intellij.openapi.vfs.VirtualFileManager +import com.intellij.openapi.vfs.newvfs.BulkFileListener +import com.intellij.openapi.vfs.newvfs.events.VFileEvent import com.intellij.util.application @Service(Service.Level.APP) @@ -49,6 +53,7 @@ class ApolloLspProjectService(private val project: Project) : Disposable { init { logd() startObserveSettings() + startObserveVfsChanges() } private fun startObserveSettings() { @@ -76,6 +81,22 @@ class ApolloLspProjectService(private val project: Project) : Disposable { }) } + private fun startObserveVfsChanges() { + project.messageBus.connect(this).subscribe(VirtualFileManager.VFS_CHANGES, object : BulkFileListener { + override fun after(events: MutableList) { + for (event in events) { + val vFile = event.file!! + val isSupergraphYaml = vFile == project.guessProjectDir()?.findChild("supergraph.yaml") || + vFile.path == project.projectSettingsState.lspPathToSuperGraphYaml + if (isSupergraphYaml) { + logd("supergraph.yaml changed: restarting Apollo LSP") + restartApolloLsp() + } + } + } + }) + } + override fun dispose() { logd() } diff --git a/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/rover/RoverHelper.kt b/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/rover/RoverHelper.kt index 0cefeb5aa89..33670332806 100644 --- a/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/rover/RoverHelper.kt +++ b/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/rover/RoverHelper.kt @@ -5,7 +5,9 @@ import com.intellij.execution.configurations.GeneralCommandLine import com.intellij.execution.processTools.getResultStdoutStr import com.intellij.execution.processTools.mapFlat import com.intellij.openapi.project.Project +import com.intellij.openapi.project.guessProjectDir import kotlinx.coroutines.runBlocking +import java.io.File object RoverHelper { private fun getRoverBinDirectory() = "${System.getProperty("user.home")}/.rover/bin" @@ -20,9 +22,18 @@ object RoverHelper { setWorkDirectory(getRoverBinDirectory()) getEnvironment().put("RUST_BACKTRACE", "full") addParameter("lsp") - if (project.projectSettingsState.lspPassPathToSuperGraphYaml && project.projectSettingsState.lspPathToSuperGraphYaml.isNotBlank()) { + if (project.projectSettingsState.lspPassPathToSuperGraphYaml && + project.projectSettingsState.lspPathToSuperGraphYaml.isNotBlank() && + File(project.projectSettingsState.lspPathToSuperGraphYaml).exists() + ) { addParameter("--supergraph-config") addParameter(project.projectSettingsState.lspPathToSuperGraphYaml) + } else { + val superGraphYamlFilePath = project.guessProjectDir()?.findChild("supergraph.yaml")?.path + if (superGraphYamlFilePath != null) { + addParameter("--supergraph-config") + addParameter(superGraphYamlFilePath) + } } if (project.projectSettingsState.lspPassAdditionalArguments && project.projectSettingsState.lspAdditionalArguments.isNotBlank()) { addParameters(project.projectSettingsState.lspAdditionalArguments.split(' ')) diff --git a/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/settings/ProjectSettingsService.kt b/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/settings/ProjectSettingsService.kt index 27170d81ac4..df8eb33dead 100644 --- a/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/settings/ProjectSettingsService.kt +++ b/intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/settings/ProjectSettingsService.kt @@ -132,6 +132,7 @@ class ProjectSettingsService(private val project: Project) : PersistentStateComp val superGraphYamlFilePath = project.guessProjectDir()?.findChild("supergraph.yaml")?.path if (superGraphYamlFilePath != null) { lspPathToSuperGraphYaml = superGraphYamlFilePath + lspPassPathToSuperGraphYaml = true } else { lspPassPathToSuperGraphYaml = false }