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

Can this library be used with IntelliJ? #24

Closed
joseraya opened this issue Oct 10, 2016 · 13 comments
Closed

Can this library be used with IntelliJ? #24

joseraya opened this issue Oct 10, 2016 · 13 comments

Comments

@joseraya
Copy link

I am using IntelliJ as my IDE and it underlines in red all my @dom functions. I tried to open the sample project at https://github.com/ThoughtWorksInc/todo/ and I have the same problem. Is there a way to get rid of this? I have looked at the docs and could not find it.
As it seems related to the use of the macro, is there an "easy" way to define a binding without the macro?

@Atry
Copy link
Collaborator

Atry commented Oct 11, 2016

This issue should be reported at https://youtrack.jetbrains.com

@Atry
Copy link
Collaborator

Atry commented Oct 11, 2016

Or you could try Scala IDE for Eclipse, which handles macros.

@deontologic
Copy link

I ran into the same issue. I investigated writing a plugin to support macro highlighting, but I'm unsure of how to change the return type of annotated vals and defs.

I submitted a question to the IDEA Scala forum here with more details.

@joseraya
Copy link
Author

I am aware that the problem with highlighting is IntelliJ's but my question was about the possibility of using the library without the macro. Anyway, thank you very much for answering.

@deontologic
Copy link

deontologic commented Oct 19, 2016

Scala's xml library is pretty weird. I doubt it would be possible to replace the macro by defining an implicit conversion from xml.Element to Binding[ ], but perhaps @Atry has some insight on the matter.

@Atry
Copy link
Collaborator

Atry commented Oct 20, 2016

Binding.scala changes types of XML literals via macros. IntelliJ IDEA seems using its own typer, which does not fully understand macros and other complex Scala syntax, even for those code that does not involve macros.

I have many Scala files that do not use macros. They are still red marked by IntelliJ IDEA.

@deontologic
Copy link

deontologic commented Oct 20, 2016

@joseraya Thought a bit more about it, and you can avoid having to use the @dom annotation.

Replace xml literals with scalatags's JSDom.

For example:

import scalatags.JsDom.all._

  def clicker(i: Var[Int]) = Binding[Node](
    div(
      button(onclick := {() => i := i.get + 1})("click me"),
      p("num times clicked: " + {i.bind.toString}),
      tag("test-tag")("this is a test")
    ).render
  )

  def app = Binding[Node]{
    val i = Var(0)
    div({clicker(i).bind}).render
  }

  def main(): Unit = {
    scalajs.dom.render(document.body, app)
  }

The only downside (upside? ;) ) is that you lose xml literals

@Atry
Copy link
Collaborator

Atry commented Oct 20, 2016

The entire app is recreated whenever i changes if you don't use XML literals.

@deontologic
Copy link

Yeah, just realized this :(

@Atry
Copy link
Collaborator

Atry commented Oct 22, 2016

XHTML literals in @dom methods create very sophisticated ScalaTags code able to partially data-bind on each element and element.

I bet you never want to hard-code the code.

@vodkaka
Copy link

vodkaka commented Jan 28, 2017

@deontologic @joseraya
there is a trick for you, define an implicit conversion (Node -> Binding[Node])

the complier won't do the implicit conversion, it knows what happen
but intellij will be tricked, so all type is right

@ritschwumm
Copy link

@vodkaka lol, nice

@JorgenG
Copy link

JorgenG commented Feb 9, 2017

@vodkaka Could you provide an example of this? I attempted defining it, but I am not familiar enough with Scala and Binding.scala to get it working.

EDIT: After some googling I came across this solution from reddit:
https://www.reddit.com/r/scala/comments/5se6hj/scalajs_reactive_frontend_framework/ddfhzqu/?st=iyxrpkul&sh=dc3d099d
implicit def makeIntellijHappy(x: scala.xml.Node): Binding[org.scalajs.dom.raw.Node] = ???

Atry pushed a commit to Atry/Binding.scala that referenced this issue Jan 27, 2023
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Atry pushed a commit that referenced this issue Jul 1, 2023
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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

6 participants