1

I have a problem similar to:

Wrong syntax highlighting for PHP file in PHPStorm

IIRC, I created a file under the wrong name (IndexViewphtml, no extension), then renamed it to IndexView.phtml. Since then, it is recognized as plain text:

enter image description here

As advised in the linked question, I went to Settings|Editor|File Types and ensured that this file name was not assigned to Text files:

PhpStorm File Types

I also checked that the file was not currently marked as plain text:

PhpStorm mark as plain text

As a last resort, I:

  • deleted the .phtml file and its parent folder
  • closed PhpStorm
  • rm -rf .idea
  • rm -rf ~/.cache/JetBrains/PhpStorm*

And to my surprise, when I re-launch PhpStorm and recreate the folder + file, it is still recognized as plain text!

If I rename it to, say Index2.phtml, the file is correctly recognized as PHP.

What did I miss? I'm using the latest 2020.3 EAP.

LazyOne
  • 158,824
  • 45
  • 388
  • 391
BenMorel
  • 34,448
  • 50
  • 182
  • 322
  • 1
    Weird. Try this: focus that file in Project View, then invoke `Ctrl+Q` (or whatever the shortcut you have for `View | Quick Documentation`) -- what so you see? – LazyOne Nov 16 '20 at 13:47
  • Have you checked whether `*.phtml` is registered as a filetype for PHP files? – Nico Haase Nov 16 '20 at 13:48
  • @NicoHaase It is, as I said if I rename to `Index2.phtml` it recognized as PHP (and so are my numerous other `.phtml` views). – BenMorel Nov 16 '20 at 13:51
  • @LazyOne Sorry, I rushed to find a solution and deleted the config directory, that I missed in my question, and it now works. I'm afraid I won't be able to debug further! – BenMorel Nov 16 '20 at 13:55

2 Answers2

2

I solved it by deleting the config folder (I had missed this one):

rm -rf ~/.config/JetBrains/PhpStorm*

Obviously you restart PhpStorm from scratch at this stage (like a new install), but it's better for me than dealing with a PHP file as text.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
0

Don't clear the whole config folder

Please check that your file type is not added in Auto-detect file type by content in File Type. If found remove and apply the changes.

System > Preference > Editor > File Type > Auto-detect file type by content in File Type

enter image description here

Prince Patel
  • 2,990
  • 1
  • 21
  • 28