How can I make a VS Code language extension insert an indent after a line ending in a colon, as in Python? - vscode-extensions

The VS Code documentation has a clear if short explanation of how to do custom indentation, but doing this has no effect — whatever I put in the "indentationRules", it fails to match the simplest patterns, and it doesn't even stop the built-in indentation from working, it goes right on using the default indentation described in the link above. All the other bits of the language extension are working, it's not a general problem, it's specific to trying to get these indentation rules to work. I've tried to find examples to copy from the internet but with no success. (I found an example of a grammar for Python but the only mention of indentation in it was as a possible kind of error, which is puzzling.)
Thanks for your help.

Related

Intellij IDEA SDK - How can I programmatically handle spellcheck 'typos'?

Wrote a plugin to handle some custom format stuff in yaml files that I've written for a huge project. It's a chat bot that can respond in a huge number of ways. There is a lot of slang and non-standard words in the yaml.
I don't want to disable spellchecking as I want to fix legitimate speeling errors. But the annotations under the "misspelled" slang words are conflicting with the annotations in my plugin, and causing issue.
One yaml file has 349 "typos". 10% or so are legit. The rest are slang and custom words.
I need to do one of two things. Either add those words to the dictionary (I've found the method to do that - SpellCheckManager.getInstance(project).acceptWordAsCorrect()) OR get a list of the words and create a custom dictionary from them. Both approaches require me to grab a list of all typos in the document/editor/project.
That's the part I can't find. Looked everywhere. (List of current Annotations? List of current Problems?) Googled my fingers off. Anyone able to point me in the right direction?
This is not the IDEAL solution, but it worked for my means, and I'm leaving the answer in case this is googled.
In DaemonCodeAnalyzerImpl, there is a method:
DaemonCodeAnalyzerImpl.getHighlights(Document document, HighlightSeverity minSeverity, Project project);
This returns a list of all highlights in the document. The method is Annotated with #TestOnly, and docs state that it should only be used in Test code because it breaks/shortcuts the normal way to access that. It still works in non-test code however.
Since the only thing I wanted was the strings of the typos, I pulled the list, then looped through the HighlightInfo's in the list, and pulled the .getText()s.
No danger of screwing anything up.
Then pushed all those strings into:
SpellCheckerManager.getInstance(project).acceptWordAsCorrect(word, project);
Viola! All current highlighted typos are now added to the dictionary.
Proper solution? No. Good enough for what I needed to accomplish? Yup.

how to add asterisk in block comments for vscode extension

Background: I am making a extension to use for a not well known coding language.
While creating a vscode extension, I have run into an issue with block comments. When creating a new line in the comment I was hoping to automate the process of adding and asterisk (*) and a space on a new line. The only way I have found to do this is with the on enter rules.
The issue that I have with this is that the on enter rules can only see the line above and after the cursor. As far as I can tell this could lead to inaccurate comments. One case could be if there was a multiplication issue stretching across multiple lines.
Am I thinking about this correctly, and if I am, are there any solutions to add this asterisk?

ANTLR v4 plugin for Intellij IDEA: have to restart IJ after changing lexer grammar

I try to use an ANTLR plugin for IJ, but there is an annoying problem. I don't know, what I'm doing wrong, but after changing something in lexer grammar besides generating ANTLR recognizer (often, but not always) I have to restart IJ to see the correct parsing tree. Already tried to "Save all" or "Synchronize" before testing parser, but nothing helps. Has anyone encountered such a problem?
Thank you in advance.
As glytching suggested in their comment, this is the problem described in this GitHub issue: https://github.com/antlr/intellij-plugin-v4/issues/242
The solution seems to be to hit Save. Another user also mentions touching the file from the terminal.
This puzzled me, as I'm using PyCharm and the way it seems to be set up by default is to auto-save as you work so I basically never interact with Save explicitly in any way. However, in this case hitting Ctrl+S does seem to make a difference (compared with just letting it auto-save) and it solves the issue for me.
For clarity, my situation is:
I have a grammar broken up into several parts (mixture of lexer, parser and combined grammars) which are imported into the 'main' grammar.
I am working interactively with the ANTLR Preview window (OP mentioned generating a recognizer, but I think this issue is completely independent of running the Antlr generator).
If I make a change in one of the imported grammars and switch back to the main grammar to re-run my start rule there it doesn't always pick up the change from the imported grammar.
Hitting Ctrl+S after making the change in the imported grammar, before switching back to my main grammar, fixes the problem.

Agda PDFs with colour

I am using lhs2TeX for my literate Agda files and I'd like them to be syntax highlighted. I know I can achieve some highlighting via %format instructions but that is a bit too much. I have tried using lhs2Tex-hl as instructed at http://foswiki.cs.uu.nl/foswiki/pub/FPOld/CourseLiterature/presentation.pdf but to no avail.
If anyone can help with getting PDF's with coloured Agda, that'd be appreciated!
Edit
The Agda latex backend is great but has some issues. Biggest issue is spec-environment. It says that spec is undefined, so making it a synonym for code should fix things: \newenvironment{spec}{\begin{code}}{\end{code}}, but instead now there are type-checking issues and missing $ errors. Using sed to remove spec blocks altogether results in missing $ errors; likewise \newenvironment{spec}{\verbatim}{\endverbatim}. Similar trouble with using |...|. Also, I honestly liked the %format of lhs2tex ...

Automatic breaking of line comments in Webstorm, PHPStorm, IntelliJ IDEA

If I'm typing a very long comment over line comments, how can I get Webstorm (et al.) to rearrange the comments automatically into a paragraph that neatly lines up? Note that I'm not asking for block comments, although if a solution exists for block comments but not line comments, I'm also interested.
If you're familiar with text editors, I basically want what M-q does in emacs or gq does in vim.
My question is not this question: Php Storm : How can i automate breaking lines in PHPStorm 2.1
There is no internal API available on whole IDEA platform to do such things (reformat/warp comments while still keeping them as comments and not just brand new line), unfortunately.
Hopefully it will be available in one of the future versions. Devs already working on it -- see this comment for example: http://youtrack.jetbrains.com/issue/WEB-5653#comment=27-758067
On another hand -- please try Wrap to Column plugin -- it does the job with both line and block comments (just checked for PHP code (line and block) and JavaScript (line)).