Can I get WebStorm to skip files that are single lines with export statements when navigating? - webstorm

I'm looking for the site banner, so I tap Shift Shift and search for "sitebanner", which leads me to packages/shared/src/app/components/index.ts. I open that and it is one line:
export { default as SiteBanner } from './SiteBanner';
I Cmd + click on './SiteBanner'; which leads me to:
export { default } from './SiteBanner';
I Cmd + click on that ./SiteBanner and it leads me to the right place.
We have roughly 150 files like this in our code base. It's a pattern the org has adopted. It's usually just one (like the second one).
Is there any way to tell WebStorm to just skip files that only have one line and that line is an export? Kind of like how Java tools will skip/collapse empty directories.

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.

Is it possible to auto-update the name of variables in two different directories

I use Webstorm to test Javascript code with the testing framework Mocha. I want to give my variables and functions names which facilitate an intuitive understanding of my code in the best possible way. As a consequence I often rename my variables and functions.
So if I in the same project have file1.js in a lib folder with the following content:
var foo = 'I am a variable';
and test_of_file1.js in a testfolder with the following content:
var foo = 'I am a variable';
and I use Webstorm's refactoring tool in file1.js to rename foo to boo I would like this change to take effect in both files. I do not use JsDoc to document the code or Git to track any changes (unsure if that is relevant). I have tried using refactoring, but it only takes effect in file1.js.
How can I make it take effect in both files?
You're mixing two concepts.
When you're renaming something (such as a file called in many other modules), Webstorm will refactor all files containing such references.
In your case, you're essentially "replacing" the name of the var. But the var foo in file 1 is NOT a reference to var foo in file 2. They'Re two completely different things.
Based on what you described above, you need to do a FIND & REPLACE operation on your project & test files.
But be careful, and make sure to review each find/replace operation.
The problem above is that you refactored (or find/replaced) only within the open file. That won't work. You'll need to select your project folder in the Project tab (should contain your project files and test files) and type: CTRL + SHIFT + R (might be different on windows) to do a project-wide Find/Replace.

How to change indentation mode in Atom?

I haven't been able to figure this out yet. Atom seems to use spaces as the default indentation mode. I prefer to have tabs instead though. Sublime Text has built in functionality for switching and converting indentation.
Anyone found out how to change the indentation mode of Atom?
Some screenshots from Sublime Text:
See Soft Tabs and Tab Length under Settings > Editor Settings.
To toggle indentation modes quickly you can use Ctrl-Shift-P and search for Editor: Toggle Soft Tabs.
Go to File -> Settings
There are 3 different options here.
Soft Tabs
Tab Length
Tab Type
I did some testing and have come to these conclusions about what each one does.
Soft Tabs - Enabling this means it will use spaces by default (i.e. for new files).
Tab Length - How wide the tab character displays, or how many spaces are inserted for a tab if soft tabs is enabled.
Tab Type - This determines the indentation mode to use for existing files. If you set it to auto it will use the existing indentation (tabs or spaces). If you set it to soft or hard, it will force spaces or tabs regardless of the existing indentation. Best to leave this on auto.
Note: Soft = spaces, hard = tab
Add this to your ~/.atom/config.cson
editor:
tabLength: 4
OS X:
Go to Atom -> prefrences or CMD + ,
Scroll down and select "Tab Length" that you prefer.
You could try going to "Atom > Preferences > Editor" and set Tab length to 4.
This is for mac. For windows you will have to find the appropriate menu.
Adding #Manbroski answer here that worked for me:
try Ctrl-Shift-P Editor: Toggle Soft Tabs
Late to the party, but a clean way to do this on a per-project basis, is to add a .editorconfig file to the root of the project. Saves you from having to change Atom's settings when you're working on several projects simultaneously.
This is a sample of a very basic setup I'm currently using. Works for Atom, ST, etc...
http://editorconfig.org/
# Automatically add new line to end of all files on save.
[*]
insert_final_newline = true
# 2 space indentation for SASS/CSS
[*.{scss,sass,css}]
indent_style = space
indent_size = 2
# Set all JS to tab => space*2
[js/**.js]
indent_style = space
indent_size = 2
This is built into core: See Settings ⇒ Tab Type and choose auto:
When set to "auto", the editor auto-detects the tab type based on the contents of the buffer (it uses the first leading whitespace on a non-comment line), or uses the value of the Soft Tabs config setting if auto-detection fails.
You may also want to take a look at the Auto Detect Indentation package. From the docs:
Automatically detect indentation of opened files. It looks at each opened file and sets file specific tab settings (hard/soft tabs, tab length) based on the content of the file instead of always using the editor defaults.
You might have atom configured to use 4 spaces for tabs but open a rails project which defaults to 2 spaces. Without this package, you would have to change your tabstop settings globally or risk having inconsistent lead spacing in your files.
I just had the same problem, and none of the suggestions above worked. Finally I tried unchecking "Atomic soft tabs" in the Editor Settings menu, which worked.
If you are using the version 1.21.1:
Click on Packages / Settings View / Open
Select "Editor" on the left side panel
Scrool down until you see "Tab Length"
Edit the value. I like to set it to 4.
Now, just close the active tab pane and you are done.
Tab Control gives nice control in a similar manner to that described in your question.
Also nice, for JavaScript developers, is ESLint Tab Length for using ESLint config.
Or if you're using an .editorconfig for defining project-specific indentation rules, there is EditorConfig
If you're using Babel you may also want to make sure to update your "Language Babel" package. For me, even though I had the Tab Length set to 2 in my core editor settings, the Same setting in the Language Babel config was overriding it with 4.
Atom -> Preferences -> Packages -> (Search for Babel) -> Grammar -> Tab Length
Make sure the appropriate Grammar, There's "Babel ES6 Javascript Grammar", "language-babel-extension Grammar" as well as "Regular Expression". You probably want to update all of them to be consistent.
If global tab/spaces indentation settings no longer fit your needs (I.E. you find yourself working with legacy codebases with varied indentation formats, and you need to quickly switch between them, and the auto-detect isn't working) you might try the tab-control plugin, which sort of duplicates the functionality of the menu in your screenshot.
When Atom auto-indent-detection got it hopelessly wrong and refused to let me type a literal Tab character, I eventually found the 'Force-Tab' extension - which gave me back control.
I wanted to keep shift-tab for outdenting, so set ctrl-tab to insert a hard tab. In my keymap I added:
'atom-text-editor':
'ctrl-tab': 'force-tab:insert-actual-tab'
Changing language-specific configuration
I changed the default tab settings, and it still did not impact when I was editing my files, which were Python files. It also did not change when I modified the "*" setting in ~/.atom/config.cson . I don't have a good explanation for either of those.
However, when I added the following to my config.cson, I was able to change the tab in my Python files to 2 spaces:
'.source.python':
editor:
tabLength: 2
Thanks to this resource for the solution: Tab key not respecting tab length
All of the most popular answers on here are all great answers and will turn on spaces for tabs, but they are all missing one thing. How to apply the spaces instead of tabs to existing code.
To do this simply select all the code you want to format, then go to Edit->Lines->Auto Indent and it will fix everything selected.
Alternatively, you can just select all the code you want to format, then use Ctrl Shift P and search for Auto Indent. Just click it in the search results and it will fix everything selected.
Yet another answer: If you are using Atom Beautify note that it has its own settings to determine the "Indent Char".

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