halirutan / Wolfram-Language-IntelliJ-Plugin-Archive

Wolfram Language and Mathematica plugin for IntelliJ IDEA.

Home Page:https://wlplugin.halirutan.de/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bracket auto-close doesn't support comments or associations

JonMcLoone opened this issue · comments

With bracket typing enabled type "("
and you automatimatically get "()"
However type "(*" and you end up with "(*)", an unterminiated comment. It would be better if you got "(**)"

Likewise typing "<|" is not recognized as a token needing closing.

I often have sort of the opposite wish: just don't auto-add a closing comment, as it's more trouble than good. I know: I should get used to using the shortcut key for commenting out parts of the code (my most common use of comments). :-)

IntellIJ has not one, but two commenting shortcuts: one is for block comment, the other for line comment.

On my macOS system, the line comment is Cmd-/ and the block comment is Opt-Cmd-/

With Mathematica, "line comments" and what Cmd-/ does make no sense. This has been a long-standing annoyance for me, but I was too lazy so far to switch the keyboard shortcuts around. I think I am going to switch them over right now, so Cmd-/ does what I usually want (block comment).

Just for the record, the biggest thing for me will be when imported package symbols are supported and the "Could not resolve definition" go away.

This is already supported, with limitations. One must add the location of the external packages to the project. Then all symbols in the external package which have a ::usage message will be considered public. (At least, as I recall, currently usage messages are the only way that it identifies public symbols. I don't recall if PackageExport without ::usage is already supported. @halirutan ?)


Do you have any ideas about how else one may detect which symbols from a package are public, and which aren't? I remember we had multiple discussions about this with @halirutan and could not find any other way which is both simple and robust. While this method is not ideal, one advantage is that package authors can adapt to the behaviour of the IDE fairly easily, and add the missing usages. This is what I have been doing.

I get unknown markers on ever package2 symbol in the package1 source file.

Do you get that even for symbols which had a usage in package2? That should not happen. Within a project, all symbols with a usage should be considered defined, regardless of which file they are defined in.

Hey Jon,

as usual, my un-paid head of tech-support, Szabolcs, was already faster with answering :)
Here is a quick list that hopefully helps and it assumes you're on Windows or Linux (Mac has slightly different shortcuts):

Commenting

  • Without any selection, you can always press Ctrl+Shift+/ to get a new, empty (**) with the cursor inside
  • Without any selection Ctrl+/ will comment the current line if there's something on it
  • With selected text, Ctrl+/ will comment out the lines that span the text and Ctrl+Shift+/ will comment out exactly your selection. Please note that you can easily select bigger code constructs.
  • Inside a comment, Ctrl + Shift+ Enter will jump to the next line and create a new comment with the cursor inside.
  • You can autocomplete function names in comments with Ctrl+Space. In an empty comment (**) with the cursor inside, Ctrl+Space will suggest all the styling directives like ::Section::

You see there are a lot of one-hit shortcuts that allow you to work with comments and you basically never have to type the (* yourself. As Szabolcs mentioned, we had quite some discussions about how much automatic intelligence we should put into the plugin and the general consensus was: Too much cleverness is often bound to break in specific situations, can be surprising and turns out to be annoying at times.

Associations

Associations are similar to typing comments, but the IntelliJ Platform provides much more things for comments. Association cleverness is implemented as Live Templates which means you simply type ass, hit Tab and a new <|...|> we appear. With the next version of the plugin, the cursor will be placed between the brackets. Note how many of the standard constructs are supported by Live Templates and that you can also wrap selected code using Live Templates.

Final Notes

As Szabolcs already disclosed, you have to set up the project structure correctly to get the IDE to recognize symbols from other files. Although not much WL Plugin-specific documentation exists, this topic was indeed RTFM. Additionally, I need to stress that most language-unspecific features of IntelliJ IDEA also work with the WL Plugin and having a look at the IntelliJ IDEA Documentation can never harm. At least the Code Editing sections are a must. Note that you can switch the OS keyboard layout at the top-right of the page so that you always see the correct shortcuts.
Things like column-selection mode, several cursors, jumping and navigating source code, etc. are a real breeze in IDEA. And if you ever run into a situation where you think that something appears as if there should be a better way, please just drop me a line. I'm always glad to help.