179

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.

Evan Wieland
  • 1,445
  • 1
  • 20
  • 36
Joseph Eames
  • 2,529
  • 3
  • 16
  • 15
  • 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. – Joseph Eames Mar 23 '13 at 19:19
  • 5
    http://stackoverflow.com/a/13374653/104891 – CrazyCoder Mar 23 '13 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. – Joseph Eames Mar 26 '13 at 16:45

12 Answers12

250

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

CommonSenseCode
  • 23,522
  • 33
  • 131
  • 186
ofzza
  • 2,701
  • 1
  • 11
  • 5
  • 20
    FYI, in my version of WebStorm this was under "Preferences > Editor > File Types". – MrHen Jan 26 '15 at 16:16
  • This should be marked as the correct answer since it's more complete and is the solution, not just a workaround. – Alejandro García Iglesias Mar 03 '16 at 21:04
  • 2
    This worked for me, one of my filenames was explicitly showing as a "text file" and was not hitting the regex on another filetype. – enderland Jul 06 '16 at 15:49
  • 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! – Dimitry K Jul 28 '16 at 16:11
  • I had this particular problem when I needed to associate *.geojson files to the standard JSON Schema. Using this answer and adding the necessary association worked a charm. Thanks for this. Also, this answer should be marked as the right answer... – Mystus Aug 08 '16 at 15:16
  • 2
    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! – mrClean Jan 19 '17 at 21:57
  • Why is clicking `Apply` needed? – Amit Aug 02 '18 at 12:43
  • Didn't expect there to be a GUI for this. Imagined I'd have to poke around cache files in a text editor. Thanks Jetbrains :) – willem Mar 12 '20 at 05:30
205

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.

Henry
  • 7,721
  • 2
  • 38
  • 38
  • 14
    I know it's archeology, but come on Joseph Eames, mark this one as an answer. You can do it :) – demicanadian Oct 12 '15 at 09:56
  • 1
    This was it. Thank you. Furthermore, WHY is the editor doing this automatically?!! – Alex Ziskind Oct 24 '15 at 17:12
  • 3
    Good question Alex, just had the same problem. Thanks to Henry I was able to sort this out :) – AlexG Nov 17 '15 at 14:11
  • 2
    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. – Preston Crawford May 02 '16 at 00:44
  • 1
    Thank you so much. Mine was a regular expression for whatever reason. You saved me so much time and frustration.... – dsingleton Aug 31 '16 at 11:17
  • 1
    Used this for a .less file in Webstorm just now and it was super helpful and resolved my problem – shane Oct 04 '16 at 18:19
  • 1
    Thank you, that was really annoying! Worked in WebStorm. – theblang Feb 04 '17 at 21:16
  • 1
    Amazingly this is still happening (for me it's a Dart file being treated as text). Thanks so much for the fix, I would've literally killed myself. – Geoffrey Zheng Aug 02 '17 at 13:46
  • 1
    Same thing happened to me for Webstorm! Glad I found this answer – tristanbbq Nov 22 '17 at 15:20
  • @GeoffreyZheng. I don't believe it's actually a bug in the IDE just a situation that's difficult to solve. – Henry May 03 '18 at 21:20
  • Anyone still struggling to find, if you can't find the association in "text files", also look into "Auto-detect file type by content". – Eres Jul 11 '21 at 20:06
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

Jeetendra Pujari
  • 1,286
  • 2
  • 17
  • 31
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

Tonny Bui
  • 131
  • 1
  • 2
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.

Mystus
  • 459
  • 6
  • 15
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

Andrei G.
  • 151
  • 3
  • 5
3

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

valdeci
  • 13,962
  • 6
  • 55
  • 80
  • 1
    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. – jdunning Jul 07 '22 at 06:15
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.

Dan Revel
  • 124
  • 6
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

illia permiakov
  • 423
  • 3
  • 10
1

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.

Michael Oryl
  • 20,856
  • 14
  • 77
  • 117
  • 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 – Raul Rene Jan 25 '23 at 11:02
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

Stefano G.
  • 143
  • 2
  • 14
-4

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.

Joseph Eames
  • 2,529
  • 3
  • 16
  • 15
  • 16
    It's a lot easier to just delete the incorrect entry in 'File types' settings, then name your file appropriately. – FlavorScape Mar 20 '14 at 17:13
  • 3
    There's a much simpler solution to it: find your file in Settings -> Editor -> File Types and delete from there (see most voted answer). – Michal M. May 07 '15 at 10:18
  • Honestly had to do this in the end. No amount of messing around in the File Types settings fixed the problem. – bressain Feb 07 '18 at 21:38