VS Code updateImportsOnFileMove setting works only with JS / TS - visual-studio-code

Is it possible to instruct VS Code to apply updateImportsOnFileMove setting to all file types, especially to JSON files? Currently I can do it only for JS / TS files and I didn't find anything in VS Code docs or anywhere else about other file types.
Here's my jsconfig.json:
"compilerOptions": {
"baseUrl": "src"
},
"include": ["src/**/*"],
"javascript.updateImportsOnFileMove.enabled": "prompt"
}
So with this setting, only after I rename or move JS file I get the popup asking whether to update imports. For JSON's and other types nothing happens, and it's a quite common thing to move JSON's around

Related

VSCode - clangd extension does not format/lint on save

I am using VSCode with the clangd extension for C++ development (through Remote SSH extension). I have my .clang-format and .clang-tidy files with the rules I want to enforce. If I format the code manually (either Ctrl-Alt-F or right click -> Format document) the code gets formatted without any issues. Same if I manually go for the clang-tidy suggested fixes (Ctrl-.). Instead, if I save, nothing happens.
These are my settings overrides for C++. I tried moving them inside the different levels (User, Remote, Workspace) but there is no difference.
"[cpp]": {
"editor.codeActionsOnSave": {
"source.fixAll": true,
},
"editor.formatOnSave": true,
"editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd"
}
The same rules for ESLint or rustfmt work with no issues.
I investigated the quick-fix issue a bit, and found that "editor.codeActionsOnSave": { "source.fixAll": true } relies on a new Language Server Protocol (LSP) enhancement added in LSP 3.17 (code actions with type source.fixAll).
Clangd does not currently support this, but it seems to me like it shouldn't be too difficult to add support for it, as clangd already classifies quick-fixes based on whether they're suitable for being applied automatically (e.g. Select All --> "Auto Fix..." makes use of this).
I filed https://github.com/clangd/clangd/issues/1446 with some more details.

How to make Quokka.js Untitled file to be ignored by Eslint?

I have a JS project with strict ESLint rules and "eslint.run": "onType" setting. I would like to ignore new Quokka.js Untitled editors, which are just a playground and I do not want to bother with clean syntax there. Is there any way how to disable VS Code ESLint for Quokka Untitled editors?
A possible workaround could be to automatically add a line /* eslint-disable */ to every Quokka.js New JavaScript File, but I also do not know if it's possible. (Maybe by a Quokka.js plugin, but that's a last option due to complexity.)
in your eslintrc.json add
"files": [
{
"patterns": "**/*()" // For Quokka files -> dont have a valid file extension
}
],

Creating a new editor.tokenColorCustomizations color Scope

I was changing the colors of the VS Code UI using editor.tokenColorCustomizations, when I noticed that some elements share the same scopes (which results in the scopes sharing the same color no matter what).
What I would like to know, is if there is a way to create a new scope, and asign a specific keyword to it?
For example, I would like to add a customized local scope for "Lua".
Here's an example of "local" and "nil" sharing the same scopes:
local
nil
Thank you for your time
Grammar Contribution
What you want to do is Contribute a Grammar using, VSCode provided, contribution points. The grammar contribution point is: contributes.grammars
Contribution points are part of the VS-Code Extension Manifest.
The VS-Code Extension Manifest is a package.json located in the Root Directory of a VS-Code Extension, or Theme. You cannot contribute Grammars from a ./.vscode/settings.json file.
Defining a Grammar in the Extension Manifest
The type of contribution you will be making in this case looks like:
"grammars": []
Here's an Example of a Grammar Being Defined in a VS-Code Extension's Manifest
/*
Grammars are defined in the Extension Manifest (package.json),
inside of the contributions property.
*/
{
"name": "language-latex",
"description": "LaTex Language Support",
"version": "0.0.1",
"publisher": "someone",
"engines": {
"vscode": "0.10.x"
},
"categories": ["Programming Languages", "Snippets"],
"contributes": {
"languages": [
{
"id": "latex",
"aliases": ["LaTeX", "latex"],
"extensions": [".tex"]
}
],
"grammars": [
{
"language": "latex",
"scopeName": "text.tex.latex",
"path": "./syntaxes/latex.tmLanguage.json"
}
],
"snippets": [
{
"language": "latex",
"path": "./snippets/snippets.json"
}
]
}
}
Originally authored as part of a contribution example # VSCode's URL: https://code.visualstudio.com/api/references/extension-manifest#combining-extension-contributions
Notice how the Language is defined in the Manifest? This is because this example is defining the Language Latex. It sounds like you want to contribute a Grammar on top of a per-exsisting language, in that case you probably will not need to define a new language. I posted three links to Official VSCode documentation at the bottom of this answer. You will need to read the three links so you can decide exactly what your extension will need. How your Extension Manifest is filled out will be contingent on the grammar you want to define. This probably sounds complicated, but once you get the hang of it, you will find it is a breeze.
Note: Lots of the Advanced VSCode features, like themes, extensions, contributions, tasks, configuring a debugger (things you can't just set a boolean value for in the settings.json file), use the same type of methods for using the features. For example, to create a theme, you also contribute the theme, which means once you learn how to contribute a grammar, you will know how to create a theme as well. Visit the contribution Link below to learn more (there's approx 20 different contribution types to read about).
As far as the Grammars section goes, you will need to provide 3 specific values, by assigning them each to the right property:
grammars.language property
grammars.scopeName property
grammars.pathname property
The path will use a json file that looks like this:
"./syntaxes/<Your-language>.tmLanguage.json"
It is a TextMate file converted to a JSON format, and can be located in your VSCode's file, or in the VSCode repository (search through the VSCode repository. It should popup as you are typing it.)
Here is a Link to the VSCode Repository
For more information about Grammar Contributions visit this link: https://code.visualstudio.com/api/references/contribution-points#grammar-example
For more information about Contributions in general visit this link: https://code.visualstudio.com/api/references/contribution-points
For more information about the VSCode Extension Manifest visit this link: https://code.visualstudio.com/api/references/extension-manifest#combining-extension-contributions
Any questions regarding this answer, should be asked in the comments section that belongs to this answer.
(Will edit & delete this line, and the line above June 21st # 11:59pm UTC)

VSCode Auto Import inconsistency

I am working in a JS project and having difficulties with using the Auto Import feature. The function that I want to have automatically imported is located at "../utils/htmlDOMFuncs" and is named setSelectedVisit. If I start typing the name of the function, I don't get any kind of autocomplete. If I then open another file in my project that does already have something imported from "../utils/htmlDOMFuncs", then I do see the function name in my autocomplete suggestions. However, upon first hitting tab, the function is not added as an import to the top of the current file. If I then hit backspace and re-type the rest of the function name, I do then see the additional tooltip showing information about the function and where it will be auto imported from. Is this the correct behavior?
A few images to illustrate.
- Typing into file, no other files opened
- With another file opened that already imports the module
- After having used the autocomplete, then deleting and re-typing, I see the Auto Import
You likely need to create a jsconfig.json file at the root of your workspace with the contents:
{
"compilerOptions": {
"target": "ES6"
},
"exclude": [
"node_modules",
"**/node_modules/*"
]
}
This file tells VS Code to treat all js files in your workspace as part of the same project

Set .history folder as ignored by intellisense

I need to ignore .history folder from intellisense.
Now it looks like this when I start typing Focus:
As you can see intellisense will offer me every Identical class found in .history folder and this is very very confusing (and find correct one).
I try find something in vscode settings, and on editor site but no success.
.history folder is ignored from git, display in explorer, and tslint:
"files.exclude": {
"**/.history": true ...
},
"files.watcherExclude": {
"**/.history/**": true ...
},
"tslint.exclude": ["**/.history/**"] ...
How to achieve ignore .history from intellisense?
Next part is based on the answer from Matt
An important assumption:
Visual Studio Code itself does not contain automatic import and you need an extension for it.
Solution:
I am using extension Auto Import (steoates.autoimport) which contains the setting autoimport.filesToScan. I changed default value from "**/*.{ts,tsx}" to "{src,e2e,node_modules}/**/*.{ts,tsx}" and now everything work as I expected.
Those suggestions are coming whatever extension you have installed that is providing auto-import functionality. Please check to see if that extension has its own exclude setting that you also need to configure
In your settings.json, you could add this:
"autoimport.filesToScan": "./index.{ts,tsx} ./App.{ts,tsx} ./src/**.*.{ts,tsx}"
Or, if you prefer:
"autoimport.filesToScan": "./{index,App,src/**}.{ts,tsx}"