xjcl
xjcl

Reputation: 15309

Only partial syntax highlighting in Kotlin script file

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:

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

Upvotes: 5

Views: 2411

Answers (3)

Jishin Dev
Jishin Dev

Reputation: 402

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.

Upvotes: 3

xjcl
xjcl

Reputation: 15309

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

Upvotes: 9

Sasha Shpota
Sasha Shpota

Reputation: 10300

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.

Upvotes: 1

Related Questions