JetBrains Rider IDE shortcut for printing - intellij-idea

In JetBrains IntelliJ, one can write just sout and the IDE write System.out.println();
I know that C# can be used in different types of projects.
Some projects require printing things in console and thus we need to print things like Console.WriteLine();
Some other projects require printing using ILogger like log.LogInformation();
... etc.
First, I wonder if there is something similar to IntelliJ print shortcut in JetBrains Rider? Then, is there a way to program this shortcut or change this shortcut manually so that it use the suitable print command for the project I work on?

Related

Rider automatically places attributes on the same line as the property [duplicate]

I prefer my code to be more compact but JetBrains Rider (or any IntelliJ based editor) automatically formats it like this:
void Start()
{
}
How can I change it to the following by default?
void Start() {
}
You should not configure this thing manually in settings, just allow Rider to "learn" from your code.
Format code block as you like
Select desired code block and invoke Reformat and cleanup... -> Detect code style settings... from alt+enter menu:
Observe changes which Rider detects:
Save settings for all solutions on this machine, or just for the specific (current) solution. There are other options also:
Now your IDE is configured to format code exactly you want :)
P.S. This thing works in JetBrains Rider and R# tools, do not know about other IDEs, probably there you have to find the same settings manually.

Intellij IDEA Plugin to read and print the contents in a IDE editor in console

I am new to Intellij Idea plugin development using gradle! I am hoping to develop a simple plugin to read the contents of java class and print it in the console(Toolwindow) in a live manner(i.e when I type a new word in the java class it should print the work in the console even if the class is saved or not)
Currently I am refering to the Intellij plugin architecture and components in https://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_components.html. I came across concepts such as editor panes and all But I have no idea how to read the contents in IDE editor(current java file)! How can I do it?
You can grab the raw text of an editor window:
Editor editor = anActionEvent.getRequiredData(CommonDataKeys.EDITOR);
editor.getDocument().getText();
If you want to get some structure from the contents of the editor window, you can use the PsiFile API:
PsiFile psi = anActionEvent.getData(CommonDataKeys.PSI_FILE);
The PsiFile API lets you walk through a file in whatever language(s) make sense. For example, for Java files there is a PsiJavaFile interface that knows about Java specific features like package name, imports, etc.
http://www.jetbrains.org/intellij/sdk/docs/basics/architectural_overview/psi_files.html
Lastly, to print a message you can try normal System.out.print() or you can use the ConsoleView class to work with the IntelliJ console tool views:
TextConsoleBuilderFactory.getInstance()
.createBuilder(anActionEvent.getProject())
.getConsole()
.print("Hello", ConsoleViewContentType.NORMAL_OUTPUT);
One note: All of the above code assumes you're working with an ActionEvent. You might want to check out the TypedActionHandler interface to get notified when the editor text changes:
http://www.jetbrains.org/intellij/sdk/docs/tutorials/editor_basics/editor_events.html#handling-keystrokes-in-the-editor

CLion code navigation with C++ doesn't work

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.

How to make auto completion in WebStorm (*.js) and IntelliJ (*.go) work the same

In WebStorm I can type something like
document.gEBI
press tab key, and it'll autocomplete to
document.getElementById()
But when I do the similar thing in IntelliJ
fmt.Prl
Auto completion doesn't work (the desired result fmt.Println()) at all, it works only if all the letters match strictly in order.
Is it possible to enable this functionality in IntelliJ? I've imported all the settings from WebStorm.
These Tab key shortcuts aren't part of the auto-complete system the Jetbrains use for all their IDEs as LazyOne says, they are actually part of the template-invocation system.
The auto-complete functionality is built into the shortcut: Ctrl+Space.
I suggest looking up the template invocation for .Println() in the settings, Jetbrains documentation, or raising a ticket with Jetbrains on YouTrack for clearer documenation/control over template-invocation.

tools / IDE that highlight function definition on which files [just wondering]

is there already any IDE / tools that if you highlight a function name, it will open the file where that function is defined on the next window so we could understaand what that function does?
you know just wondering.
Visual Studio has a "Go To Definition" feature available in its text editor. When the cursor is on a varible, function, class, and so on, you can right-click and select the "Go To Definition" menu item and it will take you to where the function is defined. If the definition is part of the .NET Framework, the feature will "jump" to the definition in the Object Browser for VB.NET projects or to the "meta-data" of C# projects
Are there any IDEs that don't do this? Every IDE I have ever used had this feature: several Smalltalk IDEs, Hopscotch, several Lisp IDEs, NetBeans, Eclipse, Visual Studio, VisualAge for Java Micro Edition, VisualAge for Java, VisualAge for Smalltalk. Even many text editors can do it: TextMate, Vim, Emacs, Notepad++.
By using something like ctags this is definitely possible, provided of course your favourite editor also has support for ctags. The good thing about ctags is that with a bit of tweaking it can be made to work with almost any language.
In Netbeans you highlight the function -> right button click -> Navigate -> Go To Declaration and it will open the file where this function has been created.
I use Eclipse as my Java IDE and find the F3 key to be the quickest way to open the declaration. Good description of this functionality below (from here):
F3: Open declaration. Alternatively,
you can click on the Declaration tab
(in the Java perspective, go to
Window, then Show View, then
Declaration). This key shows entire
method declarations in the declaration
pane when you click on a method call
in the code.
I haven't used this with other languages editors in Eclipse (Perspectives in Eclipse), but I'd guess the functionality is similar.