5

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)
  • extension methods (.forEach/.to/.map/.toInt/...) should be yellow and italic
  • errors should be underlined red
  • bad style such as extra spaces should be underlined yellow
  • 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

3
  • Maybe this YouTrack issue is related. Commented May 14, 2022 at 16:16
  • That doesn't seem related to me, can you explain? Commented May 14, 2022 at 21:00
  • So, forget about it. Commented May 15, 2022 at 5:55

3 Answers 3

10

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

Sign up to request clarification or add additional context in comments.

Comments

3

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.

1 Comment

I spent a whole day trying to resolve the issue and tried a ton of solutions, but nothing helped me except this answer. Thank you! Important note: There are a few steps in the "Repair IDE" process, and my issue was resolved only in the last step.
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.

3 Comments

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?
I found a solution, see my other answer
Thanks for me removing the .idea folder did the trick

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.