How can I change the file type association of an existing file in WebStorm?
Solution 1:
In Settings
(or Preferences
for mac) > Editor
> File Types
you can edit patterns by which a file gets associated as some type or other.
If you select the patterns for a file type you have wrongly selected (in your case Text
type) you can remove the filename pattern with which was created to associate you file's filename as a wrong type.
Then click Apply
> OK
Solution 2:
I've had this problem in php storm 8.0.3 on OSX.
I was struggling with a single file that had been added as a text file, but I'd typed in the .js extension.
I tried deleting and recreating, renaming and renaming back, deleting .idea altogether. Nothing worked.
I found that PHPStorm had added the entire file name to the list of patterns for a text file.
....
*.txt
myfile.js
... etc
This was obviously overriding all other settings. And futhermore it was in the IDE Config not the project config. So I'm guessing every other project would have suffered the same issue.
Once I knew where to look it was easily fixed.
Navigate to:
PhpStorm > Preferences > Editor > File Types > <highlight> Text files
Then find myfile.js
in the Registered Patterns
panel and delete it.
The file should immediately assume it's correct association.