1

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
  • 120,522
  • 13
  • 212
  • 426
xjcl
  • 9,368
  • 5
  • 53
  • 64

2 Answers2

3

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

xjcl
  • 9,368
  • 5
  • 53
  • 64
0

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
  • 8,300
  • 9
  • 61
  • 125
  • Didn't help, not even with IDEA 2021.1. I guess editing lone script files without a gradle file / project around it just isn't supported? – xjcl May 04 '21 at 12:05
  • I found a solution, see my other answer – xjcl May 04 '21 at 22:55