redhat-developer / yaml-language-server

Language Server for YAML Files
MIT License
1.1k stars 264 forks source link

YAML `---` for "Multiple documents within a single stream" doesn't work [YAML Language Server] #946

Open vorburger opened 11 months ago

vorburger commented 11 months ago

[Originally reported as https://github.com/redhat-developer/vscode-yaml/issues/995, before I understood this really belongs more here.]

I wrote my first trivial JSON schema enola.schema.jsonc, like this:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.enola.dev/json-schema/enola_meta.schema.jsonc",
  "title": "Enola.dev Meta Model",
  "description": "See https://docs.enola.dev",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "name": {
      "type": "string",
      "description": "Short technical name of this Type."
    }
  },
  "required": ["name"]
}

Then I wrote an test.yaml file using that schema, like this:

# yaml-language-server: $schema=enola.schema.jsonc

name: enola.dev/url
doc: enola.md#URL

---
name: enola.dev/id
doc: enola.md#ID

Current Behavior

It does put a "red squiggle" on the first doc: enola.md#URL but not on the second doc: enola.md#ID.

In fact the 2nd name: enola.dev/id doesn't have the "hover" with the descriptionfrom the schema either.

It looks like the YAML --- syntax for "multiple documents within a single stream" isn't supported / doesn't work?

Expected Behavior

I expected it to flag the doc attribute as red in both my URL and ID attributes.

AnhQuanTrl commented 9 months ago

I also encounter the same issue using Neovim. It seems like this is a regression. Multidoc used to work as far as I remember.

ionous commented 5 months ago

this previously resolved issue might be related: #16 ( Multiple YAML documents in single file features work for first section but not the rest ) and there is also this currently open issue #869 ( intellisense completion breaks with multiple documents in a single file )

thieman commented 3 months ago

Is this problem only occurring when using the # yaml-language-server inline directive to specify the schema? I think that's intended behavior in that it only applies to the YAML document (not the entire file) it's a part of. If you copy # yaml-language-server: $schema=enola.schema.jsonc into the second document, do you start seeing autocompletion etc work as expected? It's working that way for me currently in VSCode.

If that's true, this is probably more of a feature request than a bug report, as making the inline directives fallthrough to subsequent documents would probably be a breaking change in a lot of cases. If a single file has multiple distinct types of YAML documents requiring different schemas, fallthrough is probably not what you'd want, as it will cause spurious errors. Maybe there could be additional syntax in the directive to indicate you'd like it to fallthrough to subsequent documents?

AnhQuanTrl commented 3 months ago

@thieman It used to work on my end with multiple # yaml-language-server per YAML document. However, this is no longer the case and the top # yaml-language-server affects the whole file instead of a document.

nikaro commented 3 months ago

It happens to me without using the inline # yaml-language-server directive.

thieman commented 3 months ago

Ah ok, it seems like we have at least two different things being reported here? Please let me know if any of this is wrong.

@vorburger is saying that the current behavior is inline directives only apply to the document, not the file. I am also experiencing this.

@AnhQuanTrl is saying the opposite! That the inline directives apply to the entire file.

@nikaro could you elaborate on your issue, or let us know if it fits into one of the other descriptions?

Could you all please report your version numbers? I'm using the VSCode extension at v1.15.0, which is also using the language server at 1.15.0.

nikaro commented 3 months ago

@thieman sorry i ended up following this issue as its title seemed more aligned with my issue. But it fits more with the comments on this one: https://github.com/redhat-developer/yaml-language-server/issues/869

I'm using Helix editor with yaml-language-server version 1.15.0.

Capture d’écran 2024-08-28 à 15 53 07