microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.03k stars 28.79k forks source link

Completion trigger chars don't work with YAML grammar extension languages #230277

Open BoykoAlex opened 5 hours ago

BoykoAlex commented 5 hours ago

The issue is that if trigger chars are all alphabetic chars for instance only a few of them do trigger completion proposal computations. The only trigger char that works is 'y' bringing up 3 completions starting with `y'. If you try 's', 'd', 'm' which also have 3 completion proposals starting with these chars the completion proposal computation (completion provider) is never invoked. Seems random really.

Here the repo demonstrating the issue: https://github.com/BoykoAlex/vscode-extension-samples/tree/triggerchars-yaml-completions. It is a fork of VSCode's extension samples. The completions-sample is the one modified. The branch is triggerchars-yaml-completions

Essentially the extension contributes a new language sample-properties-yaml and the grammar for the language which is really the YAML grammar.

The grammar piece seems to be critical. Snippet from package.json

    "contributes": {
        "languages": [
          {
            "id": "sample-properties-yaml",
            "aliases": [
              "Sample Properties Yaml"
            ],
            "filenamePatterns": [
              "sample*.yml",
              "sample*.yaml",
              "sample*.yml",
              "sample*.yaml"
            ],
            "configuration": "./yaml-support/language-configuration.json"
          }
        ],
        "grammars": [
            {
              "language": "sample-properties-yaml",
              "scopeName": "source.sample-properties-yaml",
              "path": "./yaml-support/sample-properties-yaml.tmLanguage.json"
            }
        ]
    },

The sample-properties-yaml.tmLanguage.json:

{
  "name": "Sample Properties YAML",
  "scopeName": "source.sample-properties-yaml",
  "patterns": [
    {
      "comment": "source.yaml is defined in vscode core",
      "include": "source.yaml"
    }
  ]
}

If the grammar is not defined for the language then completion proposals show up fine for all trigger chars. The syntax highlighting is lost however. Feels, therefore, that the issue is related to the grammar definition of the yaml based language.

RedCMD commented 2 hours ago

You prob need to enable "strings": true under "editor.quickSuggestions" in package.json This will enable completion triggers within strings based on your "wordPattern" in language-configuration.json

"configurationDefaults": {
    "[sample-properties-yaml]": {
        "editor.quickSuggestions": {
            "strings": true
        }
    }
}

idk why some letters work but not others

BoykoAlex commented 1 hour ago

Wow... thanks a lot. I would never be able to guess that :-) It did help and I think this can be resolved now - thanks again!