robotcodedev / robotcode

RobotFramework support for Visual Studio Code
https://robotcode.io
Apache License 2.0
168 stars 13 forks source link

[ENHANCEMENT] Neovim Support (LSP Config) #232

Open touchedthecode opened 4 months ago

touchedthecode commented 4 months ago

Hi Daniel, we had a conversation at RoboCon24 regarding Neovim Support. You showed me your LSP Config for Neovim and suggested I write a github ticket so you could share it with me and maybe I can contribute to it because Neovim is my main IDE/editor.

Thank you for considering this request and for your contributions to the Robot Framework community!

d-biehl commented 4 months ago

this is just a crude configuration, like I said I'm not very experienced with Neovim, but it works a little for me.

I followed this guide: https://github.com/neovim/nvim-lspconfig to enable lsp support in nvim. I installed neovim-lspconfig in archlinux via pacman, don't know how this works on other distributions.

then i created a file /usr/share/nvim/site/pack/dist/start/lspconfig/lua/lspconfig/server_configurations/robotcode.lua with this content:

local util = require 'lspconfig.util'

return {
  default_config = {
    -- cmd = { 'robotcode', '--log', '--log-level', 'TRACE', '--log-filename', 'lsp.log', 'language-server' },
    cmd = { 'robotcode', 'language-server' },
    filetypes = { 'robot', 'resource' },
    root_dir = function(fname)
      return util.root_pattern('robot.toml', 'pyproject.toml')(fname) or util.find_git_ancestor(fname)
    end,
    single_file_support = true,
    get_language_id = function(_, filetype)
        return 'robotframework'
    end,
  },
  docs = {
    description = [[
https://robotcode.io

RobotCode - Language Server Protocol implementation for Robot Framework.
]],
    default_config = {
      root_dir = "util.root_pattern('robot.toml', 'pyproject.toml')(fname) or util.find_git_ancestor(fname)",
      settings = {}
    },
  },
}

and then I enabled the robotcode support in my ~/.config/nvim/init.lua neovim config by adding, this line:

local lspconfig = require('lspconfig')

lspconfig.robotcode.setup {}

now you need to create a venv for you python project and install robotcode-language-server via pip to this environment, create a robot.toml file at the root of your project, maybe you need to configure it, and after this you need to open a .robot file.

If you can get it to work, maybe you can write a little bit of documentation for it, and maybe submit a pull request to the lsp-config project so that it might be included in the official code. This would be really cool!!! ;-)

if you have questions, ... you know ;-)