I am trying to exclude a particular file in my project from being compiled.
According to the Intellij IDEA documentation you do this by "marking the file as plain text".
However, the context menu in the project view where this functionality is supposedly located has no such action. I am using version 13.02 of Intellij. Here is what my context menu looks like:
Under File > Settings > Build, Execution, Deployment > Compiler > Excludes, add an entry.
Any attempts to run a path specified here will result in a ClassNotFoundException, and a very important class indicator as well.
Just to compound on Makoto's answer (would comment but don't have reputation), it looks like this feature does not apply to classes (.java) or assets (images)...for these types of files, it looks like you will need to actually go to the compiler and explicitly state that the file(s) should be excluded.
However, for .htm, .xml, or really anything that isn't a class or asset you will find and can use the 'Mark as plain text' option.
Edit: It looks like you can also go to the 'Messages Make' error / warnings view and Exclude from there, a little less work IMHO.
The answer that #Makoto has given is pretty much the way to go, but in case that you are like me and you get easily both distracted and frustrated looking for that menu, you could use this shortcut:
press ctrl + shift + a , and in the input box that appears type excludes, and select the first item that appears.
Related
Does anyone know a way to search for all (and only) the commented code across all classes in a java project?
For example, using "Find in Path" to search for "//" is not what I want because it also returns URIs (http://......). I want a specialized way to do that.
Thanks in advance.
You can use Structural Search in IntelliJ IDEA.
Below screens as for the version 2019.1.1 (Ultimate Edition) (Works for IntelliJ IDEA 2020.3 too)
Go to Edit > Find > Search Structurally...
File type should be Java and select any path wherever you like to search.
From the top right corner click on gear icon and click on Existing Templates...
Then from Java > Comments, Javadoc and Metadata select comments
Then it will add /* $CommentContent$ */ to the Structural Search window as for the first screenshot.
This will find all the commented code (including Javadoc) from the selected path.
For more info refer : Structural search and replace
About the best you could do would be the Find In Path and use a REGEX of:
^//
That will fix your http:// problem. But it won't find comments that don't start at the beginning of a line. I suppose you could write a much more complex REGEX to find "//" but not proceeded by http: But of course comments can be in /* */ blocks too. So it all depends on how absolute you want to get.
As of intellij 2020.3, there is an inspection for commented out code in java:
Java | Code maturity | Commented out code
So if you want a list of commented out code, you can:
right+click your project, module, subfolder, directory or file where you want to search.
click analyze > inspect code
Click OK
This should open the inspection result window where all your commented out code will be grouped under Java | Code maturity | Commented out code :
If you don't want intellij to search for other issues too, you can create a new profile in File | Settings | Editor | Inspections exactly for that and select it in the analyze dialog.
I've used AppCode (Intellij C++/ObjC IDE that replaces Xcode) for a while and really gotten used to being able to Ctrl+Click on any identifier to get to its definition/decleration.
Now on a new work place, I'm using CLion for a somewhat larger code base and Ctrl+Click hardly ever works. It only seem to work when the identifier is in the same file.
Is there anything I need to setup for this to work correctly? CLion seem to index the code successfully and doing text searches works fine.
You need to use import project functionality of CLion from File -> Import Project and give ok for CMakeLists.txt file automatic creation. Never mind the file is for CMake, you can build your project with other tools too, but CLion uses it for the dependencies.
Then append in the beginning of that file a line stating:
include_directories(.)
After that go to File -> Settings and there search for Keymap from the left and after that on right, right below the word "keymap" there is a selection element for taking for example Eclipse default keymapping in use and there you have at least (I tested only it) the ctrl + click functionality working like charm!!
kudos about the include_directories(.) goes to this question: CLion indexer does not resolve some includes in the project directory
You need to press ctrl + alt + shift + n.
And after pressing it a dialog box will appear to enter your variable/function name and click enter.
Tip: Filter the result for a better experience. Filter option is present on right side of the dialog box.
To get a quick peek of function/variable definition press ctrl + q while focusing on the variable or function.
To get the detailed or full definition of function press ctrl + shift + i while focusing on the variable or function.
I just looked at one of my more complicated teaching examples with multiple header/source files where this would come up.
What I see is that ctl-click (and the red/green arrows in the gutter) does work only in the same file. But I can right-click on a method from another file and choose to go to either the declaration (in header) or definition (in cpp).
The hotkeys to do this are not ctl-click. But you can remap hotkeys in IntelliJ ides, so you may be able to come up with hotkey combinations that don't seem too awkward to you.
What helped me was to run File > New CMake Project from Sources
Until that point, Ctrl+click in CLion would go to the definitions, but wouldn't find any usages.
CLion 2016.2 helpfully detects potential errors in the file you're editing, which can be seen in the validation bar to the right of the code.
That's just a single file though, is there a way (like a tool window) to get a list of all such warnings in the whole project, or specific parts of it?
Bonus points if it also lists warnings and errors from the compiler, though that's less important, because the compiler output already includes any it found.
Yes, it is possible. The feature you are looking for is called the Inspector.
Do: Find Action... | Inspect Code. It will show a pop-up that will allow you to select the scope: file, whole project, custom, and the Inspection profile (you can choose the type of errors you want to see):
After clicking OK, this is an example of the output, that you can navigate with the mouse or with keyboard shortcuts:
In version 2017.2, I have it under Code | Inspect Code....
You can also right click a folder in Project view and select Inspect Code... there to be able to check only that folder.
IntelliJ show the squiggly red underline under require paths (node.js) that it can't find. In my case, I have a file that is copied to a particular place on installation. Their location in the source has nothing to do with their location in the installation. Its especially annoying because intelij shows that red underline for all folders in its file browser.
var x = require('./some/invalid/path')
I like that it has this check, but I want to disable it for this file since it doesn't make sense for that case. How can I do this, ideally in intelliJ 12?
That's how you suppress an inspection for a class, method or statement:
Place your cursor inside the warning statement, press Alt + Enter, choose the entry that describes your warning, and from the sub-menu select Suppress for class or statement.
You will find more info on the IDEA webhelp.
I found a dumb way to do it - make the require path an expression rather than a simple string literal like this:
var x = require('./some/invalid/path'+'')
I guess it confounds intellij enough that it just says "screw it its probably fine".
I'm having an issue with IntelliJ, that I cannot seem to find a solution for myself. I have not changed any settings, yet when I started my IDE this morning, all Inspections and other highlighting has disappeared.
By highlighting, I mean stuff like variable names becoming purple, static finals shown with italic text, etc.
Inheritance seems to be broken as well, in that an implementing method links to the implemented interface method, but interface methods do not link to the implementing method.
My search for this tells me that there is an icon for this in the bottom right. That's set to "Inspections", and under configuration, it seems like everything is set to default.
Is there some way to un-break my IDE?
Another solution:
File -> Power Save mode
It needs to be disabled.
The (or at least one) answer to this is:
File -> Invalidate Caches
Make sure the folder the code is in is marked as the sources root. If it's not marked as the sources root, syntax highlighting will be very limited.
To mark a directory as the sources root, right click the directory, then navigate down to "Mark directory as" and select "Sources root."