zed icon indicating copy to clipboard operation
zed copied to clipboard

Multiple documents in one yaml file

Open wisniew opened this issue 1 year ago • 9 comments

Check for existing issues

  • [X] Completed

Describe the bug / provide steps to reproduce it

Having multiple yaml documents in one file, Zed marks the second document all in red with the information:

Source contains multiple documents; please use YAML.parseAllDocuments() at line 169, column 1: (MULTIPLE_DOCS)

Example of yaml file:

metadata:
  name: doc1
---
metadata:
  name: doc2
---
metadata:
  name: doc3

aur/zed-editor 0.135.2-1 on Arch Linux

Environment

Zed: v1.0.0 (Zed) OS: Linux 1.0.0 Memory: 13.7 GiB Architecture: x86_64

If applicable, add mockups / screenshots to help explain present your vision of the feature

image

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

No response

wisniew avatar May 22 '24 13:05 wisniew

This makes working with Kubernetes yaml files pretty difficult ...

MrHaroldA avatar Jul 11 '24 08:07 MrHaroldA

Failing Syntax Highlighting for multiple Yaml documents in one file is also occurring in the mac version, 0.145.1 in my case.

ziermmar avatar Jul 30 '24 07:07 ziermmar

I have this issue too with flux2 yaml file

yodatak avatar Jul 31 '24 09:07 yodatak

Maybe its upstream ? https://github.com/redhat-developer/yaml-language-server/issues/869 https://github.com/redhat-developer/yaml-language-server/issues/946 and from https://github.com/eemeli/yaml

yodatak avatar Jul 31 '24 09:07 yodatak

Not sure to understand but it seem to detect if file is yml or yaml and kubernetes and parse it differently https://github.com/redhat-developer/yaml-language-server/blob/f039273ee5b6974db5ad34b03bb24cfe09b64447/src/languageservice/parser/isKubernetes.ts

The multi document yaml test https://github.com/redhat-developer/yaml-language-server/blob/f039273ee5b6974db5ad34b03bb24cfe09b64447/test/multipleDocuments.test.ts

yodatak avatar Jul 31 '24 10:07 yodatak

Bump. Would be nice this fix this issue, since this makes working on kubernetes ressources diffcult.

h3adex avatar Aug 14 '24 09:08 h3adex

This bug seems fixed.

h3adex avatar Aug 19 '24 09:08 h3adex

I'm still observing this problem on mac Zed 0.149.5

simonccc avatar Aug 22 '24 20:08 simonccc

I'm still observing this problem on mac Zed 0.149.5

me too.

imleafz avatar Aug 23 '24 03:08 imleafz

I'm still observing this problem on mac Zed Preview 0.153.1

weirdo-adam avatar Sep 11 '24 05:09 weirdo-adam

same here, still observing this problem, is there a fix for this?

akashsokik avatar Sep 27 '24 11:09 akashsokik

我仍然在 Mac Zed Preview 0.157.4 上观察到这个问题,有解决办法吗?

weirdo-adam avatar Oct 16 '24 05:10 weirdo-adam

Also observed here.

Zed: v0.160.2 (Zed Preview) OS: Linux Wayland fedora 41 Memory: 62.4 GiB Architecture: x86_64 GPU: NVIDIA GeForce RTX 3080 Ti Laptop GPU || NVIDIA || 560.35.03

tino376dev avatar Nov 01 '24 09:11 tino376dev

Still seeing this issue in today's update, not sure if the bug went away and came back or if h3adex got lucky ^^

Zed: v0.163.2 (Zed Preview) OS: macOS 15.2.0 Memory: 36 GiB Architecture: aarch64

eth0net avatar Nov 22 '24 01:11 eth0net

Issue still present. Zed: v0.166.1

blackmou5e avatar Dec 19 '24 20:12 blackmou5e

this is very annoying any ideas what is the underlying problem?

1hachem avatar Jan 01 '25 14:01 1hachem

this is very annoying any ideas what is the underlying problem?

zed-industries/tree-sitter-yaml properly supports syntax highlighting of multiple documents:

Screenshot 2025-01-01 at 10 13 02

I believe the original reported issue may have been solved (all multi-doc yaml files trigger errors) and now it's a kubernetes yaml file specific issue (kubernetes multi-doc yaml files trigger errors) upstream with redhat-developer/yaml-language-server, perhaps:

  • https://github.com/redhat-developer/yaml-language-server/issues/869
  • https://github.com/redhat-developer/yaml-language-server/issues/946

If you are still experiencing this issue, could you please comment with a minimal yaml file which triggers the issue? Given that I believe this is a yaml-language-server issue I would expect that vscode with the redhat.vscode-yaml extension would show identical behavior.

As a (sad) workaround you can disable yaml-language-server altogether with the following in your settings:

  "languages": {
    "YAML": {
      "enable_language_server": false
    }
  }

notpeter avatar Jan 01 '25 15:01 notpeter

using Zed 0.166.2 on Arch 6.12.7-arch1-1

Here is a sample file

test.yaml

---
person:
  name: John Doe
  age: 30
  occupation: Software Engineer
  skills:
    - Python
    - JavaScript
    - YAML
---
server:
  host: example.com
  port: 8080
  maintenance_mode: false
  features:
    - API
    - WebSockets
    - Static Content

image

1hachem avatar Jan 01 '25 17:01 1hachem

@1hachem When I create this as test.yaml I don't see the schema errors. I assume because your pathing is triggering one of the built-in schema associations -- can you share your pathing and the associated schema url so we can add a inline schema directive an create a fully self-contained reproduction example?

# yaml-language-server: $schema=https://my.url.to/the/schema 

Thanks

notpeter avatar Jan 01 '25 17:01 notpeter

Okay I can't explain it but I am running into this bug and it does not impact every file and I haven't been able to figure out a commonality. I am running into it when writing Kubernetes manifests and it is only showing the error on the second document in some files. It doesn't seem to be related to the detected schema, it does it with or without it defined.

Here is an example:

---
# yaml-language-server: $schema=https://raw.githubusercontent.com/yannh/kubernetes-json-schema/refs/heads/master/v1.31.5/namespace-v1.json
apiVersion: v1
kind: Namespace
metadata:
  name: config
  labels:
    kustomize.toolkit.fluxcd.io/prune: disabled
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/yannh/kubernetes-json-schema/refs/heads/master/v1.31.5/namespace-v1.json
apiVersion: v1
kind: Namespace
metadata:
  name: system
  labels:
    kustomize.toolkit.fluxcd.io/prune: disabled
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/yannh/kubernetes-json-schema/refs/heads/master/v1.31.5/namespace-v1.json
apiVersion: v1
kind: Namespace
metadata:
  name: network
  labels:
    kustomize.toolkit.fluxcd.io/prune: disabled
Image

It seems to do this no matter what the file is named (or if it uses yaml or yml) or how it was created. I can work around it by leaving an empty document in the second position but it still causes the file tree to show an error on the file.

Zed 0.169.2
MacOS 15.2 (24C101)
Apple M2
16GB Memory

Let me know if there is any other information that would be helpful!

wazoo avatar Jan 18 '25 04:01 wazoo

  1. @wazoo Can you provide the filename you are using for this?I believe the pathing you are using are causing these documents to be captured by the "Kubernetes" glob was causes yaml-language-server to handles these documents differently than by default. When I create your example as a.yml I do not see errors and validation/autocomplete works as expected.

  2. I wonder if as a workaround we can defeat this by altering the Kubernetes glob and explicitly including per-document schemas as you have above. Can you try this and see if it helps (untested).

  "lsp": {
    "yaml-language-server": {
      "settings": {
        "yaml": {
          "schemas": {
            "Kubernetes": []
          }
        }
      }
    }
  }

notpeter avatar Jan 18 '25 17:01 notpeter

Oh interesting! The file is called bootstrap.yaml but I also have one called cluster-base.yaml that has the same behavior (different manifests, same folder).

Currently I have this same issues on the following files/paths (metal is the name of the cluster):

  • clusters/metal/base/namespaces.yaml
  • clusters/metal/base/config.yaml
  • clusters/metal/bootstrap.yaml (the file from the previous comment)
  • clusters/metal/cluster-system.yaml

I also created a copy of the bootstrap file and tried the following paths:

  • test/metal/bootstrap.yaml
  • totallynotclusters/metal/bootstrap.yaml
  • totallynotclusters/bootstrap.yaml
  • totallynotclusters/zerp.yaml
  • bootstrap.yaml
  • zerp.yaml

None of those paths worked either, I wasn't able to get the error to disappear no matter what the name of the file is or what the path is. I also tried opening it in a new workspace (zed -n zerp.yaml), same result.

I tried adding that snipped above and it didn't seem to change anything, here is my whole zed config in case I missed something, I am fairly new to Zed.

wazoo avatar Jan 18 '25 20:01 wazoo

@wazoo I was able to reproduce by installing the Docker Compose Zed Extension. Uninstall that extension and you issue should go away.

  • See: https://github.com/eth0net/zed-docker-compose/issues/2

notpeter avatar Jan 24 '25 17:01 notpeter

I forgot to come back and comment that disabling that zed extension did fix it for me.

wazoo avatar Apr 15 '25 22:04 wazoo