Autocomplete for the require statement in VS Code - autocomplete

I can't find anything straight and to the point on why VS Code's intellisense doesn't show a suggestion for the require() statement. E.g. const EventEmitter = require('events'); Why is it that require() doesn't appear in intellisense? I've looked at the settings.json file and tried a number of VS Code extensions, but can't get this to work. What am I leaving out?

Related

Make new command in .ipynb markdown in VSCode

I am trying to create new commands for markdown in an ipython notebook file in VSCode, but am having trouble doing so
This post shows an example which (kinda) works in jupyter notebook:
$\newcommand{\vect}[1]{{\mathbf{\boldsymbol{{#1}}}}}$
This is the vector $\vect{x}$.
But pasting this exact code in VSCode, I get the error:
ParseError: KaTeX parse error: Undefined control sequence: \vect at position 1: \vect{x}.
So it seems the new command does not get created. Am grateful for any solution
Issue 125425 opened by Chandresh Pant and mentioned in the comments seems to be solved for VSCode 1.69 (June 2022)
See PR 148006 and commit acb156d:
In order to make macros defined by the author persistent between KaTeX elements, we need to pass one shared macros object into every call to the renderer.
KaTeX will insert macros into that object and since it continues to exist between calls, macros will persist.
See KaTeX docs.
Try the Markdown + Math extension by Stefan Goessner which supports macros. It works really well on my setup.
We can also define macros in the user settings, e.g.
"mdmath.macros": {
"\\vect" "{\\mathbf{\\boldsymbol{{#1}}}}"
}
or in a separate json file as follows.
"mdmath.macroFile": "/path/to/macros.json"

Prettier Code Formatter for VS code fails with 'No loader specified for extension ".cjs"'

In VS Code, When I select Format Document With... then choose Prettier - Code Formatter, I get the following error:
Command 'Format Document' resulted in an error (No loader specified for extension ".cjs", so searchPlaces item ".prettierrc.cjs" is invalid)
From what I can gather this has something to do with underlying TypeScript in VS Code not having a loader available for .cjs files and Prettier searching for prettierrc.cjs but I can't quite see how that all fits together, or how to work around it.
Has anyone else encountered, found a work around or solved this or a similar issue in VS Code?
I tried disabling the Prettier VS Code extension and enabling it again and that fixed the issue for me.
Credits #NikolajDamLarsen

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.

Visual Code, Fold Comments

Visual Studio Code 1.24.1
While I was working on something today. It prompted me to do an update which I did (Update was to 1.24.1). I'm not sure if I hit a shortcut accidentally at about this same time or if this was caused by the update.
But I seem to no longer be able to use comments as a fold point.
However again, I'm not sure if I hit a shortcut of some sort, or if this was caused by the patch.
and my googlefu did not help me find an answer for visual studio code. Found many old topics about visual studio (prof not code) and for other editors. but couldn't find a topic specific to VSC.
I liked to use comments as fold points \ section headers.
Example of comments I used to use as fold points
Is this a bug in VSC 1.24.1 or did I hit a shortcut I'm unaware of?
VS Code has a method of marking the start and end of a region that can be folded and expanded easily. And also provide it a name/short description that'll always be visible.
I've tried this on Javascript code and I believe it'll work on any language in VS Code. And you can have anything in between the start and end of region - comments, few lines or code, entire functions.
In the absence of proper code folding, this is a pretty good work around that'll work for all languages on VS Code.
//#region <REGION NAME>
< You can put any type of code in here - some lines of code, functions or single or multi-line comments.
//#endregion
For python, simply omit the // in the demarcation lines, since # is a valid comment indicator:
#region <REGION NAME>
...
# any code goes here, including multiple comment lines
...
#endregion
A kind of hack I found for react is using empty tags for example
<>
{/*
Your commented code
*/}
</>
This allows you to fold the commented code between the empty tags. You can go a step further and add regions as mentioned in the other answer to add some kind of description to it

Prevent Intellisense from inserting semicolons in VS 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.