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

[Rider] formatting on save not working since 0.28.0 #1266

Open
MonstraG opened this issue May 22, 2024 · 8 comments
Open

[Rider] formatting on save not working since 0.28.0 #1266

MonstraG opened this issue May 22, 2024 · 8 comments

Comments

@MonstraG
Copy link

Environments

  • IDE Version: JetBrains Rider 2024.1.2 Build #RD-241.15989.179, built on May 6, 2024
  • Extension Version: 1.7.2
  • CSharpier Version: 0.28.0+, (incl. 0.28.2)
    will NOT be the same as the extension version
  • Operating System: Linux, Manjaro
  • .csharpierrc Settings: not present in repo
  • .editorconfig Settings: not present in repo
.config/dotnet-tools.json
{
  "version": 1,
  "isRoot": true,
  "tools": {
    "csharpier": {
      "version": "0.28.2",
      "commands": [
        "dotnet-csharpier"
      ]
    }
  }
}

Log Output

before update:
2024-05-22 12:59:31,975 [  67672]   FINE - #c.i.c.CSharpierLogger - beforeDocumentSaving for DocumentImpl[file:///home/arseny/RiderProjects/ConsoleApp1/ConsoleApp1/Program.cs]
2024-05-22 12:59:31,975 [  67672]   INFO - #c.i.c.CSharpierLogger - Formatting started for /home/arseny/RiderProjects/ConsoleApp1/ConsoleApp1/Program.cs using CSharpier 0.27.3
2024-05-22 12:59:31,986 [  67683]   INFO - #c.i.c.CSharpierLogger - Formatted in 10ms
after update
2024-05-22 13:01:32,063 [  27028]   FINE - #c.i.c.CSharpierLogger - Ensure there is a csharpier process for /home/arseny/RiderProjects/ConsoleApp1/ConsoleApp1
2024-05-22 13:01:32,096 [  27061]   FINE - #c.i.c.CSharpierLogger - Looking for /home/arseny/RiderProjects/ConsoleApp1/ConsoleApp1/.config/dotnet-tools.json
2024-05-22 13:01:32,096 [  27061]   FINE - #c.i.c.CSharpierLogger - Looking for /home/arseny/RiderProjects/ConsoleApp1/.config/dotnet-tools.json
2024-05-22 13:01:32,098 [  27063]   FINE - #c.i.c.CSharpierLogger - Found version 0.28.2 in /home/arseny/RiderProjects/ConsoleApp1/.config/dotnet-tools.json
2024-05-22 13:01:32,099 [  27064]   FINE - #c.i.c.CSharpierLogger - Using 0.28.2 as the version number.
2024-05-22 13:01:32,111 [  27076]   FINE - #c.i.c.CSharpierLogger - Running /home/arseny/.cache/csharpier/0.28.2/dotnet-csharpier --version in /home/arseny/.cache/csharpier/0.28.2
2024-05-22 13:01:32,219 [  27184]   FINE - #c.i.c.CSharpierLogger - /home/arseny/.cache/csharpier/0.28.2/dotnet-csharpier--version output: 0.28.2
2024-05-22 13:01:32,219 [  27184]   FINE - #c.i.c.CSharpierLogger - Using 0.28.2 as the version number.
2024-05-22 13:01:32,219 [  27184]   FINE - #c.i.c.CSharpierLogger - CSharpier at /home/arseny/.cache/csharpier/0.28.2 already exists
2024-05-22 13:01:32,219 [  27184]   FINE - #c.i.c.CSharpierLogger - Adding new version 0.28.2 process for /home/arseny/RiderProjects/ConsoleApp1/ConsoleApp1
2024-05-22 13:01:34,223 [  29188]   WARN - #c.i.c.CSharpierLogger - Spawning the csharpier server timed out. Formatting cannot occur.
2024-05-22 13:01:34,224 [  29189]   FINE - #c.i.c.CSharpierLogger - Warm CSharpier with initial format
2024-05-22 13:01:34,227 [  29192]   WARN - #c.i.c.CSharpierLogger - Failed posting to the csharpier server.
java.net.ConnectException: Connection refused
	at java.base/sun.nio.ch.Net.pollConnect(Native Method)
	at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672)
	at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:547)
	at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:602)
	at java.base/java.net.Socket.connect(Socket.java:633)
	at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:178)
	at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:533)
	at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:638)
	at java.base/sun.net.www.http.HttpClient.<init>(HttpClient.java:281)
	at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:386)
	at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:408)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1309)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1242)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1128)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:1057)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1430)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1401)
	at com.intellij.csharpier.CSharpierProcessServer.formatFile(CSharpierProcessServer.java:100)
	at com.intellij.csharpier.CSharpierProcessServer.formatFile(CSharpierProcessServer.java:145)
	at com.intellij.csharpier.CSharpierProcessServer.<init>(CSharpierProcessServer.java:34)
	at com.intellij.csharpier.CSharpierProcessProvider.setupCSharpierProcess(CSharpierProcessProvider.java:225)
	at com.intellij.csharpier.CSharpierProcessProvider.findAndWarmProcess(CSharpierProcessProvider.java:90)
	at com.intellij.csharpier.CSharpierProcessProvider.documentChanged(CSharpierProcessProvider.java:64)
	at jdk.internal.reflect.GeneratedMethodAccessor161.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at com.intellij.util.EventDispatcher.dispatchVoidMethod(EventDispatcher.java:119)
	at com.intellij.util.EventDispatcher.lambda$createMulticaster$1(EventDispatcher.java:84)
	at jdk.proxy2/jdk.proxy2.$Proxy85.documentChanged(Unknown Source)
	at com.intellij.openapi.editor.impl.DocumentImpl.lambda$changedUpdate$1(DocumentImpl.java:917)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeNonCancelableSection$3(CoreProgressManager.java:269)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:735)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:691)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$computeInNonCancelableSection$4(CoreProgressManager.java:277)
	at com.intellij.openapi.progress.Cancellation.computeInNonCancelableSection(Cancellation.java:57)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeInNonCancelableSection(CoreProgressManager.java:277)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeNonCancelableSection(CoreProgressManager.java:268)
	at com.intellij.openapi.editor.impl.DocumentImpl.changedUpdate(DocumentImpl.java:914)
	at com.intellij.openapi.editor.impl.DocumentImpl.updateText(DocumentImpl.java:818)
	at com.intellij.openapi.editor.impl.DocumentImpl.insertString(DocumentImpl.java:549)
	at com.intellij.openapi.editor.EditorModificationUtilEx.insertStringAtCaretNoScrolling(EditorModificationUtilEx.java:79)
	at com.intellij.openapi.editor.EditorModificationUtilEx.insertStringAtCaret(EditorModificationUtilEx.java:55)
	at com.intellij.openapi.editor.EditorModificationUtilEx.insertStringAtCaret(EditorModificationUtilEx.java:47)
	at com.jetbrains.rider.editorActions.AsynchronousFrontendTypedHandlerStrategy.r(AsynchronousFrontendTypedHandlerStrategy.kt:23)
	at com.jetbrains.rider.editorActions.AsynchronousFrontendTypedHandlerStrategy.access$optimisticTypeHandler(AsynchronousFrontendTypedHandlerStrategy.kt:11)
	at com.jetbrains.rider.editorActions.AsynchronousFrontendTypedHandlerStrategy$typeChar$1.invoke(AsynchronousFrontendTypedHandlerStrategy.kt:17)
	at com.jetbrains.rider.editorActions.AsynchronousFrontendTypedHandlerStrategy$typeChar$1.invoke(AsynchronousFrontendTypedHandlerStrategy.kt:17)
	at com.jetbrains.rider.editorActions.TypingSessions.r(TypingSessions.kt:263)
	at com.jetbrains.rider.editorActions.TypingSessions.type(TypingSessions.kt:221)
	at com.jetbrains.rider.editorActions.AsynchronousFrontendTypedHandlerStrategy.typeChar(AsynchronousFrontendTypedHandlerStrategy.kt:17)
	at com.jetbrains.rider.editorActions.FrontendTypedHandlerManager.typeCharOnBackend(FrontendTypedHandlerManager.kt:52)
	at com.jetbrains.rider.editorActions.FrontendTypedHandlerDelegate.beforeSelectionRemoved(FrontendTypedHandlerDelegate.kt:25)
	at com.intellij.codeInsight.editorActions.TypedHandler.callDelegates(TypedHandler.java:267)
	at com.intellij.codeInsight.editorActions.TypedHandler.lambda$doExecute$1(TypedHandler.java:188)
	at com.intellij.openapi.editor.impl.CaretModelImpl.lambda$runForEachCaret$3(CaretModelImpl.java:303)
	at com.intellij.openapi.editor.impl.CaretModelImpl.doWithCaretMerging(CaretModelImpl.java:412)
	at com.intellij.openapi.editor.impl.CaretModelImpl.runForEachCaret(CaretModelImpl.java:312)
	at com.intellij.openapi.editor.impl.CaretModelImpl.runForEachCaret(CaretModelImpl.java:289)
	at com.intellij.codeInsight.editorActions.TypedHandler.doExecute(TypedHandler.java:159)
	at com.intellij.codeInsight.editorActions.TypedHandler.execute(TypedHandler.java:137)
	at com.intellij.codeInsight.lookup.impl.LookupTypedHandler.execute(LookupTypedHandler.java:75)
	at com.intellij.codeInsight.template.emmet.EmmetPreviewTypedHandler.execute(EmmetPreviewTypedHandler.java:43)
	at com.intellij.openapi.editor.impl.DefaultRawTypedHandler$1.run(DefaultRawTypedHandler.java:55)
	at com.intellij.openapi.application.impl.RwLockHolder.runWriteAction(RwLockHolder.kt:344)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:883)
	at com.intellij.openapi.editor.impl.DefaultRawTypedHandler.execute(DefaultRawTypedHandler.java:49)
	at com.jetbrains.rdclient.editorActions.cwm.FrontendAsyncRawTypedHandler.execute(FrontendAsyncRawTypedHandler.kt:66)
	at com.intellij.openapi.editor.impl.EditorFactoryImpl$MyRawTypedHandler.execute(EditorFactoryImpl.java:315)
	at com.intellij.openapi.editor.actionSystem.TypedAction.lambda$actionPerformed$2(TypedAction.java:201)
	at com.intellij.reporting.FreezeLoggerImpl.runUnderPerformanceMonitor(FreezeLoggerImpl.java:28)
	at com.intellij.openapi.editor.actionSystem.TypedAction.actionPerformed(TypedAction.java:200)
	at com.intellij.openapi.editor.impl.EditorImpl.processKeyTypedNormally(EditorImpl.java:1356)
	at com.intellij.openapi.editor.impl.EditorImpl.processKeyTyped(EditorImpl.java:1338)
	at com.intellij.openapi.editor.impl.EditorImpl.processKeyTyped(EditorImpl.java:3678)
	at com.intellij.openapi.editor.impl.EditorImpl$6.keyTyped(EditorImpl.java:1170)
	at java.desktop/java.awt.AWTEventMulticaster.keyTyped(AWTEventMulticaster.java:247)
	at java.desktop/java.awt.AWTEventMulticaster.keyTyped(AWTEventMulticaster.java:247)
	at java.desktop/java.awt.AWTEventMulticaster.keyTyped(AWTEventMulticaster.java:247)
	at java.desktop/java.awt.AWTEventMulticaster.keyTyped(AWTEventMulticaster.java:247)
	at java.desktop/java.awt.Component.processKeyEvent(Component.java:6612)
	at java.desktop/javax.swing.JComponent.processKeyEvent(JComponent.java:2892)
	at java.desktop/java.awt.Component.processEvent(Component.java:6434)
	at java.desktop/java.awt.Container.processEvent(Container.java:2266)
	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5027)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4855)
	at java.desktop/java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1954)
	at java.desktop/java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:886)
	at java.desktop/java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1166)
	at java.desktop/java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:1023)
	at java.desktop/java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:849)
	at com.intellij.ide.IdeKeyboardFocusManager.access$dispatchEvent$s1569605750(IdeKeyboardFocusManager.kt:22)
	at com.intellij.ide.IdeKeyboardFocusManager$dispatchEvent$1.invoke(IdeKeyboardFocusManager.kt:39)
	at com.intellij.ide.IdeKeyboardFocusManager$dispatchEvent$1.invoke(IdeKeyboardFocusManager.kt:39)
	at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$1(IdeEventQueue.kt:1022)
	at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:106)
	at com.intellij.ide.IdeEventQueueKt.performActivity(IdeEventQueue.kt:1022)
	at com.intellij.ide.IdeKeyboardFocusManager.dispatchEvent(IdeKeyboardFocusManager.kt:39)
	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4904)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)
	at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2809)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4855)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:794)
	at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:739)
	at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:733)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:97)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:766)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:764)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:763)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.kt:699)
	at com.intellij.ide.IdeEventQueue.dispatchKeyEvent(IdeEventQueue.kt:626)
	at com.intellij.ide.IdeEventQueue._dispatchEvent$lambda$11(IdeEventQueue.kt:585)
	at com.intellij.openapi.application.impl.RwLockHolder.runWithEnabledImplicitRead(RwLockHolder.kt:138)
	at com.intellij.openapi.application.impl.RwLockHolder.runWithImplicitRead(RwLockHolder.kt:129)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.kt:585)
	at com.intellij.ide.IdeEventQueue.access$_dispatchEvent(IdeEventQueue.kt:77)
	at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:362)
	at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:361)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:843)
	at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:361)
	at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:356)
	at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$1(IdeEventQueue.kt:1022)
	at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:114)
	at com.intellij.ide.IdeEventQueueKt.performActivity(IdeEventQueue.kt:1022)
	at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$7(IdeEventQueue.kt:356)
	at com.intellij.openapi.application.impl.RwLockHolder.runIntendedWriteActionOnCurrentThread(RwLockHolder.kt:209)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:830)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.kt:398)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)

Steps to reproduce

  1. create new ConsoleApp
  2. add a space
  3. ctrl + s

Downgrading to 0.27.3 works, manual formatting trough terminal works, action does not work with the same problem:

2024-05-22 13:08:34,237 [ 449202]   INFO - #c.i.c.CSharpierLogger - Running ReformatWithCSharpierAction
2024-05-22 13:08:34,238 [ 449203]   INFO - #c.i.c.CSharpierLogger - Formatting started for /home/arseny/RiderProjects/ConsoleApp1/ConsoleApp1/Program.cs using CSharpier 0.28.2
2024-05-22 13:08:34,238 [ 449203]   WARN - #c.i.c.CSharpierLogger - Failed posting to the csharpier server.
java.net.ConnectException: Connection refused
	at java.base/sun.nio.ch.Net.pollConnect(Native Method)
	....
@belav
Copy link
Owner

belav commented Jun 7, 2024

There have been issues with csharpier server trying to use a reserved windows port, I'm not sure if linux has something similar - #1249 (comment).
The root problem appears to be Spawning the csharpier server timed out. Formatting cannot occur.. The extension isn't supposed to try sending data to the server if that happens but I must have missed something.

What happens if you run dotnet csharpier --server ?

I did add an option to bypass csharpier server to VS, I'll probably add that option to rider + vscode as well. I've also considered automatically falling back to the older way of communicating.

@belav belav added this to the Planned - Extensions milestone Jun 7, 2024
@ghost
Copy link

ghost commented Jun 9, 2024

Some quick research shows that while Linux (all operating systems, in fact) have the concept of the dynamic/ephemeral port range, it seems like Windows is the only one that will block users from binding to those ports.

@MonstraG
Copy link
Author

MonstraG commented Jun 10, 2024

dotnet csharpier --server
does

Started on 49153
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://127.0.0.1:49153
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /home/arseny/Documents/Lifekeys/vulcan/backend

formatting does not work with or without it.

Errors did not became more meaningful, it's still just:

2024-06-10 08:16:14,575 [  75534]   WARN - #c.i.c.CSharpierLogger - Failed posting to the csharpier server.
java.net.ConnectException: Connection refused
	at java.base/sun.nio.ch.Net.pollConnect(Native Method)
	at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672)

I also noticed this at the start:

2024-06-10 08:15:37,925 [  38884]   FINE - #c.i.c.CSharpierLogger - Adding new version 0.28.2 process for /project
2024-06-10 08:15:39,929 [  40888]   WARN - #c.i.c.CSharpierLogger - Spawning the csharpier server timed out. Formatting cannot occur.
2024-06-10 08:15:39,929 [  40888]   FINE - #c.i.c.CSharpierLogger - Warm CSharpier with initial format
2024-06-10 08:15:39,932 [  40891]   WARN - #c.i.c.CSharpierLogger - Failed posting to the csharpier server.
java.net.ConnectException: Connection refused
	at java.base/sun.nio.ch.Net.pollConnect(Native Method)
	at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672)

@johan-lindqvist
Copy link

johan-lindqvist commented Aug 23, 2024

Also having this issue using Rider on Windows. I saw this PR #1329 so I tried turning off VS Code and it seems to work now.

If there's a problem with finding an unused port in addition to the problem in #1329 we use this code snippet that might be of help to find an unused port?

/// <summary>
/// Tries to get the TCP port in the specified range that is currently unused.
/// </summary>
/// <returns>True if the unusedPort is set, otherwise false.</returns>
public bool TryGetUnusedTcpPort(int start, int end, out int unusedPort)
{
        var usedPorts = new HashSet<int>();
	var properties = IPGlobalProperties.GetIPGlobalProperties();
	var activeTcpListeners = properties.GetActiveTcpListeners();
	var activeUdpListeners = properties.GetActiveUdpListeners();
	var activeConnections = properties.GetActiveTcpConnections();

	for (int port = start; port < end; port++)
	{
		if (!usedPorts.Contains(port)
			&& activeTcpListeners.All(c => c.Port != port)
			&& activeUdpListeners.All(c => c.Port != port)
			&& activeConnections.All(c => c.LocalEndPoint.Port != port))
		{
			unusedPort = port;
			usedPorts.Add(port);
			return true;
		}
	}

	unusedPort = default;
	return false;
}

@MonstraG
Copy link
Author

It's been a hot second, versions of everything changed, and at this very moment cshapier still doesn't work but for a different reason.

1st, using old dotnet-tools.json doesn't work anymore:

{
  "version": 1,
  "isRoot": true,
  "tools": {
    "csharpier": {
      "version": "0.30.0",
      "commands": [
        "dotnet-csharpier"
      ]
    }
  }
}

This fails with

The command "dotnet-csharpier" specified in the tool manifest file is not contained in the package with Package Id csharpier. The commands contained in the package are "csharpier".

So it seems that it should be updated to

{
  "version": 1,
  "isRoot": true,
  "tools": {
    "csharpier": {
      "version": "0.30.0",
      "commands": [
        "csharpier"
      ]
    }
  }
}

This succeeds.
But, I believe, the extension is not updated yet and still tries to reference the previous command/filename because it fails with this in log:

2024-11-18 09:22:16,957 [  50727]   FINE - #c.i.c.CSharpierLogger - Running 'dotnet tool list' to look for version
2024-11-18 09:22:16,957 [  50727]   FINE - #c.i.c.CSharpierLogger - Output was: 
 Package Id      Version      Commands       Manifest                                                                
--------------------------------------------------------------------------------------------------------------------
csharpier       0.30.0       csharpier      /home/arseny/Documents/Lifekeys/vulcan/backend/.config/dotnet-tools.json
2024-11-18 09:22:16,958 [  50728]   FINE - #c.i.c.CSharpierLogger - Using 0.30.0 as the version number.
2024-11-18 09:22:16,966 [  50736]   FINE - #c.i.c.CSharpierLogger - Running /home/arseny/.dotnet/dotnet tool install csharpier --version 0.30.0 --tool-path /home/arseny/.cache/csharpier/0.30.0
2024-11-18 09:22:20,054 [  53824]   FINE - #c.i.c.CSharpierLogger - Running /home/arseny/.cache/csharpier/0.30.0/dotnet-csharpier --version in /home/arseny/.cache/csharpier/0.30.0
2024-11-18 09:22:20,056 [  53826] SEVERE - #c.i.c.CSharpierLogger - Cannot run program "/home/arseny/.cache/csharpier/0.30.0/dotnet-csharpier" (in directory "/home/arseny/.cache/csharpier/0.30.0"): error=2, No such file or directory
java.io.IOException: Cannot run program "/home/arseny/.cache/csharpier/0.30.0/dotnet-csharpier" (in directory "/home/arseny/.cache/csharpier/0.30.0"): error=2, No such file or directory
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1170)
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1089)
	at com.intellij.csharpier.ProcessHelper.executeCommand(ProcessHelper.java:34)
	at com.intellij.csharpier.CustomPathInstaller.validateInstall(CustomPathInstaller.java:66)
	at com.intellij.csharpier.CustomPathInstaller.ensureVersionInstalled(CustomPathInstaller.java:58)
	at com.intellij.csharpier.CSharpierProcessProvider.setupCSharpierProcess(CSharpierProcessProvider.java:250)
	at com.intellij.csharpier.CSharpierProcessProvider.findAndWarmProcess(CSharpierProcessProvider.java:98)
	at com.intellij.csharpier.CSharpierProcessProvider.documentChanged(CSharpierProcessProvider.java:67)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	...

In fact, /home/arseny/.cache/csharpier/0.30.0/dotnet-csharpier doesn't exist; /home/arseny/.cache/csharpier/0.30.0/csharpier does.

Other data for reference:

IDE Version: Build #RD-243.21565.191, built on November 13, 2024
Extension Version: 1.8.2
CSharpier Version: 0.30.0
will NOT be the same as the extension version
Operating System: Linux, Manjaro
.csharpierrc Settings:
{
	"printWidth": 140,
	"useTabs": true,
	"tabWidth": 4,
	"preprocessorSymbolSets": [
		"",
		"DEBUG",
		"DEBUG,CODE_STYLE"
	]
}
.editorconfig Settings:
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8

@oddeirik
Copy link

Really struggling with the CSharpier plugin in Rider 2024.3 as well. Sometimes it works, most times it just fails with the "CSharpier unable to format files" warning toast.

Enabled debug logging, which gives me these relevant entries:

2024-11-26 09:51:36,797 [ 126185]   FINE - #c.i.c.CSharpierLogger - Ensure there is a csharpier process for /home/[...]
2024-11-26 09:51:36,797 [ 126185]   FINE - #c.i.c.CSharpierLogger - Looking for csproj in or above /home/[...] that references CSharpier.MsBuild
2024-11-26 09:51:36,798 [ 126186]   FINE - #c.i.c.CSharpierLogger - Looking for /home/[...]/*.csproj
2024-11-26 09:51:36,798 [ 126186]   FINE - #c.i.c.CSharpierLogger - Looking for /home/[...]/Models/*.csproj
2024-11-26 09:51:36,798 [ 126186]   FINE - #c.i.c.CSharpierLogger - Looking for /home/[...]/*.csproj
2024-11-26 09:51:36,823 [ 126211]   FINE - #c.i.c.CSharpierLogger - Running /usr/lib64/dotnet/dotnet tool list in /home/[...]
2024-11-26 09:51:36,933 [ 126321]   FINE - #c.i.c.CSharpierLogger - Running 'dotnet tool list' to look for version
2024-11-26 09:51:36,933 [ 126321]   FINE - #c.i.c.CSharpierLogger - Output was: 
- Package Id                 Version      Commands              Manifest                                                 
------------------------------------------------------------------------------------------------------------------------
-csharpier                  0.30.2       dotnet-csharpier      /home/[...]/.config/dotnet-tools.json
-roslynator.dotnet.cli      0.9.3        roslynator            /home/[...]/.config/dotnet-tools.json
2024-11-26 09:51:36,933 [ 126321]   FINE - #c.i.c.CSharpierLogger - Using 0.30.2 as the version number.
2024-11-26 09:51:36,937 [ 126325]   FINE - #c.i.c.CSharpierLogger - Running /home/[...]/.cache/csharpier/0.30.2/dotnet-csharpier --version in /home/[...]/.cache/csharpier/0.30.2
2024-11-26 09:51:37,011 [ 126399]   FINE - #c.i.c.CSharpierLogger - /home/[...]/.cache/csharpier/0.30.2/dotnet-csharpier--version output: 0.30.2
2024-11-26 09:51:37,011 [ 126399]   FINE - #c.i.c.CSharpierLogger - Using 0.30.2 as the version number.
2024-11-26 09:51:37,011 [ 126399]   FINE - #c.i.c.CSharpierLogger - CSharpier at /home/[...]/.cache/csharpier/0.30.2 already exists
2024-11-26 09:51:37,011 [ 126399]   FINE - #c.i.c.CSharpierLogger - Adding new version 0.30.2 process for /home/[...]
2024-11-26 09:51:39,013 [ 128401]   WARN - #c.i.c.CSharpierLogger - Spawning the csharpier server timed out. Formatting cannot occur.

THe tools are installed and I can run them just fine from a terminal myself. It also seems to work fine with the VSCode extension if I run VSCode instead. But in Rider, it's usually just a second or two hanging on the first attempt to format and then that infamous warning toast pops up.

The repository dotnet-tools.json file:

{
  "version": 1,
  "isRoot": true,
  "tools": {
    "csharpier": {
      "version": "0.30.2",
      "commands": [
        "dotnet-csharpier"
      ],
      "rollForward": true
    },
    "roslynator.dotnet.cli": {
      "version": "0.9.3",
      "commands": [
        "roslynator"
      ],
      "rollForward": true
    }
  }
}

@belav
Copy link
Owner

belav commented Dec 7, 2024

Sorry for the delay, I haven't had time to really look at this yet but some info that may help.

0.30.0 - was broken for all plugins.

For 0.30.X, there are logs available at a path similar to C:\Users\bela\AppData\Local\CSharpier\0.30.2\.store\csharpier\0.30.2\csharpier\0.30.2\tools\net9.0\any\server[Port].log which may contain useful info for why csharpier server is failing to startup.

Rider does have an option to disable cshapier server and use the older method of communication - tools - csharpier - disable csharpier server.

@MonstraG
Copy link
Author

MonstraG commented Dec 8, 2024

Okay, I've updated csharpier to 0.30.3, made sure I have a log entry com.intellij.csharpier.CSharpierLogger (hashtag gets removed after restart) in Rider's Debug Log Settings. Plugin is 1.8.2.

Trying to format (on save), a notification appears: CShariper is unable to format files

Rider logs end with the usual


2024-12-08 22:04:59,983 [  25422]   FINE - #c.i.c.CSharpierLogger - Running 'dotnet tool list' to look for version
2024-12-08 22:04:59,983 [  25422]   FINE - #c.i.c.CSharpierLogger - Output was: 
 Package Id      Version      Commands              Manifest                                                                
---------------------------------------------------------------------------------------------------------------------------
csharpier       0.30.3       dotnet-csharpier      /home/arseny/Documents/Lifekeys/vulcan/backend/.config/dotnet-tools.json
dotnet-ef       9.0.0        dotnet-ef             /home/arseny/Documents/Lifekeys/vulcan/backend/.config/dotnet-tools.json
2024-12-08 22:04:59,983 [  25422]   FINE - #c.i.c.CSharpierLogger - Using 0.30.3 as the version number.
2024-12-08 22:04:59,991 [  25430]   FINE - #c.i.c.CSharpierLogger - Running /home/arseny/.cache/csharpier/0.30.3/dotnet-csharpier --version in /home/arseny/.cache/csharpier/0.30.3
2024-12-08 22:05:00,072 [  25511]   FINE - #c.i.c.CSharpierLogger - /home/arseny/.cache/csharpier/0.30.3/dotnet-csharpier--version output: 0.30.3
2024-12-08 22:05:00,073 [  25512]   FINE - #c.i.c.CSharpierLogger - Using 0.30.3 as the version number.
2024-12-08 22:05:00,073 [  25512]   FINE - #c.i.c.CSharpierLogger - CSharpier at /home/arseny/.cache/csharpier/0.30.3 already exists
2024-12-08 22:05:00,073 [  25512]   FINE - #c.i.c.CSharpierLogger - Adding new version 0.30.3 process for /home/arseny/....
2024-12-08 22:05:02,077 [  27516]   WARN - #c.i.c.CSharpierLogger - Spawning the csharpier server timed out. Formatting cannot occur.
2024-12-08 22:05:02,202 [  27641]   FINE - #c.i.c.CSharpierLogger - beforeDocumentSaving for DocumentImpl[AdminsController.cs]
2024-12-08 22:05:02,203 [  27642]   INFO - #c.i.c.CSharpierLogger - Formatting started for /home/arseny......Controller.cs using CSharpier 0.30.3
2024-12-08 22:05:02,203 [  27642]   WARN - #c.i.c.CSharpierLogger - CSharpier process failed to start. Formatting cannot occur.
2024-12-08 22:05:02,203 [  27642]   INFO - #c.i.c.CSharpierLogger - Formatted in 0ms

I found the cshapier logs in

/home/arseny/.cache/csharpier/0.30.3/.store/csharpier/0.30.3/csharpier/0.30.3/tools/net9.0/any/server.log

(no port in filename)

but it contains only

2024-12-08T22:04:38.4030968+01:00	INFO	[Microsoft.Hosting.Lifetime]	[ListeningOnAddress]	Now listening on: http://127.0.0.1:33785
2024-12-08T22:04:38.4186048+01:00	INFO	[Microsoft.Hosting.Lifetime]	[0]	Application started. Press Ctrl+C to shut down.
2024-12-08T22:04:38.4189337+01:00	INFO	[Microsoft.Hosting.Lifetime]	[0]	Hosting environment: Production
2024-12-08T22:04:38.4189708+01:00	INFO	[Microsoft.Hosting.Lifetime]	[0]	Content root path: /home/arseny
2024-12-08T22:05:05.1543209+01:00	INFO	[Microsoft.Hosting.Lifetime]	[ListeningOnAddress]	Now listening on: http://127.0.0.1:44329
2024-12-08T22:05:05.1680131+01:00	INFO	[Microsoft.Hosting.Lifetime]	[0]	Application started. Press Ctrl+C to shut down.
2024-12-08T22:05:05.1683223+01:00	INFO	[Microsoft.Hosting.Lifetime]	[0]	Hosting environment: Production
2024-12-08T22:05:05.1683440+01:00	INFO	[Microsoft.Hosting.Lifetime]	[0]	Content root path: /home/arseny

I've switched on Disable csharpier server and restarted Rider, and tried formatting a file. File was formatted succesfully!

server.log did not change.

server44339.log appeared with only one entry

2024-12-08T22:14:38.6499143+01:00	INFO	[Microsoft.Hosting.Lifetime]	[0]	Application is shutting down...

In riders logs:

2024-12-08 22:15:05,035 [  24607]   FINE - #c.i.c.CSharpierLogger - Ensure there is a csharpier process for /home/arseny/...
2024-12-08 22:15:05,036 [  24608]   FINE - #c.i.c.CSharpierLogger - Looking for csproj in or above /home/arseny... that references CSharpier.MsBuild
...
2024-12-08 22:15:05,089 [  24661]   FINE - #c.i.c.CSharpierLogger - Looking for //*.csproj
2024-12-08 22:15:05,090 [  24662]   FINE - #c.i.c.CSharpierLogger - Running /home/arseny/.dotnet/dotnet tool list in /home/arseny/...
2024-12-08 22:15:05,243 [  24815]   FINE - #c.i.c.CSharpierLogger - Running 'dotnet tool list' to look for version
2024-12-08 22:15:05,243 [  24815]   FINE - #c.i.c.CSharpierLogger - Output was: 
 Package Id      Version      Commands              Manifest                                                                
---------------------------------------------------------------------------------------------------------------------------
csharpier       0.30.3       dotnet-csharpier      /home/arseny/Documents/Lifekeys/vulcan/backend/.config/dotnet-tools.json
dotnet-ef       9.0.0        dotnet-ef             /home/arseny/Documents/Lifekeys/vulcan/backend/.config/dotnet-tools.json
2024-12-08 22:15:05,244 [  24816]   FINE - #c.i.c.CSharpierLogger - Using 0.30.3 as the version number.
2024-12-08 22:15:05,253 [  24825]   FINE - #c.i.c.CSharpierLogger - Running /home/arseny/.cache/csharpier/0.30.3/dotnet-csharpier --version in /home/arseny/.cache/csharpier/0.30.3
2024-12-08 22:15:05,358 [  24930]   FINE - #c.i.c.CSharpierLogger - /home/arseny/.cache/csharpier/0.30.3/dotnet-csharpier--version output: 0.30.3
2024-12-08 22:15:05,358 [  24930]   FINE - #c.i.c.CSharpierLogger - Using 0.30.3 as the version number.
2024-12-08 22:15:05,358 [  24930]   FINE - #c.i.c.CSharpierLogger - CSharpier at /home/arseny/.cache/csharpier/0.30.3 already exists
2024-12-08 22:15:05,358 [  24930]   FINE - #c.i.c.CSharpierLogger - Adding new version 0.30.3 process for /home/arseny/...
2024-12-08 22:15:05,358 [  24930]   FINE - #c.i.c.CSharpierLogger - CSharpier server is disabled, falling back to piping via stdin
2024-12-08 22:15:05,362 [  24934]   FINE - #c.i.c.CSharpierLogger - Warm CSharpier with initial format
...
2024-12-08 22:15:07,225 [  26797]   FINE - #c.i.c.CSharpierLogger - Ensure there is a csharpier process for /
2024-12-08 22:15:07,226 [  26798]   FINE - #c.i.c.CSharpierLogger - Looking for csproj in or above / that references CSharpier.MsBuild
2024-12-08 22:15:07,226 [  26798]   FINE - #c.i.c.CSharpierLogger - Looking for //*.csproj
2024-12-08 22:15:07,226 [  26798]   FINE - #c.i.c.CSharpierLogger - Running /home/arseny/.dotnet/dotnet tool list in /
2024-12-08 22:15:07,416 [  26988]   FINE - #c.i.c.CSharpierLogger - Running 'dotnet tool list' to look for version
2024-12-08 22:15:07,416 [  26988]   FINE - #c.i.c.CSharpierLogger - Output was: 
 Package Id      Version      Commands      Manifest
---------------------------------------------------
2024-12-08 22:15:07,417 [  26989]   FINE - #c.i.c.CSharpierLogger - Running /home/arseny/.dotnet/dotnet tool list -g in /
2024-12-08 22:15:07,682 [  27254]   FINE - #c.i.c.CSharpierLogger - Running 'dotnet tool list-g' to look for version
2024-12-08 22:15:07,682 [  27254]   FINE - #c.i.c.CSharpierLogger - Output was: 
 Package Id      Version      Commands 
--------------------------------------
dotnet-ef       9.0.0        dotnet-ef
....
2024-12-08 22:15:15,770 [  35342]   FINE - #c.i.c.CSharpierLogger - Ensure there is a csharpier process for /home/arseny/....
...
2024-12-08 22:15:19,003 [  38575]   FINE - #c.i.c.CSharpierLogger - beforeDocumentSaving for DocumentImpl[AdminsController.cs]
2024-12-08 22:15:19,003 [  38575]   INFO - #c.i.c.CSharpierLogger - Formatting started for /home/arseny/.....Controller.cs using CSharpier 0.30.3
2024-12-08 22:15:19,039 [  38611]   INFO - #c.i.c.CSharpierLogger - Formatted in 35ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants