2

IDEs offer a lot of cool features like jump to declaration and syntax highlighting. Just out of curiosity, in order to provide these features, does my IDE (IntelliJ) first have to compile my source code? Like I noticed that whenever I open a new project in my IDE, there is a lag, and it generates a "target" folder. Does the IDE compile any of my source code without me explicitly running the code or telling it to compile?

Michael Lafayette
  • 2,972
  • 3
  • 20
  • 54
  • IDEs usually use something like the Eclipse [Abstract Syntax Tree](http://www.vogella.com/tutorials/EclipseJDT/article.html) for analysis. – greg-449 Oct 08 '18 at 15:23
  • 1
    Somewhat related: [What is a presentation compiler?](https://stackoverflow.com/questions/9468367/what-is-scala-presentation-compiler). – Andrey Tyukin Oct 08 '18 at 16:20
  • 1
    Possible duplicate of [What is "Scala Presentation Compiler"?](https://stackoverflow.com/questions/9468367/what-is-scala-presentation-compiler) – Suma Oct 08 '18 at 18:57

2 Answers2

3

There's several things going on here. When you import an sbt project, IntelliJ runs sbt to extract the project structure. This takes a while, and sbt itself creates the target folder.

Most IDE features, such as jumping to declaration don't require compilation. IntelliJ instead parses the code into it's own internal syntax model which allows for indexing, error highlighting and so on. This model allows many refactorings and analysis even on code that has compile errors. Indexing typically happens after the initial import in a background process.

Justin Kaeser
  • 5,868
  • 27
  • 46
1

This largely depends on the IDE.

IntelliJ makes use of an indexing process in which it takes your entire project and indexes it in its own internal structures known as Psi* classes. These classes then are referenced by the IDE to provide static analysis and determine code flow.

I'm not as familiar with Eclipse, but the Abstract Syntax Tree exists and is likely analogous to IntelliJ's internal structure.

IntelliJ doesn't make an effort to compile your code on your behalf unless you let it, but in order for its static analysis to actually work, your code must be compilable. If it isn't, you won't get static analysis; you'll get red squiggly lines instead.

Makoto
  • 104,088
  • 27
  • 192
  • 230