vscode-yaml
vscode-yaml copied to clipboard
AutoComplete not showing up in .yaml (but in .json with same json schema file!)
Seems like same as this issue from a long time ago: https://github.com/redhat-developer/vscode-yaml/issues/222
I am using the latest version of VSCode and this plugin.
Here's the json schema:
{
"$id": "foo",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"cd": {
"type": "object",
"properties": {
"profile": {
"type": "string",
"enum": [
"multizoneClusterSystem",
"foobar"
]
},
"couchdb": {
"type": "boolean",
"description": "Whether you are using couchdb or not"
}
},
"required": [ "profile" ]
}
},
"required": [
"cd"
]
}
Here's the settings.json entry:
"yaml.schemas": {
"/Users/kamok/Documents/code/yaml-validation-demo/cd.json": [
"*build.yml"
]
},
"json.schemas": [
{
"fileMatch": ["build.json"],
"url": "/cd.json"
}
],
Here's the two .yml and .json files:
{
"cd": {
"profile": "foobar",
"couchdb": false
}
}
cd:
profile: foobar
The .yml file, when I type profile
does not pop up the two options. The json does!
It's working for me. My guess is the json schema path isn't entirely correct and the schemas not being picked up. What OS are you using?
Hi. I'm using MacOS Catalina. I'm not sure why the json schema path
has to do with yaml not autocompleting. Can you explain?
For clarification, yaml is NOT autocompleting. json IS autocompleting. And this is using the same exact config file, and both are in the same folder structure.
Ah I see now. I originally thought it was a schema issue but the problem is that in the json editor it prompts you automatically with the enums after you auto complete profile but in the yaml editor it doesn't (you have to press ctrl+space).
It looks like the json language server automatically adds:
"command": {
"title": "Suggest",
"command": "editor.action.triggerSuggest"
},
into the completionitem when attempting to autocomplete a key. That way you are automatically prompted when an enum is available.
For reference the full response is:
[Trace - 8:08:30 p.m.] Received response 'textDocument/completion - (235)' in 4ms.
Result: {
"items": [
{
"kind": 10,
"label": "profile",
"insertText": "\"profile\": $1",
"insertTextFormat": 2,
"filterText": "\"profile\"",
"documentation": "",
"command": {
"title": "Suggest",
"command": "editor.action.triggerSuggest"
},
"textEdit": {
"range": {
"start": {
"line": 2,
"character": 8
},
"end": {
"line": 2,
"character": 15
}
},
"newText": "\"profile\": $1"
}
},
{
"kind": 10,
"label": "couchdb",
"insertText": "\"couchdb\": $1",
"insertTextFormat": 2,
"filterText": "\"couchdb\"",
"documentation": "Whether you are using couchdb or not",
"command": {
"title": "Suggest",
"command": "editor.action.triggerSuggest"
},
"textEdit": {
"range": {
"start": {
"line": 2,
"character": 8
},
"end": {
"line": 2,
"character": 15
}
},
"newText": "\"couchdb\": $1"
}
}
],
"isIncomplete": false
}
I'll mark this as an enhancement
I guess I'll try to make the contribution during my next Friday's "Your Learning" here at IBM. Thanks for your help. I will probably just search for editor.action.triggerSuggest
in the codebase and see how it is implemented in json and replicate in yaml.
I just took a quick look and here's where it's added in the vscode-json-languageservice: https://github.com/microsoft/vscode-json-languageservice/blob/main/src/services/jsonCompletion.ts#L247 and https://github.com/microsoft/vscode-json-languageservice/blob/main/src/services/jsonCompletion.ts#L271. If you work on it let me know if you need any help!
Thanks that helped a lot. I actually took a look at it just now and couldn't figure it out. It helps that both the JSON and Yaml server uses the same type from VSCode of CompletionItem. God bless TypeScript. Will try to hook up the server with my local vscode this Friday so I can test.
I have a branch open locally, I'm just trying to test it now, I followed the docs on the yaml server but I don't know what I'm doing... https://github.com/redhat-developer/yaml-language-server#developer-support
I also tried to push the the repo, but it doesn't let me. How do people usually contribute?
ERROR: Permission to redhat-developer/yaml-language-server.git denied to kamok.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Did you fork the repository before you cloned it? It looks like you're trying to push directly to upstream
Thanks I never contributed to open source before. I forked, and made a PR. https://github.com/redhat-developer/yaml-language-server/pull/462
I still don't know how to run it though, can to provide more instructions? I followed all the steps in https://github.com/redhat-developer/yaml-language-server#developer-support, but I still don't know how to tell the VSCode to use my version of the plugin that's locally compiled.
To test your changes with VSCode you can follow these steps: https://github.com/redhat-developer/vscode-yaml/blob/master/CONTRIBUTING.md#developing-the-client-and-server-together
Let me know if you have any issues with those and I can help further!
Thank you I will get to work.
Hey all, was there an update on this? YAML just doesn't auto-complete sub definitions where json does I think its related to this.