How can I change the file type association of an existing file in WebStorm?

Webstorm

Webstorm Problem Overview


I accidentally created a file with no extension and I chose the wrong file type association. Text Document I think. I renamed it to have the .js extension which is what I wanted, but now it's stuck without any syntax highlighting. WebStorm doesn't treat it as a javascript file. I can't find anywhere to change how WebStorm treats this file. I've tried renaming it and renaming it back and that doesn't work. With any other name, (with a .js extension) it treats it as a javascript file, but not as the original name.

How can I fix this? The WebStorm documentation is no help.

Webstorm Solutions


Solution 1 - Webstorm

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 - Webstorm

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.

Solution 3 - Webstorm

Go to Settings->File Types and then click on "Text Files". You should see the file if you scroll down. You can then remove it with the association by selecting it and clicking the - (minus) button

Solution 4 - Webstorm

Refer to File -> Settings -> IDE Settings -> File Types

In right select "Text files" in Reconigzed File Types then find in Registered Patterns your file and click remove your file

Solution 5 - Webstorm

On Windows 8, I was able to remove the invalid association by going under File > Settings > Editor > File Types, then I selected "Text files" as the Recognised File Type and removed the invalid entry from the Registered Patterns block at the bottom.

Solution 6 - Webstorm

So much answers and everything is close but no one as in my case.

A had an issue with .vue files. My old PHpStorm version did not track the .vue files, so I somehow associated them as .js files. However, this was a mistake because the syntax is different and I saw a lot of "mistakes" in the code.

Yeah, the solution is really in Settings (or Preferences for mac) > Editor > File Types dialogue. In the window you can see the list of possible associations. At the very bottom of the list you'll see the Vue.js Templates and I had no associations in the bottom window (see the pic), so I manually added *.vue association after clicking green "+".

I think this would be right for any proper file type added to PHPStorm. However, you can add your own file type.PHPStorm associations

Solution 7 - Webstorm

I have found in phpstorm that I can use the Refactor > Rename... function to associate a file of unspecified file type (e.g. a name with no extension) with a file type.

For example if I have a bash script named do_the_things I can Refactor > Rename it to do_the_things.sh which causes it to pick up the bash highlighting, then when I Refactor > Rename it back to do_the_things it keeps the bash highlighting.

Solution 8 - Webstorm

This works in PHPStorm, i can assume in WebStorm should be something similar

  1. Go to Preferences directory Here is how to find for your OS https://intellij-support.jetbrains.com/hc/en-us/articles/206544519-Directories-used-by-the-IDE-to-store-settings-caches-plugins-and-logs

  2. Find a file YOUR_PREFERENCES_DIRECTORY/options/filetypes.xml

  3. Edit it with any text editor and delete needed row, for example

>

  1. Top Menu File->Invalidate Caches / Restart

  2. Enjoy

Solution 9 - Webstorm

I've found a solution, delete (o rename as .old) the file: C:\Users<YourSelf>.PyCharmCE\config\options\filetypes.xml

Es: C:\Users\goofy.PyCharmCE2018.3\config\options\filetypes.xml

Solution 10 - Webstorm

In my case, the file in question, DepositBreakdownList.js, was associated with a "type" called "File type auto-detected by file content". Selecting it and then removing it (with the minus sign button) allowed the file to be treated as a proper JavaScript file again.

Removing the mis-typed file

Until I did that, I was unable to use Live Templates associated with JavaScript, even though the file extension was .js, which was just maddening.

Solution 11 - Webstorm

In the new WebStorm versions we can click on the file, select the option Override File Type and change for the type that we want.

Selecting the Override File Type option:

enter image description here

Selecting the file extension:

enter image description here

Solution 12 - Webstorm

After like an hour of searching and screwing around I found a fix:

I renamed the file (through the refactor command) to a temporary file name. Then I created a new file with the correct name with the .js extension and it worked, then I copied the code from the original to the newly created file with the correct extension.

I imagine selecting "new javascript file" and doing the same thing would also work.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJoseph EamesView Question on Stackoverflow
Solution 1 - WebstormofzzaView Answer on Stackoverflow
Solution 2 - WebstormHenryView Answer on Stackoverflow
Solution 3 - WebstormJeetendra PujariView Answer on Stackoverflow
Solution 4 - WebstormTonny BuiView Answer on Stackoverflow
Solution 5 - WebstormMatthew FritzView Answer on Stackoverflow
Solution 6 - WebstormAndrei G.View Answer on Stackoverflow
Solution 7 - WebstormDan RevelView Answer on Stackoverflow
Solution 8 - Webstormillia permiakovView Answer on Stackoverflow
Solution 9 - WebstormStefano G.View Answer on Stackoverflow
Solution 10 - WebstormMichael OrylView Answer on Stackoverflow
Solution 11 - WebstormvaldeciView Answer on Stackoverflow
Solution 12 - WebstormJoseph EamesView Answer on Stackoverflow