Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IJ Plugin] Rover: always pass path to supergraph.yaml if present #6384

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -49,6 +53,7 @@ class ApolloLspProjectService(private val project: Project) : Disposable {
init {
logd()
startObserveSettings()
startObserveVfsChanges()
}

private fun startObserveSettings() {
Expand Down Expand Up @@ -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<out VFileEvent>) {
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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(' '))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading