vim-lsp-settings icon indicating copy to clipboard operation
vim-lsp-settings copied to clipboard

How to slightly modify a server config?

Open idbrii opened this issue 2 years ago • 2 comments

I'm trying to use a language server with vim-lsp-settings's provided configuration, but I want to change a couple fields in the configuration.

  1. Should I copy the config from ~\.vim\bundle\lsp-settings\settings\sumneko-lua-language-server.vim into ~/.vim/ftplugin/lua.vim?
  2. Should I use :LspSettingsGlobalEdit? What do I put in there?
  3. Should I use lsp#update_workspace_config()?

What seems like the obvious solution is to put a minimal config into my .vimrc:

let g:lsp_settings = get(g:, 'lsp_settings', {})
let s:sumneko = get(g:lsp_settings, 'sumneko-lua-language-server', {})
let g:lsp_settings['sumneko-lua-language-server'] = s:sumneko
let s:sumneko.workspace_config = {
            \        'Lua': {
            \            'diagnostics': {
            \                'globals': ["Class"],
            \                },
            \            },
            \        }

That doesn't work because diagnostics.enable is never set to true -- the lsp-settings default config didn't apply. Also :echo lsp_settings#get('sumneko-lua-language-server', 'workspace-config', lsp_settings#server_config('sumneko-lua-language-server')) returns an empty dict. Not sure how I can see what settings are getting applied.

:help vim-lsp-settings-configuration implies that this should work:

Tips: If you want to only add/replace arguments for the server,

let g:lsp_settings = { \ 'some-langserver': { \ 'args': ['foo', 'bar', 'baz'], \ }, }

settings\sumneko-lua-language-server.vim gets these settings like so:

      \ 'workspace_config': lsp_settings#get('sumneko-lua-language-server', 'workspace_config', g:vim_lsp_settings_sumneko_lua_language_server_workspace_config),

But lsp_settings#get() doesn't merge the tables, so I either get workspace_config from g:lsp_settings or g:vim_lsp_settings_sumneko_lua_language_server_workspace_config.

idbrii avatar Feb 23 '22 23:02 idbrii

Documenting exactly what I tried and how it worked out:

copy the config

✅ works ❌ requires full config copy

Copypasting the full config (44 lines!) into my vimrc as a field in g:lsp_settings worked, but now I'll lose any improvements that lsp-settings adds

let g:lsp_settings = get(g:, 'lsp_settings', {})
let g:lsp_settings['sumneko-lua-language-server'] = {
            \    'workspace_config': {
            \        'Lua': {
...
            \            'diagnostics': {
            \                'enable': v:true,
            \                'globals': ["Class"],
            \                'severity': {}
            \                },
...
            \            }
            \        }
            \    }

LspSettingsGlobalEdit

✅ works ❌ requires full config copy

Minimal config has the same problem as minimal config in vimrc:

{
    "sumneko-lua-language-server": {
        "workspace_config": {
            "Lua": {
                "diagnostics": {
                    "globals": [
                        "Class"
                    ]
                }
            }
        }
    }
}

Pasting the full config as json and changing globals worked:

let g:temp_settings = { "sumneko-lua-language-server": { "workspace_config": g:vim_lsp_settings_sumneko_lua_language_server_workspace_config, }, } 
put =json_encode(g:temp_settings)

lsp#update_workspace_config

✅ works ✅ requires minimal config ❌ doesn't load on startup

This was the most promising, but can't run on first load since the lsp server isn't running yet.

let s:servername = 'sumneko-lua-language-server'
if lsp#get_server_status(s:servername) ==# 'running'
    call lsp#update_workspace_config(s:servername, {
                \            'Lua': {
                \                'diagnostics': {
                \                    'globals': ["Class"],
                \                    },
                \        },
                \ })
endif

idbrii avatar Feb 24 '22 00:02 idbrii

The solution I'm still running with is calling lsp#update_workspace_config from ftplugin/lua.vim with a guard that the server is running (as shown above). This tends to apply my config after I edit my second lua file in a session. Not great, but not the worst.

idbrii avatar Aug 10 '23 20:08 idbrii