One .js file not recognized as javascipt, others ok

Hi, I'm actually using IntelliJ to edit my javascript files, but you guys might have a better idea what is going on.



My IntelliJ is having trouble recognizing the file "RowLabel.js" as a javascript file. When I create this file, it treats it as a plain text file (text file icon), and there is no syntax highlighting. If I rename this file, either via the OS or through Refactor -> Rename menu to something else, say "RowLabel2.js", it gets correctly recognized as a javascript file (with syntax highlighting). I am unable to duplicate this behavior with any other file name, except that particular one. Weird, huh?

Attached is a screen cap showing this problem. Here, I've made a new project "untitled" with "RowLabel.js" and "RowLabel2.js" files, that are both empty. I'm using the latest version of IntelliJ.

I have tried invalidating my caches already. Is there anything else I can try?

Thanks,
Tim

Attachment(s):
idea-js-filename-bug2-about.png
idea-js-filename-bug1.png
3
21 comments

Hi Timothy,

Settings | File Types | Text files -- check for "RowLabel.js" pattern there and remove it.

34

Thanks, that was exactly it!
So perhaps you can also tell me how it ended up there?

0

To answer my own question, I must have used the new file dialog, and associated RowLabel.js as a text file type. Thanks for your helpful reply, Andryi!

0

I do not know for sure .. but it is indeed most likely to be the reason.

0

I did something similar by mistake :

  • Created new file
  • Entered filename without extension
  • Got prompted by the new file dialog
  • Selected Open matching files in associated application
  • Pressed OK

This prevented me from editing this specific file in PhpStorm. Note that deleting the file and recreating it didn't solve the issue; it looked like the filename was the problem.

After a while I found out that a pattern entry had been added in Settings | File Types | Files Opened In Associated Applications, with this specific filename. Make sure you remove it from there too.

Hope that helps anyone encountering this issue.

11
Thank you Nicolas Beaucage, you're the master
0
Avatar
Permanently deleted user

I have the same issue, but not the same cause or maybe just a newer IntelliJ that doesn't offer the same fix?

Just like the original post:

I was adding a file and somehow types got in the mix, though I named my file foo.js

The file was added to git as well.

It is recognized as a Text File and no syntax highlighting, no auto-complete or formatting.

If I rename the file just like the original poster (with a 2) it is recognized as JS and I get the benefits of an IDE.

Unlike the "accepted" fix this file, under the original name (foo.js) is not listed in the File Types dialog under Text.

 

0
Avatar
Permanently deleted user

I just want to note that I have:

git rm -f foo*

But, same thing when I create a new file.

So, I followed the rm op with a commit.

Same behaviour...

0

Hello Neil Lindberg,

I know it might seem a bit tedious, but I would recommend browsing all options in the Preferences | Editor | File Types | Recognized File Types list.

Ensure that the foo.js filename is not present in any Registered Patterns down below. For good measure, ensure it's not in Ignore files and folders further below either.

Hope that helps, have a nice day!

P.S. I'm using PhpStorm 2017.3.4

 

2

@Neil Lindberg 

Please provide screenshots -- e.g. how that file looks in Project View panel. In particular I'm interested in file icon.

Use it using Default theme and not some Material or stuff where icons may be replaced by others/unknown to me.

0
Avatar
Permanently deleted user

I did find it in the File Types under Text. I was looking through all the types expecting *.foo.js or *.js in the text list. After clearing all refs from .idea/workspace.xml and restarting I enlisted help and found the file name at the bottom of the list.

So, it was me. Thanks. I don't know how to delete my comments or I would.

1

I LOVE you @Andriy Bazanov! Thanks, this had me suck for a while.

0

For others stumbling across this, I have an extensionless project all interpreted as PHP (don't ask.) Adding * to the PHP file types list fixes that and allows all the IDE features to work, but breaks all the features for JS - all black type, no navigation, etc. etc. Posting another thread about it.

0

I came across this happening to me and was able to go through Preferences | Editor | File Types > Select "Text" under Recognized File Types (top section) and then find the name of the file in the Registered Patterns (bottom section) that was under issue. 

This got me wondering why this happened in the first place and what would be a use case to have a file ending with the .js extension to be read as a text file.

 

WebStorm 2019.2

2

@Derrick Dunville

>This got me wondering why this happened in the first place and what would be a use case to have a file ending with the .js extension to be read as a text file.

Please see this comment -- that's most likely what had happened: https://intellij-support.jetbrains.com/hc/en-us/community/posts/207062135/comments/115000626264

0

It's 2020 and I don't know how I got into this state. It wasted nearly 15 minutes while I search for what the deal was. At the same time, it was trying to install a plugin! So, it knew something was wrong. I created a file with no extension on accident, then added "ts" since it is a TypeScript file. No problem! Then, it tried to install TypoScript (whatever that is!). More and more IntelliJ can't keep up with the needs of developers. Make things more ergonomic!!

1

In 2020 none of the posted answers worked, here's what did:

  1. Left click the file
  2. On the top toolbar, select File -> File Properties -> Associate with File Type
2

@Hellohellosharp

In all cases where I have seen such behaviour such unwanted pattern entry will be under one of the file types entries in "Settings/Preferences | Editor | File Types"

The actual entry may be different, depending on what you did (when such unwanted association had happened) and what IDE version you have.

It normally happens when creating a new file with no extension (e.g. using "File | New... | File" action):

2020.2 and older that would be:

  • "Text" entry (most likely, default selection)
  • "Files opened in associated applications" entry (less likely)

2020.3:

  • the same + "Auto-detect file type by content" -- a new entry that is default now.

 

On the top toolbar, select File -> File Properties -> Associate with File Type

What you did here is pretty much the same: you forcibly associated that file name with specific file type (e.g. added "myfile.php" to "PHP" file type ... even though it already has *.php pattern).

If it works for you and not causing any issues -- it's great, no probs. It just... you better try to fix the original issue (wrong file type) instead of hard overriding it (hammer it with nails).

For example: trying to "fix" index.php file (that is treated as PHP anyway for me, but lets assume it is wrongly displayed as Plaint Text) using your proposed solution:

After associating it with "PHP" file type -- it still works, but looks unnecessary:

 

My suggestion:

  1. Check those 3 file type entries first (see below) and remove any unwanted patterns from there.
  2. Then remove that extra pattern that you have created.

Settings/Preferences | Editor | File Types:

  • Auto-detect file type by content
  • Files opened in associated applications
  • Text

 

1

The UX for this behaviour is so bad, it seriously needs be reworked.
At least rename the prompted options' label to something less confusing.

0

Please sign in to leave a comment.