Skip to content

Commit

Permalink
only use dotnetCoreRuntime, wait until rider is ready to ensure it is…
Browse files Browse the repository at this point in the history
… loaded.
  • Loading branch information
belav committed Mar 8, 2024
1 parent 72a4804 commit fc13e31
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 185 deletions.
4 changes: 4 additions & 0 deletions Src/CSharpier.Rider/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

# csharpier-rider Changelog

## [1.6.2]
- Fix issues with lookup of '.NET CLI executable path', csharpier will now wait until rider is ready with the information.
- No more falling back to `PATH`

## [1.6.1]
- Delay lookup of '.NET CLI executable path' until it is needed
- Fall back to looking for dotnet on PATH if '.NET CLI executable path' is not available
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.intellij.csharpier

import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.StartupActivity
import com.intellij.openapi.startup.StartupActivity.DumbAware
import com.jetbrains.rd.platform.util.lifetime
import com.jetbrains.rd.util.reactive.adviseUntil
import com.jetbrains.rider.model.riderSolutionLifecycle
import com.jetbrains.rider.projectView.solution
import com.jetbrains.rider.runtime.RiderDotNetActiveRuntimeHost

// kotlin because I have no idea how to get project.solution.riderSolutionLifecycle.isProjectModelReady.adviseUntil happy in java
class CSharpierStartup : StartupActivity, DumbAware {
var logger: Logger = CSharpierLogger.getInstance()

override fun runActivity(project: Project) {
project.solution.riderSolutionLifecycle.isProjectModelReady.adviseUntil(project.lifetime) { isReady ->

val dotNetCoreRuntime =
RiderDotNetActiveRuntimeHost.Companion.getInstance(project).dotNetCoreRuntime.value

if (!isReady || dotNetCoreRuntime == null) {
if (isReady) {
logger.warn("isProjectModelReady is true, but dotNetCoreRuntime is still null");
}

return@adviseUntil false
}

CSharpierProcessProvider.getInstance(project)
ApplicationManager.getApplication().getService(ReformatWithCSharpierOnSave::class.java)
DotNetProvider.getInstance(project).initialize();

return@adviseUntil true
}
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class DotNetProvider {
private final Project project;
private String dotNetRoot;
private String cliExePath;
private boolean isInitialized;

public DotNetProvider(@NotNull Project project) {
this.project = project;
Expand All @@ -26,11 +25,7 @@ static DotNetProvider getInstance(@NotNull Project project) {
return project.getService(DotNetProvider.class);
}

private synchronized void initializeIfNeeded() {
if (this.isInitialized) {
return;
}

void initialize() {
var foundDotNet = this.findDotNet();
if (!foundDotNet) {

Expand All @@ -39,26 +34,17 @@ private synchronized void initializeIfNeeded() {
var notification = NotificationGroupManager.getInstance().getNotificationGroup("CSharpier").createNotification(title, message, NotificationType.WARNING);
notification.notify(this.project);
}

this.isInitialized = true;
}

private boolean findDotNet() {
try {
var dotNetCoreRuntime = RiderDotNetActiveRuntimeHost.Companion.getInstance(project).getDotNetCoreRuntime().getValue();

if (!CSharpierSettings.getInstance(this.project).getSkipCliExePath()
&& dotNetCoreRuntime != null
&& dotNetCoreRuntime.getCliExePath() != null) {
if (dotNetCoreRuntime != null && dotNetCoreRuntime.getCliExePath() != null) {
this.logger.debug("Using dotnet found from RiderDotNetActiveRuntimeHost at " + dotNetCoreRuntime.getCliExePath());
this.cliExePath = dotNetCoreRuntime.getCliExePath();
} else {
this.cliExePath = DotNetFinder.findOnPath(this.logger);

if (this.cliExePath == null) {
return false;
}
this.logger.debug("Found dotnet at " + this.cliExePath);
return false;
}

this.dotNetRoot = Paths.get(this.cliExePath).getParent().toString();
Expand All @@ -72,7 +58,6 @@ private boolean findDotNet() {
}

public String execDotNet(List<String> command, File workingDirectory) {
this.initializeIfNeeded();
var commands = new ArrayList<>(command);
commands.add(0, this.cliExePath);

Expand All @@ -82,12 +67,10 @@ public String execDotNet(List<String> command, File workingDirectory) {
}

public String getDotNetRoot() {
this.initializeIfNeeded();
return this.dotNetRoot;
}

public boolean foundDotNet() {
this.initializeIfNeeded();
return this.cliExePath != null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void actionPerformed(@NotNull AnActionEvent e) {

@Override
public void update(@NotNull AnActionEvent e) {
logger.info("update!");
var virtualFile = e.getData(PlatformDataKeys.VIRTUAL_FILE);
if (virtualFile == null) {
e.getPresentation().setVisible(false);
Expand Down

0 comments on commit fc13e31

Please sign in to comment.