dense-analysis / ale

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
BSD 2-Clause "Simplified" License
13.57k stars 1.44k forks source link

yaml-language-server completion & validation not working #4569

Open pbnj opened 1 year ago

pbnj commented 1 year ago

Information

VIM version

:version
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Feb  7 2023 12:17:42)
macOS version - arm64

Operating System: macOS 13.4.1

What went wrong

  1. Completion is not working. Create an empty .github/workflows/test.yml file and invoke omnicomplete <C-x><C-o>. Expected relevant suggestions, like on and jobs, but nothing happens. :ALEInfo shows LSP error (Errors for yaml-language-server) Request textDocument/completion failed with message: Cannot read properties of undefined (reading 'length')

  2. Validation against JSON schema is not working. Create the following .github/workflows/test.yml file:

    ---
    on
    jobs

    Expected ALE to show errors on lines 2 & 3, but nothing happens.

Debugging Attempts

  1. I tried to rule out user (mis)configuration issues by defining

    let b:ale_yaml_ls_config = {'yaml': {'schemaStore': { 'enable': v:true, 'url': 'https://www.schemastore.org/json/' }, 'completion': v:true, 'format': { 'enable': v:true }, 'validate': v:true } }
  2. I tried to rule out yaml LSP issues by testing a different lsp client. yaml-language-server provided completion and validation without issues using yegappan/lsp client with this LSP configuration:

    call LspAddServer([#{
    \    name: 'yaml-language-server',
    \    filetype: ['yaml'],
    \    path: '/opt/homebrew/bin/yaml-language-server',
    \    args: ['--stdio'],
    \  }])

Reproducing the bug

  1. Create .github/workflows/test.yaml file
  2. Type invalid yaml syntax, like:

    ---
    f
    o
    o

    or invalid GitHub Workflow definition, like:

    ---
    on
    jobs

No completion suggestions provided and no errors shown.

:ALEInfo

Expand Current Filetype: yaml Available Linters: ['actionlint', 'circleci', 'gitlablint', 'yaml-language-server', 'spectral', 'swaglint', 'yamllint'] Enabled Linters: ['yaml-language-server', 'spectral', 'yamllint'] Ignored Linters: [] Suggested Fixers: 'prettier' - Apply prettier to a file. 'remove_trailing_lines' - Remove all blank lines at the end of a file. 'trim_whitespace' - Remove all trailing whitespace characters at the end of every line. 'yamlfix' - Fix yaml files with yamlfix. Linter Variables: let g:ale_yaml_ls_config = {} let b:ale_yaml_ls_config = {'yaml': {'validate': v:true, 'format': {'enable': v:true}, 'completion': v:true, 'schemaStore': {'url': 'https://www.schemastore.org/json/', 'enable': v:true}}} let g:ale_yaml_ls_executable = 'yaml-language-server' let g:ale_yaml_ls_use_global = 0 let g:ale_yaml_spectral_executable = 'spectral' let g:ale_yaml_spectral_use_global = 0 let g:ale_yaml_yamllint_executable = 'yamllint' let g:ale_yaml_yamllint_options = '' Global Variables: let g:ale_cache_executable_check_failures = v:null let g:ale_change_sign_column_color = 0 let g:ale_command_wrapper = '' let g:ale_completion_delay = 100 let g:ale_completion_enabled = 0 let g:ale_completion_max_suggestions = 50 let g:ale_disable_lsp = 0 let g:ale_echo_cursor = 1 let g:ale_echo_msg_error_str = 'Error' let g:ale_echo_msg_format = '%code: %%s' let g:ale_echo_msg_info_str = 'Info' let g:ale_echo_msg_warning_str = 'Warning' let g:ale_enabled = 1 let g:ale_fix_on_save = 1 let g:ale_fixers = {'*': ['remove_trailing_lines', 'trim_whitespace']} let b:ale_fixers = ['prettier'] let g:ale_history_enabled = 1 let g:ale_history_log_output = 1 let g:ale_keep_list_window_open = 0 let g:ale_lint_delay = 200 let g:ale_lint_on_enter = 1 let g:ale_lint_on_filetype_changed = 1 let g:ale_lint_on_insert_leave = 1 let g:ale_lint_on_save = 1 let g:ale_lint_on_text_changed = 'normal' let g:ale_linter_aliases = {} let g:ale_linters = {} let g:ale_linters_explicit = 0 let g:ale_linters_ignore = {} let g:ale_list_vertical = 0 let g:ale_list_window_size = 10 let g:ale_loclist_msg_format = '%code: %%s' let g:ale_max_buffer_history_size = 20 let g:ale_max_signs = -1 let g:ale_maximum_file_size = v:null let g:ale_open_list = 0 let g:ale_pattern_options = v:null let g:ale_pattern_options_enabled = v:null let g:ale_root = {} let g:ale_set_balloons = 0 let g:ale_set_highlights = 1 let g:ale_set_loclist = 1 let g:ale_set_quickfix = 0 let g:ale_set_signs = 1 let g:ale_sign_column_always = 0 let g:ale_sign_error = '>>' let g:ale_sign_info = '--' let g:ale_sign_offset = 1000000 let g:ale_sign_style_error = '>>' let g:ale_sign_style_warning = '--' let g:ale_sign_warning = '--' let g:ale_sign_highlight_linenrs = 0 let g:ale_statusline_format = v:null let g:ale_type_map = {} let g:ale_use_neovim_diagnostics_api = 0 let g:ale_use_global_executables = v:null let g:ale_virtualtext_cursor = 0 let g:ale_warn_about_trailing_blank_lines = 1 let g:ale_warn_about_trailing_whitespace = 1 LSP Error Messages: (Errors for yaml-language-server) Request textDocument/completion failed with message: Cannot read properties of undefined (reading 'length') Request textDocument/completion failed with message: Cannot read properties of undefined (reading 'length') Request textDocument/completion failed with message: Cannot read properties of undefined (reading 'length') Request textDocument/completion failed with message: Cannot read properties of undefined (reading 'length') Command History: (executable check - success) yaml-language-server (executable check - failure) spectral (executable check - failure) yamllint (started) ['/opt/homebrew/bin/bash', '-c', '''yaml-language-server'' --stdio']
pbnj commented 1 year ago

I believe the completion issue is related to https://github.com/dense-analysis/ale/issues/4210#issuecomment-1134677571

ALE lsp implementation does not support snippets, while YAML LSP completion needs snippet support: https://github.com/redhat-developer/yaml-language-server/blob/3a74bdc22a1ae8a752e89cbf32616eacae163cea/src/languageservice/services/yamlCompletion.ts