tommilata / intelliroutes

Support for Play Routes in IntelliJ IDEA
MIT License
19 stars 6 forks source link

"Cannot resolve" error when controller function has 2 arguments #9

Closed LLCampos closed 4 years ago

LLCampos commented 4 years ago

The following method is in a controller:

  def someMethod(Argument1: Int, Argument2: Int): Action[AnyContent] = {
    ???
  }

But this happens:

image

I wouldn't expect the Argument2 to be red.

tommilata commented 4 years ago

Hi, thanks for reporting. I wasn't able to reproduce your example unfortunately.

Could you please try to:

Routes File(0,102)
  RoutesRouteImpl(ROUTE)(0,101)
    PsiElement(HTTP verb)('POST')(0,4)
    PsiWhiteSpace(' ')(4,5)
    RoutesPathImpl(PATH)(5,18)
      PsiElement(/)('/')(5,6)
      RoutesPathSegmentImpl(PATH_SEGMENT)(6,18)
        PsiElement(static path segment)('someEndpoint')(6,18)
    PsiWhiteSpace(' ')(18,19)
    RoutesCallImpl(CALL)(19,101)
      PsiElement(controller method)('@controllers.UserEntitlementsController.someMethod')(19,69)
      PsiElement(()('(')(69,70)
      RoutesArgumentsImpl(ARGUMENTS)(70,100)
        RoutesArgumentImpl(ARGUMENT)(70,84)
          PsiElement(argument name)('Argument1')(70,79)
          PsiElement(:)(':')(79,80)
          PsiWhiteSpace(' ')(80,81)
          PsiElement(argument type)('Int')(81,84)
        PsiElement(,)(',')(84,85)
        PsiWhiteSpace(' ')(85,86)
        RoutesArgumentImpl(ARGUMENT)(86,100)
          PsiElement(argument name)('Argument2')(86,95)
          PsiElement(:)(':')(95,96)
          PsiWhiteSpace(' ')(96,97)
          PsiElement(argument type)('Int')(97,100)
      PsiElement())(')')(100,101)
  PsiElement(new line)('\n')(101,102)
LLCampos commented 4 years ago

I get errors on that example project.

image

The dump:

Play2RoutingFile(0,102)
  Play2ScalaPsiStub(ROUTING_LINE)(0,101)
    PsiElement(HTML_METHOD_NAME)('POST')(0,4)
    PsiWhiteSpace(' ')(4,5)
    Play2URIPath(ROUTING_PATH)(5,18)
      PsiElement(PATH_SLASH)('/')(5,6)
      Play2ScalaPsiNamedUrlPart(ROUTING_STATIC_REGEXP)(6,18)
        PsiElement(PATH_STATIC_IDENTIFIER)('someEndpoint')(6,18)
    PsiWhiteSpace(' ')(18,19)
    PsiElement(MANUALLY_MANAGED_AT)('@')(19,20)
    MethodCall(20,101)
      ReferenceExpression: controllers.UserEntitlementsController.someMethod(20,69)
        ReferenceExpression: controllers.UserEntitlementsController(20,58)
          ReferenceExpression: controllers(20,31)
            PsiElement(identifier)('controllers')(20,31)
          PsiElement(.)('.')(31,32)
          PsiElement(identifier)('UserEntitlementsController')(32,58)
        PsiElement(.)('.')(58,59)
        PsiElement(identifier)('someMethod')(59,69)
      ArgumentList(69,101)
        PsiElement(()('(')(69,70)
        TypedStatement(70,84)
          ReferenceExpression: Argument1(70,79)
            PsiElement(identifier)('Argument1')(70,79)
          PsiElement(:)(':')(79,80)
          PsiWhiteSpace(' ')(80,81)
          SimpleType: Int(81,84)
            CodeReferenceElement: Int(81,84)
              PsiElement(identifier)('Int')(81,84)
        PsiElement(,)(',')(84,85)
        PsiWhiteSpace(' ')(85,86)
        TypedStatement(86,100)
          ReferenceExpression: Argument2(86,95)
            PsiElement(identifier)('Argument2')(86,95)
          PsiElement(:)(':')(95,96)
          PsiWhiteSpace(' ')(96,97)
          SimpleType: Int(97,100)
            CodeReferenceElement: Int(97,100)
              PsiElement(identifier)('Int')(97,100)
        PsiElement())(')')(100,101)
  PsiWhiteSpace('\n')(101,102)

Other scenarios:

1 Argument:

  def someMethod(Argument1: Int): Action[AnyContent] = {
    Action(Ok("hello"))
  }

image

Play2RoutingFile(0,86)
  Play2ScalaPsiStub(ROUTING_LINE)(0,85)
    PsiElement(HTML_METHOD_NAME)('POST')(0,4)
    PsiWhiteSpace(' ')(4,5)
    Play2URIPath(ROUTING_PATH)(5,18)
      PsiElement(PATH_SLASH)('/')(5,6)
      Play2ScalaPsiNamedUrlPart(ROUTING_STATIC_REGEXP)(6,18)
        PsiElement(PATH_STATIC_IDENTIFIER)('someEndpoint')(6,18)
    PsiWhiteSpace(' ')(18,19)
    PsiElement(MANUALLY_MANAGED_AT)('@')(19,20)
    MethodCall(20,85)
      ReferenceExpression: controllers.UserEntitlementsController.someMethod(20,69)
        ReferenceExpression: controllers.UserEntitlementsController(20,58)
          ReferenceExpression: controllers(20,31)
            PsiElement(identifier)('controllers')(20,31)
          PsiElement(.)('.')(31,32)
          PsiElement(identifier)('UserEntitlementsController')(32,58)
        PsiElement(.)('.')(58,59)
        PsiElement(identifier)('someMethod')(59,69)
      ArgumentList(69,85)
        PsiElement(()('(')(69,70)
        TypedStatement(70,84)
          ReferenceExpression: Argument1(70,79)
            PsiElement(identifier)('Argument1')(70,79)
          PsiElement(:)(':')(79,80)
          PsiWhiteSpace(' ')(80,81)
          SimpleType: Int(81,84)
            CodeReferenceElement: Int(81,84)
              PsiElement(identifier)('Int')(81,84)
        PsiElement())(')')(84,85)
  PsiWhiteSpace('\n')(85,86)

1 Argument with default value

image

Play2RoutingFile(0,90)
  Play2ScalaPsiStub(ROUTING_LINE)(0,89)
    PsiElement(HTML_METHOD_NAME)('POST')(0,4)
    PsiWhiteSpace(' ')(4,5)
    Play2URIPath(ROUTING_PATH)(5,18)
      PsiElement(PATH_SLASH)('/')(5,6)
      Play2ScalaPsiNamedUrlPart(ROUTING_STATIC_REGEXP)(6,18)
        PsiElement(PATH_STATIC_IDENTIFIER)('someEndpoint')(6,18)
    PsiWhiteSpace(' ')(18,19)
    PsiElement(MANUALLY_MANAGED_AT)('@')(19,20)
    MethodCall(20,89)
      ReferenceExpression: controllers.UserEntitlementsController.someMethod(20,69)
        ReferenceExpression: controllers.UserEntitlementsController(20,58)
          ReferenceExpression: controllers(20,31)
            PsiElement(identifier)('controllers')(20,31)
          PsiElement(.)('.')(31,32)
          PsiElement(identifier)('UserEntitlementsController')(32,58)
        PsiElement(.)('.')(58,59)
        PsiElement(identifier)('someMethod')(59,69)
      ArgumentList(69,89)
        PsiElement(()('(')(69,70)
        AssignStatement(70,88)
          ReferenceExpression: Argument1(70,79)
            PsiElement(identifier)('Argument1')(70,79)
          PsiElement(:)(':')(79,80)
          PsiWhiteSpace(' ')(80,81)
          SimpleType: Int(81,84)
            CodeReferenceElement: Int(81,84)
              PsiElement(identifier)('Int')(81,84)
          PsiWhiteSpace(' ')(84,85)
          PsiElement(=)('=')(85,86)
          PsiWhiteSpace(' ')(86,87)
          LITERAL(87,88)
            PsiElement(integer)('2')(87,88)
        PsiElement())(')')(88,89)
  PsiWhiteSpace('\n')(89,90)

Some info about my IntelliJ:

IntelliJ IDEA 2019.3.3 (Ultimate Edition)
Build #IU-193.6494.35, built on February 11, 2020
Licensed to Luis Campos
Subscription is active until February 28, 2020
Runtime version: 11.0.5+10-b520.38 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.15.0-76-generic
GC: ParNew, ConcurrentMarkSweep
Memory: 1925M
Cores: 8
Registry: 
Non-Bundled Plugins: Karma, PsiViewer, Pythonid, org.intellij.scala, com.github.tomasmilata.intelliroutes, com.intellij.lang.puppet, de.netnexus.camelcaseplugin, mobi.hsz.idea.gitignore, org.jetbrains.plugins.hocon, org.jetbrains.plugins.ruby
tommilata commented 4 years ago

Thanks for providing the details.

The problem in your case is that the scala plugin in IntelliJ Ultimate has built-in support for Play (unlike the Community version) and as a result, both plugins are trying to associate their editors with routes files. So what you are seeing is actually a routes file editor from the Scala plugin, not this one.

I am not sure how to handle conflicting file associations on my side at the moment, so I'd recommend:

LLCampos commented 4 years ago

Thanks!

Here is what worked for me:

  1. Go to File -> Settings -> Editor -> File Types
  2. Search for Html Routing Support For Play 2 Framework
  3. Remove de registered pattern from there

image

  1. Search for Play Framework Routes
  2. Add routes to Registered patterns

image

tommilata commented 4 years ago

Great, thanks for sharing this!