redhat-developer / yaml-language-server

Language Server for YAML Files
MIT License
1.05k stars 257 forks source link

yaml.schemaStore.enable default? #591

Open kaihendry opened 2 years ago

kaihendry commented 2 years ago

Summary

It does clear to me after scanning https://github.com/redhat-developer/yaml-language-server/blob/main/README.md whether yaml.schemaStore.enable is enabled by default or not. How does one find out?

evidolob commented 2 years ago

Yes, it is enabled by default.

kaihendry commented 2 years ago

How do I verify that? My goal is to how validation whilst editing Cloudformation or Serverless YAML https://github.com/kaihendry/days/blob/main/template.yml

Do I need to explicitly load the schema or can I expect it to download it automatically?

evidolob commented 2 years ago

Which editor do you use?

kaihendry commented 2 years ago

neovim and I load your yamlls via https://github.com/williamboman/nvim-lsp-installer

kaihendry commented 2 years ago

For example if I edit https://raw.githubusercontent.com/kaihendry/days/main/template.yml can I expect it to download https://raw.githubusercontent.com/awslabs/goformation/master/schema/sam.schema.json to validate it?

evidolob commented 2 years ago

No, as sam.schema.json defined in json schema store as:

{
      "name": "AWS CloudFormation Serverless Application Model (SAM)",
      "description": "The AWS Serverless Application Model (AWS SAM, previously known as Project Flourish) extends AWS CloudFormation to provide a simplified way of defining the Amazon API Gateway APIs, AWS Lambda functions, and Amazon DynamoDB tables needed by your serverless application.",
      "fileMatch": [
        "serverless.template",
        "*.sam.json",
        "*.sam.yml",
        "*.sam.yaml",
        "sam.json",
        "sam.yml",
        "sam.yaml"
      ],
      "url": "https://raw.githubusercontent.com/awslabs/goformation/v5.2.11/schema/sam.schema.json"
    },

So, yaml-ls will automatically download and use schema only if your file name match file pattern defined in fileMatch section. Or you can set up yaml-ls to use sam.schema.json for you file with schemas-settings

kaihendry commented 2 years ago

If you sam init, you will invariably have a default template.yaml file from https://github.com/aws/aws-sam-cli-app-templates/blob/master/nodejs12.x/cookiecutter-aws-sam-hello-nodejs/%7B%7Bcookiecutter.project_name%7D%7D/template.yaml not a sam.yaml.

If you rename the file, you'll get issues:

(ins)[hendry@t14s sam-app]$ mv template.yaml sam.yaml
(ins)[hendry@t14s sam-app]$ sam package
Error: Template file not found at /tmp/s/sam-app/template.yml

Sidenote I also noticed whilst loading a file it says Architectures is not allowed, so the schema is wrong?