yaml-language-server icon indicating copy to clipboard operation
yaml-language-server copied to clipboard

intellisense completion breaks with multiple documents in a single file

Open bcha opened this issue 1 year ago • 6 comments

Describe the bug

It seems like intellisense completion breaks with multiple docs in single file. For example if I'm working with k8s manifests it's very common to have multiple related k8s resources per .yaml file.

Expected Behavior

If I have only one doc per file the completion works perfectly:

image

& I'd expect it to work just fine with multiple docs as well

Current Behavior

...but actually with multiple docs it offers nothing:

image

Environment

  • [ ] Windows
  • [X] Mac
  • [ ] Linux
  • [ ] other (please specify)

bcha avatar Apr 11 '23 05:04 bcha

I get an error on multiple documents in a single file:

Source contains multiple documents; please use YAML.parseAllDocuments()

carderne avatar Jun 20 '23 16:06 carderne

I can not replicate this issue. Can you provide a more complete example?

gorkem avatar Jul 02 '23 21:07 gorkem

So I'm not sure if my issue is related to the original issue, but will add some details.

Basic details

OS: macOS 13.4.1 Environment: Neovim 0.9.1 Installed with: Mason yaml-language-server version: 1.13.0

Settings as reported by Mason:

    ◍ yaml-language-server yamlls
      Language Server for YAML Files.
      
      installed version 1.13.0                                                   
      homepage          https://github.com/redhat-developer/yaml-language-server 
      languages         YAML                                                     
      categories        LSP                                                      
      executables       yaml-language-server                                     
      
      ↓ LSP server configuration schema (press enter to collapse)
        This is a read-only overview of the settings this server accepts. Note that some settings might not apply to neovim.
        
        → redhat.telemetry.enabled         
        → yaml.completion                   default: true
        → yaml.customTags                   default: []
        → yaml.disableAdditionalProperties  default: false
        → yaml.format.bracketSpacing        default: true
        → yaml.format.enable                default: true
        → yaml.format.printWidth            default: 80
        → yaml.format.proseWrap             default: "preserve"
        → yaml.format.singleQuote           default: false
        → yaml.hover                        default: true
        → yaml.maxItemsComputed             default: 5000
        → yaml.schemaStore.enable           default: true
        → yaml.schemaStore.url              default: "https:\/\/www.schemastore.org\/api\/json\/catalog.json"
        → yaml.schemas                      default: {}
        → yaml.trace.server                 default: "off"
        → yaml.validate                     default: true

Example

---
 key: "value"
--- # ---> Here I get the Error
 key: "value"

The Error

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

 key: "value"
---
^
 [MULTIPLE_DOCS]

carderne avatar Jul 03 '23 07:07 carderne

So I'm not sure if my issue is related to the original issue, but will add some details.

Basic details

OS: macOS 13.4.1 Environment: Neovim 0.9.1 Installed with: Mason yaml-language-server version: 1.13.0

Settings as reported by Mason:

    ◍ yaml-language-server yamlls
      Language Server for YAML Files.
      
      installed version 1.13.0                                                   
      homepage          https://github.com/redhat-developer/yaml-language-server 
      languages         YAML                                                     
      categories        LSP                                                      
      executables       yaml-language-server                                     
      
      ↓ LSP server configuration schema (press enter to collapse)
        This is a read-only overview of the settings this server accepts. Note that some settings might not apply to neovim.
        
        → redhat.telemetry.enabled         
        → yaml.completion                   default: true
        → yaml.customTags                   default: []
        → yaml.disableAdditionalProperties  default: false
        → yaml.format.bracketSpacing        default: true
        → yaml.format.enable                default: true
        → yaml.format.printWidth            default: 80
        → yaml.format.proseWrap             default: "preserve"
        → yaml.format.singleQuote           default: false
        → yaml.hover                        default: true
        → yaml.maxItemsComputed             default: 5000
        → yaml.schemaStore.enable           default: true
        → yaml.schemaStore.url              default: "https:\/\/www.schemastore.org\/api\/json\/catalog.json"
        → yaml.schemas                      default: {}
        → yaml.trace.server                 default: "off"
        → yaml.validate                     default: true

Example

---
 key: "value"
--- # ---> Here I get the Error
 key: "value"

The Error

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

 key: "value"
---
^
 [MULTIPLE_DOCS]

I got the same error

tinguyen1107 avatar Apr 05 '24 08:04 tinguyen1107

We got the same in zed-editor with yaml language server too

yodatak avatar Jul 31 '24 09:07 yodatak

ParseAllDocuments() specifically appears on Kubernetes manifests. The error changes when yaml-language-server is configured with a kubernetes glob pattern. https://github.com/redhat-developer/yaml-language-server/blob/main/README.md?plain=1#L115

It will instead show:

Matches multiple schemas when only one must validate. (0)

Despite the workaround: https://github.com/redhat-developer/yaml-language-server/blob/main/src/languageservice/services/yamlValidation.ts#L122-L124

Baarsgaard avatar Aug 16 '24 07:08 Baarsgaard