Prevent Intellisense from inserting semicolons in VS Code - visual-studio-code

We don't use semicolons in TypeScript. Each time Intellisense in VS code (v1.18.1) inserts a line, it terminates it with ;. Example would be an import statement.
Is it possible to configure VS Code not to append semicolons? Very inefficient right now to have to delete them manually.

TSLint semicolon rule (has autofix)
TSLint extension for vscode
tslint.json rules section:
"semicolon": [true, "never"]
settings.json Ctrl+,
"tslint.autoFixOnSave": ["semicolon"]
There is an open issue about it https://github.com/Microsoft/TypeScript/issues/19882

If you're using Prettier add to settings.json
"prettier.semi": false
And then in tslint.json
"semicolon": [true, "never"],

TypeScript 3.6 is now able to detect whether your file uses semicolons or not, which can be leveraged in VS Code for quick fixes, refactorings, transformations (e.g. auto import) and other features. It is called Semicolon-Aware Code Edits.
Editors like Visual Studio and Visual Studio Code can automatically apply quick fixes, refactorings, and other transformations like automatically importing values from other modules. These transformations are powered by TypeScript, and older versions of TypeScript unconditionally added semicolons to the end of every statement; unfortunately, this disagreed with many users’ style guidelines, and many users were displeased with the editor inserting semicolons.
TypeScript is now smart enough to detect whether your file uses semicolons when applying these sorts of edits. If your file generally lacks semicolons, TypeScript won’t add one.

Related

Grammar checker in VS CODE

I need to check the grammar of various docstrings, is there a way to do that directly in Visual Studio Code (or any other editor) without copying and pasting each docstring in a grammar checker like Grammarly?
At the bottom of the extension settings for Grammarly, under Grammarly>Files: Include you could add python files to be checked, by adding:
**/*.py
Note, this would include the whole python file and not just the docstrings.

How do I set up text replacement shortcuts in VS Code?

I want to set up automatic text replacement shortcuts in Visual Studio Code similar to snippets in SQL Complete or text replacements on iOS. So for example: if I type ssf I want VS Code to replace it with SELECT * FROM. (Or alternatively, offer it as an autocomplete suggestion).
How can I set up automatic text replacement rules in VS Code?
you can use extensions such as the "JavaScript (ES6) code snippets"

How to disable VS Code prettier from deleting extra parenthesis

I'm using prettier in VS Code for typescript. It always remove extra parenthesis, for example
(new Controller()).setData(data).run();
will always be format into
new Controller().setData(data).run();
Which rules handle this deletion? I did see a similar rule in eslint: no-extra-parens. However, I am not using this rule in my eslint file.

VS Code syntax highlighting for SQL commands in Python

The first syntax highlighting is of VS Code and the second one is of Sublime Text. I searched for extensions but I couldn't find anything which could detect SQL commands like CREATE TABLE and highlight them or suggest them as I start typing.
Sublime Text and Atom have this feature by default, but I can't get it to work in VS Code.
I am working with .py files so the syntax highlighting works only for Python commands and the whole text (inside quotes) is treated as string in VS Code.
Is there any fix to get syntax highlighting like Sublime Text / Atom in VS Code when working with SQL syntax in .py files or highlighting commands even if it's inside quotes ("")?
It seems the VS Code doesn't support this feature officially.
Hence, I make an extension called Highlight String Code which can highlight SQL expressions in Python or any other language.
You can easily use it by uppercasing the first keyword of the SQL command and adding a semicolon at the end:
I hope the extension can be helpful.

How to create keybinding that reindents only selected lines in Visual Code

I'm using Visual Studio Code 1.14 on MacOS and have tried creating my own keybinding that re-indents only the lines of code that I've highlighted.
I have this in keybindings.json:
[
{
"key": "alt+cmd+[", "command": "editor.action.reindentlines",
"when": "editorHasSelection && editorTextFocus"
}
]
I chose the commands for the "when": clause based on this article.
The Problem: When I use my custom keyboard shortcut, it re-indents the entire page instead of only the text I've selected.
It's petty, perhaps, but this can cause a formatting nightmare, such as when writing a ReactJS app where VSC's regex pattern for detecting how to indent lines seems to get confused when looking at a mix of javascript and html within a .jsx file. In such cases I only want to re-indent/auto-indent the text I choose - not the entire page.
How can I get the keybinding to function with the behavior I'm looking for?
The when-clause can only change when the command is active - not how it behaves. The issue is that the implementation of the command operates on the whole file, rather than the current selection.
I don't think reindentation of a selection is supported yet, but it seems to be on the roadmap. For instance, it was mentioned in #19847 (emphasis mine):
The reason that right now we don't support Reindent in ranges is that we have some issues with boundaries in embedded-language files. Some of them are just TextMate Grammar issues but I'm sure if that can fix all. Once that issue is addressed, I think it's easy to support reindent in ranges/selection. And then Reindent when paste/moveLines/etc.
Thanks to #Gama11 for pointing me to this github issue.
The solution that accomplishes what I was trying to do is to use the command editor.action.formatSelection instead of editor.action.redindentlines.
As shown by Gama11, reindent in ranges isn't currently supported, however Format Selection is a very similar command that uses different logic to accomplish indentation within a certain range.