I got this working mostly as per the above.
For syntax highlighting I guess it’s not supported by nvim-treesitter. So copy files from the repo as follows:
git clone https://github.com/mfukar/robotframework-vim
cd robotframework-vim
cp ftdetect/robot.vim .config/nvim/ftdetect/
cp after/syntax/robot.vim .config/nvim/syntax/robot.vim
For LSP support add the following lines to init.lua
to bootstrap with Packer:
-- Bootstrap packer.nvim
-- from https://github.com/wbthomason/packer.nvim#bootstrapping
local ensure_packer = function()
local fn = vim.fn
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
if fn.empty(fn.glob(install_path)) > 0 then
fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
vim.cmd [[packadd packer.nvim]]
return true
end
return false
end
local packer_bootstrap = ensure_packer()
return require('packer').startup(function(use)
use 'wbthomason/packer.nvim'
-- My plugins here
-- LSP nvim-cmp
use 'neovim/nvim-lspconfig' -- Collection of configurations for built-in LSP client
use 'hrsh7th/nvim-cmp' -- Autocompletion plugin
use 'hrsh7th/cmp-nvim-lsp' -- LSP source for nvim-cmp
use 'saadparwaiz1/cmp_luasnip' -- Snippets source for nvim-cmp
use 'L3MON4D3/LuaSnip' -- Snippets plugin
use 'williamboman/mason.nvim' -- manage LSP and DAP servers, linters and formatters
-- Automatically set up your configuration after cloning packer.nvim
-- Put this at the end after all plugins
if packer_bootstrap then
require('packer').sync()
end
end)
Then add in init.lua
or a submodule within .config/nvim/lua/
the following to setup Mason:
require("mason").setup()
And then add the following lines to setup nvim-cmp (auto complete) for C, python and robot framework:
-- Add additional capabilities supported by nvim-cmp
local capabilities = require("cmp_nvim_lsp").default_capabilities()
local lspconfig = require('lspconfig')
-- Enable some language servers with the additional completion capabilities offered by nvim-cmp
local servers = { 'clangd', 'pylsp', 'robotframework_ls' }
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup {
-- on_attach = my_custom_on_attach,
capabilities = capabilities,
}
end
require('lspconfig')['pylsp'].setup {
capabilities = capabilities,
settings = {
pylsp = {
plugins = {
jedi_completion = {
include_params = true,
},
},
},
},
}
-- luasnip setup
local luasnip = require 'luasnip'
-- nvim-cmp setup
local cmp = require 'cmp'
cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
}),
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
},
}
At this stage I exited neovim and restarted it, then ran commands:
:PackerSync
to install the new plugins and
:Mason
to launch the Mason interface, where I scrolled down to robotframework-lsp
and pressed the i
key to install it. Also installed the python-lsp-server
.
Used pylsp instead of the default python language server because it supports function argument signatures and shows docstrings.
For robot files when I ran nvim command :LspInfo
I was getting the following error for root directory: Not found:
I noticed here, it is looking for either robotidy.toml
or pyproject.toml
to indocate the root directory, or a git repo. I just ran git init
and then it started working. You can also just create one of those two files.
Still not quite as nice as VS Code robocorp plugin as it’s missing the docstrings in the autocomplete for the robot framework keywords. Also missing is the DAP protcol for the robotframework_debug_adapter for debugging support. Also integration of robocop linter and robotidy formatter would be nice. Should all be doable I’d imagine. Though robocop/robotide can all be done at the CLI easily enough.
Perhaps a neovim plugin that pulls all of this together is in order.