182

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.

3
  • after further investigation, I can't reliably reproduce this behavior, but I have seen several people ask this question so I imagine it's not something that was entirely unique to me. Commented Mar 23, 2013 at 19:19
  • 5
    stackoverflow.com/a/13374653/104891 Commented Mar 23, 2013 at 19:33
  • 1
    Thank you CrazyCoder. Since I can't reliably reproduce the behavior I can't verify that this will fix the issue but it appears to. Commented Mar 26, 2013 at 16:45

13 Answers 13

249

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

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

8 Comments

FYI, in my version of WebStorm this was under "Preferences > Editor > File Types".
This should be marked as the correct answer since it's more complete and is the solution, not just a workaround.
This worked for me, one of my filenames was explicitly showing as a "text file" and was not hitting the regex on another filetype.
Remember to select a particular "file type" eg. "Text File", because your file is not in the main menu, but in this particular file-type submenu!
It should be mentioned that you should click on the matching icon you accidentally mapped it to, in order to edit the association. I did every thing up until that step and was lost for a minute. Thank you!
|
207

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.

11 Comments

I know it's archeology, but come on Joseph Eames, mark this one as an answer. You can do it :)
This was it. Thank you. Furthermore, WHY is the editor doing this automatically?!!
Good question Alex, just had the same problem. Thanks to Henry I was able to sort this out :)
I just used this solution to solve a similar problem in PyCharm (another IntelliJ based IDE). Same location, same situation. A file that was originally associated with a text file and somehow couldn't be changed in spite of me changing the extension. Thanks for this. This should be marked as the answer.
Thank you so much. Mine was a regular expression for whatever reason. You saved me so much time and frustration....
|
31

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

1 Comment

And don't forget "Apply" (like I did)!
13

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

Comments

10

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.

Comments

5

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

Comments

2

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.

1 Comment

Thanks for this! I had multiple files with the same constants.js name and all were identified as plaintext and I had to manually select each one and Override file type. This is what I was looking for and should be the accepted answer
2

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

2 Comments

This is the best answer, at least for Webstorm 2022, and probably somewhat earlier as well. Instead of finding the file in the Project view, you can also right-click the file name in the Navigation Bar and select Override File Type, or search for it in Help > Find Action.
this just overrides it. not the desired result.
1

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.

Comments

1

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

<mapping pattern="delete.yaml" type="PLAIN_TEXT" />
  1. Top Menu File->Invalidate Caches / Restart

  2. Enjoy

Comments

1

Result For WebStorm 2021.1.3

  1. Select a file.
  2. File->File Properties->Associate with File Type...

Comments

0

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

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

Comments

-3

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.

3 Comments

It's a lot easier to just delete the incorrect entry in 'File types' settings, then name your file appropriately.
There's a much simpler solution to it: find your file in Settings -> Editor -> File Types and delete from there (see most voted answer).
Honestly had to do this in the end. No amount of messing around in the File Types settings fixed the problem.

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.