3

I opened a folder in Android Studio which contains a Kotlin script file (.kts). I configured a JDK as SDK in Project Structure (but I added no gradle files), and running the file as Kotlin script works fine. However the syntax highlighting is only PARTIALLY working, see below example (Linux Mint 19.3 and AS 4.1.3):

enter image description here

Some of the stuff missing:

  • unused variable should be gray (val unused)
  • to/forEach keyword should be yellow and italic
  • misspelled variable names should be red
  • bad style such as extra spaces should be underlined
  • etc.

What's even going on here? Is this some sort of "fallback" mode?

Any way to use the "full" syntax highlighting from normal Android projects, so I can spot mistakes earlier?

For reference, this is what it "should" look like (pasted into a random Android project):

enter image description here

Ken White
  • 123,280
  • 14
  • 225
  • 444
xjcl
  • 12,848
  • 6
  • 67
  • 89

3 Answers3

5

Renaming the file to end in *.main.kts (scriptname.main.kts) enabled full highlighting for me!

xjcl
  • 12,848
  • 6
  • 67
  • 89
1

I get this type of issues from time to time with IntelliJ IDEA. I haven't found the reason why it happens, neither do I know the 100% working solution. But here are the options that usually help me solve it:

  • Restart IDE
  • Invalidating caches: File > Invalidate Caches...
  • Re-import the project. Remove the .idea folder and the project.iml file and try to import the project again.
  • Update the IDE. Last time I had this issue, nothing helped but updating IDEA to 2021.1.

I hope some of these options will help.

Sasha Shpota
  • 9,436
  • 14
  • 75
  • 148
0

Newer IDE versions have a Repair IDE (File->Repair IDE) option that did the trick for me. It takes you through a set of steps - reindexing, reopening the project, invalidate cache restart etc and tries to repair the IDE.

Jishin Dev
  • 371
  • 7
  • 10