Yaml Support for Kubernetes in VSCode - kubernetes

I am trying to use VS code editor for creating kubernetes yaml files, by some reason, vscode is not showing auto-complete commands or space in my yaml files even though I have installed Yaml Support by Redhat extension and configured yaml.schema file as per below:
{
"yaml.schemas": {
"Kubernetes": "*.yaml"
}
}
Any help would be appreciated.
Thanks

I don't know why your config does not work. Here's mine:
{
"workbench.colorTheme": "Default Light+",
"workbench.startupEditor": "none",
"editor.cursorSurroundingLines": 5,
"window.zoomLevel": 3,
"redhat.telemetry.enabled": false,
"yaml.schemas": {
"Kubernetes": [
"deploy*.yaml"
],
},
}
This snippet works for me which currently selects deploy*.yaml files.
I added rest of settings just to show overall structure. Only yaml.schemas part matters, of course.
To access this file one should press command+shift+P (macOS), and type >user settings json in the search. To reload vscode one should press command+shift+P and then type >reload window there.
I tried to match *.yaml and it works as well.
Hopefully this answer will help some vscode newbie like me. It's not very obvious how to proceed with yaml configuration after initial install.

Fix This Problem On The Vscode Step by Step
Step 1 : install yaml plugin on the vscode
Step 2 : Edit this path vscode file>prefrences>settings>Extention>YAML
Step 3 : After Click Yaml on the right side find and edit YAML: Custom Tag Edit in setings.json
Step 4 : Append This lines in File Settings.json
"https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.22.4-standalone-strict/all.json": ["/*.yaml","/*.yml"]
Step 5 : Final Reload vscode You can use Ctrl+Shift+p and search Reload Window On The Vscode

try this.
{
"yaml.schemas": {
"Kubernetes": "*.yaml"
},
"redhat.telemetry.enabled": true
}

you can try it.
"yaml.schemas": {
"http://www.schemastore.org/json/composer": ["/*"],
"kubernetes": ["/*.yaml"]
},

Related

VSCode Error with Schema for Azure DevOps Yaml extension

I am trying to work with my usersettings.json file and make sure that on a particular file type it uses the Azure DevOps Schema, for syntax checking. Yet I keep getting this error when loading in a .yml file:
Problems loading reference 'schemaservice://combinedschema/azure-devops': Unable to load schema from 'schemaservice://combinedschema/azure-devops': No content (note for my setup .yaml is reserved for kubernetes yaml)
I was wondering if anyone else had come across this problem before, I have been following this repo for setting up my user settings: https://github.com/Microsoft/azure-pipelines-vscode and this document: https://marketplace.visualstudio.com/items?itemName=ms-azure-devops.azure-pipelines
Here is my usersettings.json file
{
"redhat.telemetry.enabled": true,
"vs-kubernetes": {
"vscode-kubernetes.helm-path.windows": "C:\\Users\\Jason\\.vs-kubernetes\\tools\\helm\\windows-amd64\\helm.exe",
"vscode-kubernetes.minikube-path.windows": "C:\\Users\\Jason\\.vs-kubernetes\\tools\\minikube\\windows-amd64\\minikube.exe"
},
"files.associations": {
"**/ci/*.yml": "azure-pipelines"
},
"[azure-pipelines]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
}
I figured out what was wrong in the end for some reason in my settings VSCode can not resolve: "http://www.schemastore.org/json/composer"
Now this was not originally appearing in my usersettings.json but was being used what VSCode Was referring to was a hidden file in my project area called .vscode once I deleted that it then brought up the right file with the json schema.
I have since changed my settings to use the camel schema.
Here are my settings also with these settings you can now diffrentiate between an azure devops yaml file and kuberneted yaml file. As long as you have on the end of your kubernetes file _kube.yaml This will then let vscode know im working on a kubernetes file use the relevant schema.
{
"redhat.telemetry.enabled": true,
"yaml.schemas": {
"https://raw.githubusercontent.com/microsoft/azure-pipelines-vscode/master/service-schema.json": "*.yml",
// "http://www.schemastore.org/json/composer": ["/*"],
"https://raw.githubusercontent.com/apache/camel/main/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/camel-yaml-dsl.json" : "/_kube*.yaml",
"kubernetes": ["/*.yaml"]
},
"vs-kubernetes": {
"vscode-kubernetes.helm-path.windows": "C:\\Users\\Jason\\.vs-kubernetes\\tools\\helm\\windows-amd64\\helm.exe",
"vscode-kubernetes.minikube-path.windows": "C:\\Users\\Jason\\.vs-kubernetes\\tools\\minikube\\windows-amd64\\minikube.exe"
},
"files.associations": {
"**/ci/*.yml": "azure-pipelines"
},
"[azure-pipelines]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"yaml.schemaStore.url": "http://www.schemastore.org/api/json/catalog.json",
}

LaTeX Workshop does'nt work well (Recipe terminated with error.)

Problem
I fail to build the LaTeX document on the VScode with LaTeX Workshop.
More preciously, ctrl + S can save the document but can't build the pdf. VScode warns "Recipe terminated with error".
The thing is that I was able to build the LaTeX documents earlier, but yesterday it abruptly didn't work well. Although I didn't change any option about LaTeX, I changed some settings about Python. For example, I uninstalled Anaconda and tried to create virtual environment of python with pipenv. However, I don't think those change are related to this problem...
settings.json
settings.json is as following.
{
"editor.suggest.snippetsPreventQuickSuggestions": false,
// ---------- LaTeX Workshop ----------
"latex-workshop.intellisense.package.enabled": true,
"latex-workshop.message.log.show": true,
"latex-workshop.message.badbox.show": true,
"latex-workshop.latex.autoClean.run": "onBuilt",
"latex-workshop.view.pdf.viewer": "tab",
"latex-workshop.latex.recipes": [{
"name": "ptex2pdf",
"tools": [
"ptex2pdf"
]
}],
"latex-workshop.latex.tools": [{
"name": "ptex2pdf",
"command": "ptex2pdf",
"args": [
"-l",
"-ot",
"-kanji=utf8 -synctex=1 -interaction=nonstopmode",
"%DOC%"
]
}],
"latex-workshop.message.latexlog.exclude":["(Font shape `(JY1|JT1|JY2|JT2)(/.*)(sl|it|sc)'.*|Some font shapes were not available.*)"]
}
Additional information
Since I hadn't used Workspace of VScode yet, but yesterday I started to use that. Since I thought it
may be the reason of the problem, now I stop using the worspace, but the situation doesn't change.
Furthermore, if I run on the cmd on VScode,
platex hoge.tex
dvipdfmx hoge.dvi
the pdf was outputted successfully.
environment
Windows10 Home
VScode 1.49.0
LaTeX Workshop 8.13.2

How do I get flake8 to reliably ignore rules in VS Code?

Two things that annoy me. First is the warning Flake8 gives me when I type more than 80 characters on a line. Second is the warnings I get when I haven't yet used a module name that I imported. I've looked at all the documentation on using Flake8 in the terminal. No use.
flake8 --ignore=E402
flake8 --max-line-length=120
This doesn't work. At least VS Code doesn't show any effect.
Add your arguments to your USER SETTINGS json file like this:
"python.linting.flake8Args": [
"--max-line-length=120",
"--ignore=E402,F841,F401,E302,E305",
],
note that flake8 uses
"python.linting.flake8Args": [
whereas black seems to use:
"python.formatting.blackArgs": [
if you're using both (or toggling) these settings maybe helpful:
{
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
"python.formatting.provider": "black",
"python.formatting.blackArgs": [
"--line-length",
"120"
],
"python.linting.flake8Args": [
"--max-line-length=120",
"--ignore=E402",
],
"python.pythonPath": "venv/bin/python"
}
In my case (vscode 1.72.2, flake 5.0.4) it only worked by adding:
"flake8.args": [
"--max-line-length=120"
]
in the settings.json
I prefer editing the Workspace settings, namely <root project folder>/.vscode/settings.json, because I store it in version control. This way it is backed up and everyone working on the project will get it.
What was suggested in most of the other answers:
"python.linting.flake8Args": [
"--max-line-length=120",
],
had no effect for me.
I ran into this problem recently. I ran into problems because I was setting the argument to --config flake8.cfg instead of --config=flake8.cfg. Under the hood, vscode puts the CLI argument in quotes. Adding "--config flake8.cfg" to the flake8 command seems to confuse flake8 into thinking that it's looking at a file path and not a CLI argument.
The solution for me was to either set the args as --config=flake8.cfg (with the equals sign) or the args up into separate items in the array:
"python.linting.flake8Args": [
"--config",
"flake8.cfg"
]
The solution proposed by reka18 is great and was no doubt written specifically for the original question.
From a more general stand point, I would advise against using this kind of trick
if you work on a project that has dedicated configuration files.
You are guaranteed to run into incomprehensible configuration conflicts
and will possibly ignore rules that were purposefully enforced by the project.
In this case, you should use the following instead:
assuming the file is named .flake8 and is present at the project's root folder
// .vscode/settings.json
"python.linting.flake8Args": ["--config", ".flake8"],
Using --config .flake8 ensures only this file will be read (See official doc).
So it is important to use this option, even though it is a default value. Otherwise, a custom user configuration in a parent folder could accidentally be used.
To extend (change) the default Flake8 line length I added the following in my VS Code workspace: project.code-workspace:
{
...
"settings": {
"flake8.args": [
"--max-line-length=120",
]
}
}

VSCode single to double quote automatic replace

When I execute a Format Document command on a Vue Component.vue file VSCode replace all single quoted string with double quoted string.
In my specific case this rule conflicts with electron-vue lint configuration that require singlequote.
I don't have prettier extensions installed (no prettier.singleQuote in my setting)
How to customize VSCode to avoid this?
I dont have prettier extension installed, but after reading the possible duplicate answer I've added from scratch in my User Setting (UserSetting.json, Ctrl+, shortcut):
"prettier.singleQuote": true
A part a green warning (Unknown configuration setting) the single quotes are no more replaced.
I suspect that the prettier extension is not visible but is embedded inside the Vetur extension.
Well, like the guy (#user2982122) mentioned but instead of File go to Code -> Preferences -> Settings, then look for Quote, select Prettier and check both boxes
For projects that use .editorconfig file by default. The formatter will ignore the rules in the settings and use the rules in .editorconfig, then you can either:
Remove .editorconfig file, and use your VSCode settings.
Add quote_type = single to the .editorconfig file regarding your file type. You can also set quote_type value to double or auto.
It looks like it is a bug open for this issue: Prettier Bug
None of above solution worked for me.
The only thing that worked was, adding this line of code in package.json:
"prettier": {
"singleQuote": true
},
At the time of writing (June 2022):
please consider that .editorconfig overwrites every other configuration at the end, find the file (most probably on the root of your project), edit it and add the following:
[*]
quote_type = single
From the vuejs/vetur issue page https://github.com/vuejs/vetur/issues/986#
This solution worked for me.
In VSCodes settings.json file add this entry
"vetur.format.defaultFormatterOptions": {
"prettier": {
"singleQuote": true
}
},
Install prettier extension and paste below code in your VSCode settings.json file
"prettier.useEditorConfig": false,
"prettier.singleQuote": true
this will ignore your .editorconfig file setting.
What worked for me was setting up the .prettierrc.json config file. Put it to the root of your project with a sample config like this:
{
"singleQuote": true,
"trailingComma": "all",
"tabWidth": 2,
"semi": true,
"arrowParens": "always"
}
After triggering the Format Document command, all works just as expected.
Side note: What comes as a bonus with this solution is that each team member gets the same formatting outputs thanks to the present config file.
Correct solution :
I add .prettierrc.js file in my main root project
and write
module.exports = {
singleQuote: true
};
For newbies like me:
From the menu Nav bar at the top: Select File -> Preferences -> Settings.
In the search text box, type in Quote
In the filtered list that appears below, look for the gear icon and next to it - "Prettier". Click on check box to enable "Prettier: Single Quote"
I had the same issue in vscode. Just create a .prettierrc file in your root directory and add the following json.
For single quotes add:
{
"singleQuote": true
}
For double quotes add:
{
"singleQuote": false
}
Try one of these solutions
In vscode settings.json file add this entry
"prettier.singleQuote": true
In vscode if you have .editorconfig file, add this line under the root [*] symbol quote_type = single
In vscode if you have .prettierrc file, add this line
{
"singleQuote": true,
"vetur.format.defaultFormatterOptions": {
"prettier": {
"singleQuote": true
}
}
}
quote_type = single
add this inside .editorconfig
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
quote_type = single
As noted by #attdona the Vetur extension includes prettier.
While you can change the prettier settings, as per the accepted answer, you can also change the formatter for specific regions of a vue component.
Here, for example, I've set Vetur to use the vscode-typescript formatter as it uses single quotes by default:
in .prettierrc add
{
"arrowParens": "avoid",
"semi": false,
"singleQuote": true
}
After struggling with the issue I found a useful tool. If you click on the Prettier word in the right lower corner you will get the Output window opened. In that window once you run formatting (in my case it is Alt + Shift + F) you will see all the configurations which prettier will use to format the document. So, we can clearly see that specifying the prettier in the prettier.singleQuote is wrong. It should just be singleQuote. Hence, having the .prettierrc file in my user root folder with the following contents produced the desired result:
{
"trailingComma": "none",
"useEditorConfig": false,
"singleQuote": true
}
Also, make sure that you have the Prettier extension installed.
I'm using typescript, for me it got resolved with checking "Tslint integration" flag under prettier settings (in vscode preferences):
There only solution that worked for me:
and only for Angular Projects:
Just go into your project ".editorconfig" file and paste 'quote_type = single'.
Hope it should work for you as well.
In my case, the problem was in the escaping \ character inside the string:
message = 'Error argument is not an object, it\'s ' + typeof error
Turning on the avoidEscape option and using double quotes for that string solved the problem:
message = "Error argument is not an object, it's " + typeof error
.eslintrc.js
module.exports = {
rules : {
// Other rules...
'quotes' : ['error', 'single', {'avoidEscape' : true}],
}
}
I added file called .prettierrc in my project folder.
File content:
{
"singleQuote": true,
"vetur.format.defaultFormatterOptions": {
"prettier": {
"singleQuote": true
}
}
}
It works for me to check single quote in Prettier as well
tslint.autoFixOnSave as true
You can use this in settings.json
"javascript.preferences.quoteStyle": "single"
Use this extension.
https://marketplace.visualstudio.com/items?itemName=BriteSnow.vscode-toggle-quotes
cmd ' (ctrl ' on win/Linux) will cycle among ' " `
For JSX use:
{"jsxSingleQuote": false}
First, install the Prettier extension. Create a .prettierrc configuration file at the root of your project. And add config like below:
{
"trailingComma": "es5",
"singleQuote": true,
"jsxSingleQuote": true,
"printWidth": 100,
"tabWidth": 2,
"semi": true,
"endOfLine": "auto"
}
Well for me both options solved the issue:
By adding inside the .prettierrc - "singleQuote": true
Or by adding following inside the package.json ->
"prettier": {
"singleQuote": true
}
Though I tried also adding .prettierrc.js and have following
module.exports = {
singleQuote: true
};
This didn't worked.
I had a lot of issues controlling linting and prettier formating. I had rules for eslint on for prettier like
"prettier/prettier": [
"error",
{ "singleQuote": true, "trailingComma": "none" }
],
and rules inside .prettierrc file
{
"tabWidth": 2
}
But my .prettierrc file was not getting processed. My fix was installing prettier as a package on dev dependency. So the solution that worked for me was installing all these packages eslint-config-prettier eslint-plugin-prettier and prettier.
This works for me :
try right click on the current document
and choose "format document with " ,
and choose your own format extension for the document.
:)
If you're using a YAML plugin, it also has a single/double quote option that was tripping me up. Cheers.
"prettier": {
"singleQuote": true
},
This line of code save my hours.

Visual Studio Code Run On Save Extension not running

I installed the Run On Save extension for VS Code. I made a Workspace setting for it, and if I change a file then resave, it does not seem to run. "I run for all files" does not show up in the console or terminal.
When I chose to edit the command configuration in my Workspace settings, it automatically edited the file with the comment "Place your settings in this file to overwrite default and user settings." so it looks like this:
// Place your settings in this file to overwrite default and user settings.
{
"editor.mouseWheelZoom": false,
"emeraldwalk.runonsave": {
"commands": [
{
"match": ".*",
"isAsync": true,
"cmd": "echo 'I run for all files'"
}
]
}
}
I'm new to configuring Workspace settings, so I'm not sure if this is okay or not. I ensured that Run On Save is enabled by selecting it on the command palette.
Here is the site for the extension: https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave
In order to see the console output, you have to be in the Output tab and select the Run On Save option in the dropdown. The extension was created before the integrated terminal existed and hasn't seen a major update in a while.
Regarding the comment that was added to your config:
// Place your settings in this file to overwrite default and user
settings.
is unrelated to this particular extension. It is just vscode letting you know the purpose of the workspace level configuration. It allows you to override a subset of your more global user / default settings. This allows you to keep reasonable default preferences but to customize certain specific things in any given workspace.
Regarding the original RunOnSave extension, feel free to file an issue here https://github.com/emeraldwalk/vscode-runonsave/issues if you have any questions or problems. I would also welcome pull requests if anyone is interested.
I had the exact same issue. I removed that extension and am using this one instead:
https://marketplace.visualstudio.com/items?itemName=wk-j.save-and-run
It is a fork based on RunOnSave. This one works for me when I set its configuration in my user settings and then run the command "Save and Run: Enable".
This one uses the bulit-in powershell terminal.
HTH
In addition to our dear #bingles, I have accidentally discovered that the commands should be added to .vscode/settings.json file instead of .vscode/emeraldwalk.runonsave as said in the plugin documentation
Add it to settings.json and everything should work as expected.
For the extension to work on Workspace you must put the emeraldwalk.runonsave inside settings:
{
"settings": {
"emeraldwalk.runonsave": {
"commands": [
{
"match": ".*",
"isAsync": true,
"cmd": "echo 'I run for all files'"
}
]
}
}
}
A related one:
Previously I used RunOnSave, this time around I used Code Runner.
Code Runner - https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner
Below are it's settings I used:
File: %AppData%\Code\User\keybindings.json
{
{
"key": "ctrl+s",
"command": "code-runner.run"
}
}
File: .vscode\settings.json
{
"code-runner.saveFileBeforeRun": true,
"editor.codeActionsOnSave": [
"code-runner.executorMap"
]
"code-runner.executorMap": {
"javascript": "node a.js"
},
}
If possible, you could use Code Runner with the above settings, or use a similar to the above settings for the RunOnSave.
Note that RunOnSave has its own tab which is time-consuming to switch to another tab.
With Code Runner I can see the output in the Output tab itself which is a very nice thing, saves time.