cezarypiatek / MappingGeneratorIssueTracker

This is a issue tracker for MappingGenerator
2 stars 0 forks source link

No Code Actions in Rider #12

Closed rfvgyhn closed 2 years ago

rfvgyhn commented 2 years ago

I'm unable to get code actions to show up in Rider (neither 2022.1.2 or 2022.2 RC) on Linux. They do work for me in VSCode.

Given the following code, placing my cursor on the function Map and pressing alt+enter or clicking the light bulb shows a context menu without any MappingGenerator items. I've tried various scenarios from the docs and haven't been able to get the code actions to show up at all.

dotnet new console

// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

public class One
{
    public int MyProperty { get; set; }
}

public class Two
{
    public int MyProperty { get; set; }
}

public class TestMapper
{
    public static Two Map(One one)
    {
        throw new NotImplementedException();
    }
}
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="MappingGenerator" Version="2022.7.45" />
  </ItemGroup>
</Project>

rider-mappinggen-context-menu

In version 2022.2 RC, I get the following IDE error. In version 2022.1.2, I don't get any IDE errors. Not sure if this is relevant.

--- EXCEPTION #1/2 [RdFault]
Message = “
  The type initializer for 'MappingGenerator.Installer.Installer' threw an exception., reason: System.TypeInitializationException: The type initializer for 'MappingGenerator.Installer.Installer' threw an exception.
   ---> System.ArgumentNullException: Value cannot be null. (Parameter 'path1')
     at System.IO.Path.Combine(String path1, String path2, String path3)
     at MappingGenerator.Installer.Installer..cctor()
     --- End of inner exception stack trace ---
     at MappingGenerator.Installer.Installer.ComputeRefactoringsAsync(CodeRefactoringContext context)
     at JetBrains.Roslyn.Worker.Workspaces.Analyzers.RefactoringsManager.GetCodeActionsAsync(Document document, Int32 offset, Func`2 isEnabled, CancellationToken token)
     at JetBrains.Roslyn.Worker.Workspaces.Analyzers.RoslynRefactoringsManager.GetRefactorings(Lifetime lifetime, RoslynGetRefactoringsArgs args)
     at JetBrains.Roslyn.Worker.Workspaces.RoslynAnalysisSession.GetRefactorings(Lifetime lifetime, RoslynGetRefactoringsArgs args)
”
ExceptionPath = Root.InnerException
ClassName = JetBrains.Rd.Tasks.RdFault
HResult = COR_E_EXCEPTION=80131500
Source = JetBrains.RdFramework
StackTraceString = “
  at JetBrains.Rd.Tasks.RdTaskResult`1.Unwrap()
     at JetBrains.Platform.RdFramework.Util.RdCallEx.SyncInterruptible[TIn,TOut](IRdCall`2 call, Lifetime lifetime, TIn arg, TimeSpan timeout, Int32 checkPeriodMs)
     at JetBrains.Roslyn.Host.RoslynWorkerHost.GetRefactorings(Lifetime caretPositionLifetime, ITextControl textControl, TimeSpan timeout)
     at JetBrains.Roslyn.Host.Daemon.RoslynBulbItemsProvider.CollectActions(IntentionsBulbItems intentionsBulbItems, BulbItemsCache bulbItemsCache, ITextControl textControl, Lifetime caretPositionLifetime, IPsiSourceFile psiSourceFile, Object precalculatedData)
”

--- Outer ---

--- EXCEPTION #2/2 [LoggerException]
Message = “
  Failed to collect actions The type initializer for 'MappingGenerator.Installer.Installer' threw an exception., reason: System.TypeInitializationException: The type initializer for 'MappingGenerator.Installer.Installer' threw an exception.
   ---> System.ArgumentNullException: Value cannot be null. (Parameter 'path1')
     at System.IO.Path.Combine(String path1, String path2, String path3)
     at MappingGenerator.Installer.Installer..cctor()
     --- End of inner exception stack trace ---
     at MappingGenerator.Installer.Installer.ComputeRefactoringsAsync(CodeRefactoringContext context)
     at JetBrains.Roslyn.Worker.Workspaces.Analyzers.RefactoringsManager.GetCodeActionsAsync(Document document, Int32 offset, Func`2 isEnabled, CancellationToken token)
     at JetBrains.Roslyn.Worker.Workspaces.Analyzers.RoslynRefactoringsManager.GetRefactorings(Lifetime lifetime, RoslynGetRefactoringsArgs args)
     at JetBrains.Roslyn.Worker.Workspaces.RoslynAnalysisSession.GetRefactorings(Lifetime lifetime, RoslynGetRefactoringsArgs args)
”
ExceptionPath = Root
ClassName = JetBrains.Util.LoggerException
InnerException = “Exception #1 at Root.InnerException”
HResult = COR_E_APPLICATION=80131600
StackTraceString = “
  at JetBrains.Util.ILoggerEx.LogException(ILogger this, LoggingLevel level, Exception exception, ExceptionOrigin exceptionOrigin, String comment)
     at JetBrains.Util.ILoggerEx.Error(ILogger this, Exception ex, String message)
     at JetBrains.Roslyn.Host.Daemon.RoslynBulbItemsProvider.CollectActions(IntentionsBulbItems intentionsBulbItems, BulbItemsCache bulbItemsCache, ITextControl textControl, Lifetime caretPositionLifetime, IPsiSourceFile psiSourceFile, Object precalculatedData)
     at JetBrains.ReSharper.Intentions.Bulbs.BulbItems.<>c__DisplayClass25_0.<BuildAvailableActionsList>b__0()
     at JetBrains.Application.Threading.InterruptableReadActivityThe.Work()
     at JetBrains.Application.Threading.InterruptableReadActivity.DoWork()
     at JetBrains.Application.Threading.InterruptableReadActivity.WorkerThreadProc()
     at JetBrains.Application.Threading.Tasks.TaskHost.AccessViolationCatcher(Action action)
     at JetBrains.Application.Threading.Tasks.TaskHost.<>c__DisplayClass36_0.<Create>b__0(Object state)
     at System.Threading.Tasks.Task.InnerInvoke()
     at System.Threading.Tasks.Task.<>c.<.cctor>b__272_0(Object obj)
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
     at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
     at System.Threading.Tasks.Task.ExecuteEntry()
     at System.Threading.Tasks.TaskScheduler.TryExecuteTask(Task task)
     at JetBrains.Application.Threading.Tasks.Scheduler.JetScheduler.ExecuteTask(Task task)
     at JetBrains.Application.Threading.Tasks.Scheduler.JetSchedulerThread.EnqueueNextTask()
     at JetBrains.Application.Threading.Tasks.Scheduler.JetSchedulerThread.ThreadPoolProc()
     at JetBrains.Util.Reflection.CallStackAnnotation.CatchAnnotatedInvocation[TClassOfNewFrame](String methodNameOfNewFrame, Action actionToAnnotate)
     at JetBrains.Application.Threading.Tasks.Scheduler.JetSchedulerThread.<>c__DisplayClass6_0.<.ctor>b__0()
     at System.Threading.Thread.StartCallback()
”

    at com.jetbrains.rdclient.protocol.components.RdClientProtocolComponent$2.invoke(RdClientProtocolComponent.kt:47)
    at com.jetbrains.rdclient.protocol.components.RdClientProtocolComponent$2.invoke(RdClientProtocolComponent.kt:22)
    at com.jetbrains.rd.util.reactive.Signal.fire(Signal.kt:32)
    at com.jetbrains.rd.framework.impl.RdSignal.onWireReceived(RdSignal.kt:42)
    at com.jetbrains.rd.framework.MessageBroker$invoke$2$2.invoke(MessageBroker.kt:57)
    at com.jetbrains.rd.framework.MessageBroker$invoke$2$2.invoke(MessageBroker.kt:12)
    at com.jetbrains.rd.framework.impl.ProtocolContexts.readMessageContextAndInvoke(ProtocolContexts.kt:151)
    at com.jetbrains.rd.framework.MessageBroker$invoke$2.invoke(MessageBroker.kt:56)
    at com.jetbrains.rd.framework.MessageBroker$invoke$2.invoke(MessageBroker.kt:12)
    at com.jetbrains.rdclient.protocol.RdDispatcher.flushAll(RdDispatcher.kt:97)
    at com.jetbrains.rdclient.protocol.RdDispatcher.access$flushAll(RdDispatcher.kt:18)
    at com.jetbrains.rdclient.protocol.RdDispatcher$flushAllRunnable$1.run(RdDispatcher.kt:23)
    at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:209)
    at com.intellij.openapi.application.TransactionGuardImpl.access$100(TransactionGuardImpl.java:21)
    at com.intellij.openapi.application.TransactionGuardImpl$1.run(TransactionGuardImpl.java:191)
    at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:881)
    at com.intellij.openapi.application.impl.ApplicationImpl$3.run(ApplicationImpl.java:513)
    at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:75)
    at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:118)
    at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:42)
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:779)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:730)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:724)
    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:749)
    at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:898)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:746)
    at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$6(IdeEventQueue.java:439)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:791)
    at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:438)
    at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:105)
    at com.intellij.ide.IdeEventQueue.performActivity(IdeEventQueue.java:604)
    at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:436)
    at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:881)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:484)
    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)
cezarypiatek commented 2 years ago

I'm sorry but Linux platform is not supported. MappingGenerator supports only Windows, and there are no plans to extend that support to other platforms (Linux/Mac) at the moment.

rfvgyhn commented 2 years ago

FYI, I did some digging and the cause of this is Environment.GetEnvironmentVariable("APPDATA") returns null on Linux which then causes Path.Combine to throw an exception. Possible fixes include:

  1. Replace the call with Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); which returns %APPDATA% on Windows and $XDG_CONFIG_HOME on Linux. This would require using net standard 2.0.
  2. Manually providing the fallback location Environment.GetEnvironmentVariable("APPDATA") ?? Environment.GetEnvironmentVariable("XDG_CONFIG_HOME").

I modified the IL of my local assemblies and the code actions are now showing up in Rider on Linux.

cezarypiatek commented 2 years ago

I can exclude the installer module loading on Linux, but this only will give you access to basic, non-premium features. I will provide that fix with the next release.

cezarypiatek commented 2 years ago

Should be fixed in 2022.7.46