VSCode Error with Schema for Azure DevOps Yaml extension - visual-studio-code

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",
}

Related

Yaml Support for Kubernetes in VSCode

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"]
},

Requiring config.js file in VSCode extension with absolute path (e.g. "C:\...") does not work

I am developing the Argdown VSCode extension. The Argdown parser can be configured using either argdown.config.json files or argdown.config.js files exporting a config object. Using Javascript files is the easiest way to allow users to add custom plugins to the Argdown parser.
If the user tells the parser to use a Javascript file, the file is loaded using import-fresh, (which uses node's require, but deletes the cached version.
Using the Argdown commandline tool (#argdown/cli) this works fine, but in the VSCode extension the module of the config file can not be found. The extension is using absolute file paths to require the config module (e.g. "C:\Users\my-username\projects\my-argdown-project\argdown.config.js"). These paths work with import-fresh outside of the VScode extension.
Is there a security restriction for VSCode extensions that does not allow to require modules with absolute file paths? Or is there some other reason why this does not work?
This was not related to VSCode. The problem was caused by bundling up import-fresh with webpack. I thought that webpack would ignore dynamic imports, but it did not.
I was lucky: Since last month, webpack supports "magic comments" for require (not only for import). So I can use:
require(/* webpackIgnore: true */ file);
You have to activate magic comments support in your webpack config:
module.exports = {
parser: {
javascript: {
commonjsMagicComments: true,
},
},
}
Now the next question is how to add the magic comments to the import-fresh package. For that I used the string-replace-loader:
module.exports = {
module: {
rules: {
{
enforce: "pre",
test: /import-fresh[\/\\]index\.js/,
loader: "string-replace-loader",
options: {
search:
"return parent === undefined ? require(filePath) : parent.require(filePath);",
replace:
"return parent === undefined ? require(/* webpackIgnore: true */ filePath) : parent.require(/* webpackIgnore: true */ filePath);",
},
},
}
}
}
After that, I could load the argdown.config.js files again, even after bundling everything with webpack.

file copy on save or upload in vs code

I work frequently providing custom java script solutions to SharePoint. The annoying part at the moment is that either I need to setup a watcher to check file changes and overwrite it in the directory where the files will be in SharePoint or I just move then manually. Is there anyway we can setup something with a config file, like it is with the watch tsc compiler.
All I want is, for example to run robocopy when I save a file.
Or even just overwrite the same file specified location, preferable not dependent on extensions.
Thank you all.
For those wondering. I was able to achieve it with the simplest way I can think of: by using fs.watch or node-watch package.
created a js file with the code below to watch file changes in the src dir and act depending on the event.
watch.js:
//if you are using fs:
//var fs = require('fs');
//
var watch = require('node-watch');
//fs.watch if using the node fs.
watch('./src/',{recursive: true}, async function(evt, name) {
if (evt == 'remove') {
// on delete runs rest call to delete the file
}
if (evt == 'update') {
// on create or modify runs rest to upload the file
}
}
with that you can either run the cmd "node watch.js"
or create a task to run on folderopen.
./.vs_code/tasks.json
{
"type": "npm",
"script": "watch",
"label": "wathever label you want",
"isBackground": true,
"runOptions": {
"runOn": "folderOpen"
}
}
package.json:
"scripts": {
"watch": "node watch.js"
}
For the task to run on folderopen you also need to allow it in the folder. you can search on the command pallete (ctrl+shift+p), "Tasks:Manage Automatic Tasks in Folder" to enable it.

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.

Meteor typescript complaining about missing doctype in vscode

VSCode is complaining about missing DOCTYPE on the html files. Meteor build system automatically adds file types and having them causes build errors. How do I make vscode to ignore missing doctype on html files?
Error I get for this.
Doctype must be declared first.
you need to create a .htmlhintrc in your root folder
you can go to http://htmlhint.com/ and setup the rules that are convient to you and create the .htmlhintrc
here is an example with "doctype-first": false,, which would ignore the error you're receiving, if that's your goal.
{
"tagname-lowercase": true,
"attr-lowercase": false,
"attr-value-double-quotes": true,
"doctype-first": false,
"tag-pair": true,
"spec-char-escape": true,
"id-unique": true,
"src-not-empty": true,
"attr-no-duplication": true,
"title-require": true
}
Go to your VScode Preferences > Settings > HTML-Hint and add this:
"htmlhint.options": {
"doctype-first": false
}