vscode-yaml icon indicating copy to clipboard operation
vscode-yaml copied to clipboard

AutoComplete not showing up in .yaml (but in .json with same json schema file!)

Open kamok opened this issue 3 years ago • 12 comments

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!

kamok avatar Apr 26 '21 21:04 kamok

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?

JPinkney avatar Apr 26 '21 22:04 JPinkney

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.

kamok avatar Apr 26 '21 23:04 kamok

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

JPinkney avatar Apr 27 '21 00:04 JPinkney

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.

kamok avatar Apr 27 '21 00:04 kamok

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!

JPinkney avatar Apr 27 '21 14:04 JPinkney

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.

kamok avatar Apr 27 '21 14:04 kamok

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.

kamok avatar May 14 '21 15:05 kamok

Did you fork the repository before you cloned it? It looks like you're trying to push directly to upstream

JPinkney avatar May 14 '21 15:05 JPinkney

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.

kamok avatar May 14 '21 16:05 kamok

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!

JPinkney avatar May 17 '21 13:05 JPinkney

Thank you I will get to work.

kamok avatar May 17 '21 14:05 kamok

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.

dean-vanderwath-lab3 avatar Nov 08 '21 03:11 dean-vanderwath-lab3