@@ -20,6 +20,7 @@ import com.intellij.execution.process.ProcessEvent
20
20
import com.intellij.icons.AllIcons
21
21
import com.intellij.openapi.actionSystem.ActionManager
22
22
import com.intellij.openapi.actionSystem.AnActionEvent
23
+ import com.intellij.openapi.components.service
23
24
import com.intellij.openapi.diagnostic.logger
24
25
import com.intellij.openapi.progress.ProcessCanceledException
25
26
import com.intellij.openapi.progress.ProgressIndicator
@@ -38,13 +39,12 @@ import org.rust.cargo.project.settings.toolchain
38
39
import org.rust.cargo.project.workspace.CargoWorkspace
39
40
import org.rust.cargo.project.workspace.PackageOrigin
40
41
import org.rust.cargo.project.workspace.StandardLibrary
42
+ import org.rust.cargo.runconfig.buildtool.CargoBuildAdapterBase
43
+ import org.rust.cargo.runconfig.buildtool.CargoBuildContextBase
41
44
import org.rust.cargo.runconfig.command.workingDirectory
42
45
import org.rust.cargo.toolchain.RsToolchainBase
43
46
import org.rust.cargo.toolchain.impl.RustcVersion
44
- import org.rust.cargo.toolchain.tools.Rustup
45
- import org.rust.cargo.toolchain.tools.cargoOrWrapper
46
- import org.rust.cargo.toolchain.tools.rustc
47
- import org.rust.cargo.toolchain.tools.rustup
47
+ import org.rust.cargo.toolchain.tools.*
48
48
import org.rust.cargo.util.DownloadResult
49
49
import org.rust.openapiext.TaskResult
50
50
import org.rust.stdext.mapNotNullToSet
@@ -112,7 +112,7 @@ class CargoSyncTask(
112
112
val stdlibStatus = CargoProject .UpdateStatus .UpdateFailed (" Project directory does not exist" )
113
113
CargoProjectWithStdlib (cargoProject.copy(stdlibStatus = stdlibStatus), null )
114
114
} else {
115
- val context = SyncContext (project, cargoProject, toolchain, indicator, childProgress)
115
+ val context = SyncContext (project, cargoProject, toolchain, indicator, syncProgress.id, childProgress)
116
116
val rustcInfoResult = fetchRustcInfo(context)
117
117
val rustcInfo = (rustcInfoResult as ? TaskResult .Ok )?.value
118
118
val cargoProjectWithRustcInfoAndWorkspace = cargoProject.withRustcInfo(rustcInfoResult)
@@ -137,7 +137,7 @@ class CargoSyncTask(
137
137
buildContentDescriptor.isActivateToolWindowWhenAdded = false
138
138
buildContentDescriptor.isNavigateToError = project.rustSettings.autoShowErrorsInEditor
139
139
val refreshAction = ActionManager .getInstance().getAction(" Cargo.RefreshCargoProject" )
140
- val descriptor = DefaultBuildDescriptor (" Cargo " , " Cargo" , project.basePath!! , System .currentTimeMillis())
140
+ val descriptor = DefaultBuildDescriptor (Any () , " Cargo" , project.basePath!! , System .currentTimeMillis())
141
141
.withContentDescriptor { buildContentDescriptor }
142
142
.withRestartAction(refreshAction)
143
143
.withRestartAction(StopAction (progress))
@@ -168,8 +168,12 @@ class CargoSyncTask(
168
168
val oldCargoProject : CargoProjectImpl ,
169
169
val toolchain : RsToolchainBase ,
170
170
val progress : ProgressIndicator ,
171
+ val buildId : Any ,
171
172
val syncProgress : BuildProgress <BuildProgressDescriptor >
172
173
) {
174
+
175
+ val id: Any get() = syncProgress.id
176
+
173
177
fun <T > runWithChildProgress (
174
178
title : String ,
175
179
action : (SyncContext ) -> TaskResult <T >
@@ -315,12 +319,32 @@ private fun fetchCargoWorkspace(context: CargoSyncTask.SyncContext, rustcInfo: R
315
319
val cargo = toolchain.cargoOrWrapper(projectDirectory)
316
320
try {
317
321
CargoEventService .getInstance(childContext.project).onMetadataCall(projectDirectory)
318
- val projectDescriptionData = cargo.fullProjectDescription(
322
+ val ( projectDescriptionData, status) = cargo.fullProjectDescription(
319
323
childContext.project,
320
324
projectDirectory,
321
- // TODO: collect build events and show them in structured way
322
- SyncProcessAdapter (childContext)
323
- )
325
+ ) {
326
+ when (it) {
327
+ CargoCallType .METADATA -> SyncProcessAdapter (childContext)
328
+ CargoCallType .BUILD_SCRIPT_CHECK -> {
329
+ val childProgress = childContext.syncProgress.startChildProgress(" Build scripts evaluation" )
330
+ val syncContext = childContext.copy(syncProgress = childProgress)
331
+
332
+ val buildContext = SyncCargoBuildContext (
333
+ childContext.oldCargoProject,
334
+ buildId = syncContext.buildId,
335
+ parentId = syncContext.id,
336
+ progressIndicator = syncContext.progress
337
+ )
338
+
339
+ SyncCargoBuildAdapter (syncContext, buildContext)
340
+ }
341
+ }
342
+ }
343
+ if (status == ProjectDescriptionStatus .BUILD_SCRIPT_EVALUATION_ERROR ) {
344
+ childContext.warning(" Build scripts evaluation failed" ,
345
+ " Build scripts evaluation failed. Features based on generated info by build scripts may not work in your IDE" )
346
+ }
347
+
324
348
val manifestPath = projectDirectory.resolve(" Cargo.toml" )
325
349
326
350
val cfgOptions = try {
@@ -435,6 +459,36 @@ private class SyncProcessAdapter(
435
459
override fun warning (title : String , message : String ) = context.warning(title, message)
436
460
}
437
461
462
+ private class SyncCargoBuildContext (
463
+ cargoProject : CargoProject ,
464
+ buildId : Any ,
465
+ parentId : Any ,
466
+ progressIndicator : ProgressIndicator
467
+ ) : CargoBuildContextBase(cargoProject, " Building..." , false , buildId, parentId) {
468
+ init {
469
+ indicator = progressIndicator
470
+ }
471
+ }
472
+
473
+ private class SyncCargoBuildAdapter (
474
+ private val context : CargoSyncTask .SyncContext ,
475
+ buildContext : CargoBuildContextBase
476
+ ) : CargoBuildAdapterBase(buildContext, context.project.service<SyncViewManager >()) {
477
+
478
+ override fun onBuildOutputReaderFinish (
479
+ event : ProcessEvent ,
480
+ isSuccess : Boolean ,
481
+ isCanceled : Boolean ,
482
+ error : Throwable ?
483
+ ) {
484
+ when {
485
+ isSuccess -> context.syncProgress.finish()
486
+ isCanceled -> context.syncProgress.cancel()
487
+ else -> context.syncProgress.fail()
488
+ }
489
+ }
490
+ }
491
+
438
492
private fun CargoSyncTask.SyncContext.error (title : String , message : String ) {
439
493
syncProgress.message(title, message, MessageEvent .Kind .ERROR , null )
440
494
}
0 commit comments