yegappan / lsp

Language Server Protocol (LSP) plugin for Vim9
MIT License
461 stars 54 forks source link

Is there a way to reconfigure a server's config after entering vim? #536

Open kedodrill opened 2 months ago

kedodrill commented 2 months ago

Hi there, thank you for this plugin!

I'm trying to set the environment.phpVersion config for the intelephense (PHP) server dynamically. Unfortunately intelephense does not do this automatically.

In neovim, I did this using the on_init function provided by nvim-lspconfig. Is there something similar I can use here, or can I use some kind of vimscript to do this?

Conditionally adding the server if vim is opened in a directory where there is a composer.json file does work, but it would be nice to be able to set the version so I can move around to different projects within vim.

Here is what I have right now. (github doesn't support vim9script yet I don't think? this is all in vim9script).

def GetPHPVersion():string
" ...
enddef

var lspServers = []

if (filereadable('composer.json'))
    lspServers->add({
        " intelephense...
        workspaceConfig: { intelephense: { environment: { phpVersion: GetPHPVersion() } } }
    })
endif

What I would like to see is something like this (I think this is valid vim9script...but not sure. you get the idea though):

" ...
var lspServers = []
var intelephense = {
    " intelephense...
}
" onInit (optional): each time the server is started, execute an inline function that has the settings as a param and changes the settings
intelephense.onInit = (intelephense) => {
    intelephense.workspaceConfig = {
        intelephense: { environment: { phpVersion: GetPHPVersion() } }
    }
}
lspServers->add(intelephense)