ChatGPT解决这个技术问题 Extra ChatGPT

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

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.

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

C
CommonSenseCode

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


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!
H
Henry

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.


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....
J
Jeetendra Pujari

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


And don't forget "Apply" (like I did)!
T
Tonny Bui

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


M
Matthew Fritz

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.


A
Andrei G.

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 "+".

https://i.stack.imgur.com/9LCQH.jpg


D
Dan Revel

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.


i
illia permiakov

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

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 Find a file YOUR_PREFERENCES_DIRECTORY/options/filetypes.xml Edit it with any text editor and delete needed row, for example

Top Menu File->Invalidate Caches / Restart Enjoy


v
valdeci

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:

https://i.stack.imgur.com/Gj9yv.png

Selecting the file extension:

https://i.stack.imgur.com/yCIX7.png


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.
S
Stefano G.

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


M
Michael Oryl

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.

https://i.stack.imgur.com/yyNcL.png

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.


J
Joseph Eames

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.


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.

关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now