How can I change the file type association of an existing file in WebStorm? - 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.

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

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.

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

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

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.

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.

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:
Selecting the file extension:

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.

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
<mapping pattern="delete.yaml" type="PLAIN_TEXT" />
Top Menu File->Invalidate Caches / Restart
Enjoy

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

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

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.

Related

Navigate to the file from output in the terminal - WebStorm

Is it possible to tune WebStorm so that when I have something like this in my terminal window, then I just click on the filename and jump to it.
Not possible using built-in terminal (please vote for IDEA-118566 and IDEA-154439).
Awesome Console plugin might be a solution; but it doesn't support built-in terminal (https://github.com/anthraxx/intellij-awesome-console/issues/23)
there is also Output Link Filter plugin that provides similar functionality, but it looks outdated and (also) doesn't work in built-in terminal
Update (2022): IDEA-118566 is already fixed, links should work. Please note that providing links for particular output needs adding specific logic handing such output. Thus, if you encounter missing links in a particular output, please file a separate issue request describing link output format and steps to reproduce such output.
Webstorm does in fact now have this functionality.
Note that the bug about this functionality being missing (linked in another answer) has been marked as fixed: https://youtrack.jetbrains.com/issue/IDEA-118566.
It's not quite a single click solution, but what I do, is double click the text so that it auto selects and copies the path, including line and char numbers to clipboard. Then use the shortcut for Goto File.... Hit paste (cmd+v) then Enter and it will take you to the exact location.
For me, the shortcut for Goto File... is cmd+shift+O - you can check your shortcut in the menu Navigate -> File...
You can use the following format to output text in the terminal via console.log and the path will be clickable:
at ($FILE_FULL_PATH:$LINE_NUMBER:$SYMBOL_NUMBER)
Example with the full path to the file:
at (/home/ubuntu/project/index.js:12:55)
However, if you're running WebStorm with exact file path's project's folder, you can use the following format:
at (./project/index.js:12:55)
I installed Awesome Console plugin and with this plugin, all files and links in the console and terminal will be highlighted and can be clicked. Source code files will be opened in the IDE, other links with the default viewer/browser for this type.
You can jump to files from the terminal with left click
Just select file path (dblclick) & press "shift" twice (search everywhere) & press "enter"...

How to make WebStorm IDE to correctly recognise file type?

 The Background
(Within JetsBrains / WebStorm IDE) Initially I created a file called HelloWorldContainer - accidentally left out the .js extension (I meant to create HelloWorldContainer.js).
WebStorm asks what file type I would like that file to be (e.g. JavaScript? Text File? HTML? etc.). I accidentally hit the enter key - and WebStorm has treated it as a text file.
Realising my mistake, I renamed the file to HelloWorldContainer.js (adding that .js to the end`). Hoping this will change the file type back to a JavaScript file.
The Problem
For some reason, WebStorm is still "seeing" HelloWorldContainer.js as a text file??? (snapshot below). This is a problem as now my JavaScript Live Templates no longer load for this file.
Snapshot 1: showing HelloWorld.js as a JavaScript file, whilst HelloWorldContainer.js showing as a text file (huh?).
Snapshot 2: for HelloWorld.js, WebStorm knows it is a JavaScript file - Live Templates successfully loaded as a result. (Cmd + J)
Snapshot 3: for HelloWorldContainer.js, WebStorm (for some reason) fail to recognise it as a JavaScript file - the JavaScript Live Templates fail to load as a result. (Cmd + J)
How to I make WebStorm recognise HelloWorldContainer.js as a JavaScript file again?
Note: I've tried...
delete the HelloWorldContainer.js and recreate it again, WebStorm is still seeing it as a text file.
rename HelloWorldContainer.js to HelloWorldContainer2.js - WebStorm now sees it as a JavaScript file. But if I rename it back to original name, WebStorm sees it as a text file again. (I really want to call my file HelloWorldContainer.js! :-)
The Solution
Just tried out the solution provided below (by #LazyOne)- works like a charm! Some snapshots for note keeping...
Snapshot 4: remove the offending pattern.
Snapshot 5: WebStorm now sees the file as a JavaScript again!
Settings/Preferences | Editor | File Types
Locate Text entry in top list
Remove offending pattern from bottom list -- most likely will be HelloWorldContainer.js or very similar
Hit OK and wait till project will be re-indexed.

MS Word 2010 Completely reformatted my whole document

I'm thinking this might have something to do with a template, but it's really weird.
I started off with a .doc file and a .docx file that I had previously edited, combined them, and saved the result as a .docx file. Both files were originally created as templates by someone else long ago. Within a few minutes, the fonts and spacing of everything in the document have been changed, making a total mess out of my document. I also noticed something in the lower left corner referencing "contacting" a template. I never noticed this before with these templates.
What a mess. How can I make it stop doing this? If I take the time to reformat everything the way I want it again, I don't want it to revert back the next time my back is turned.
Thanks,
Rebeccah
Ah. I got it figured out. One of the component documents, and the merged document, had a template attached to it that was stored on a server. The template file on the server doesn't exist any more - someone must have recently deleted it. The reformatting apparently reflects Word automatically changing the template to normal.dot.
If I catch it in time, before the changes are made, I can save the file as a .dot or .dotx (template) file, and then attach that local template file to future documents so they don't have to rely on the template that is no longer on the server.
How I figured this out:
Google found an answer to a question about disabling a long wait for a linked file that no longer existed, leading me to File | Options | Advanced | General - uncheck "Update automatic links at open." That didn't undo the reformatting that had already happened, but may have prevented reformatting of the component document the next time I opened it.
The same answer pointed me to the right side of the File page, where various file properties are displayed. When I click on "Show All Properties", I can see the file name of the Template file, as the eighth property displayed.
General googling about Word templates led me to File | Options | Customize Ribbon | Customize the Ribbon, where I checked the previously empty box next to "Developer". Now, Developer | Document Template allows me to see and change the location of the document template.
I opened a previous version of one of the component files (the .doc file), the one that had the template from the server attached to it, and watched Word search for the template. But it did not reformat it the file. I saved the file as .dot, as .dotx with compatibility, and as .dotx - just to be sure I had all necessary options available.
I opened my reformatted composite file, went to Developer | Document Template, and specified my recently saved .dotx file as the template, made sure that "Automatically update document styles" was checked, and clicked OK.
Voila! I have my previous formatting back.
Rebeccah

gruntfile not color codes like other JS files

For some reason Webstorm will not color the code within a Gruntfile, it opens like a standard text file, I cant seem to find the settings to make it work like a normal JS file. I don't recall changing any setting which could have effected this.
Please check if 'Gruntfile.js' (or 'gruntfile.js' if your file name starts with lower case) is added to text file patterns in Settings | Editor | File types -> 'Text files' file type. Removing this pattern should solve your problem

How to correctly assign template file in IntelliJ?

I inherited an old Zope project, and I am also new to Intellij.
Template files got the file ending .xpt (eXtended PageTemplates)
They contain mostly html, but also tal-tags, which either include syntax like person/getName or even "name python: user.getName()".
Currently, those files show white text on black background.
I want those file endings associated with html/xml whatever, so I get a better overview visually.
BUT I really need to keep the Intellij functions like refactor and find usages and so on working, so Intellij finds methods, which are only called inside those templates.
Any help is appreciated!
Go to File -> Settings -> File types. There in Recognized File Types you can find XML files template, then in Registered Patterns add your file pattern: *.xpt