Use the Flux LSP with Vim

Requirements

Install the Flux plugin

There are many ways to install and manage Vim plugins. We recommend either of the following two methods:

Both methods require you to add the following to your .vimrc so that Vim can recognize the .flux file type:

  1. " Flux file type
  2. au BufRead,BufNewFile *.flux set filetype=flux

Install with vim-lsp

  1. Install flux-lsp-cli with npm

    1. npm i -g @influxdata/flux-lsp-cli
  2. Install vim-lsp

    If it doesn’t exist yet, create a directory called pack/$USER/start/ in your ~/.vim/ and clone vim-lsp into it:

    1. cd ~
    2. mkdir -p .vim/pack/$USER/start/
    3. cd .vim/pack/$USER/start/
    4. git clone https://github.com/prabirshrestha/vim-lsp
  3. Edit your .vimrc

    Next, edit your .vimrc configuration file to include the following:

    1. let g:lsp_diagnostics_enabled = 1
    2. if executable('flux-lsp')
    3. au User lsp_setup call lsp#register_server({
    4. \ 'name': 'flux lsp',
    5. \ 'cmd': {server_info->[&shell, &shellcmdflag, 'flux-lsp']},
    6. \ 'whitelist': ['flux'],
    7. \ })
    8. endif
    9. autocmd FileType flux nmap gd <plug>(lsp-definition)

Install with vim-coc

  1. Install flux-lsp-cli from npm

    1. npm i -g @influxdata/flux-lsp-cli
  2. Install plug-vim

    Install plug-vim, a plugin manager for Vim.

  3. Install vim-coc

    Install vim-coc, a code-completion plugin for Vim.

  4. Configure vim-coc

    vim-coc uses a coc-settings.json located in your ~/.vim/ directory. To run the Flux LSP, add the Flux section under languageserver:

    1. {
    2. "languageserver": {
    3. "flux": {
    4. "command": "flux-lsp",
    5. "filetypes": ["flux"]
    6. }
    7. }
    8. }

    To debug flux-lsp, configure it to log to /tmp/fluxlsp:

    1. {
    2. "languageserver": {
    3. "flux": {
    4. "command": "flux-lsp",
    5. "args": ["-l", "/tmp/fluxlsp"],
    6. "filetypes": ["flux"]
    7. }
    8. }
    9. }