godotengine / godot-docs

Godot Engine official documentation
https://docs.godotengine.org
Other
3.7k stars 3.03k forks source link

Add Neovim LSP client configuration examples. #8779

Open Rubonnek opened 7 months ago

Rubonnek commented 7 months ago

Your Godot version: v4.2.1.stable.official

Issue description: Simulating an stdio connection against the LSP server through a piped TCP connection might cause issues that seem server-sided such as textDocument/hover not working correctly as reported on https://github.com/godotengine/godot/issues/87192 when in reality the issue is client-sided.

This issue is specific to Neovim -- it would be nice to have working examples of LSP client configurations for NeoVim in the documentation.

URL to the documentation page (if already existing): https://docs.godotengine.org/en/stable/tutorials/editor/external_editor.html

luevano commented 5 months ago

I have a working neovim setup but I'm not sure if it's worth it to write as there are multiple ways to configure this. For example I use:

My vim.lsp.buf.hover works fine, unless the issue is another thing:

image

Rubonnek commented 5 months ago

works fine, unless the issue is another thing

To my knowledge there's no issue other than missing documentation.

I have a working neovim setup but I'm not sure if it's worth it to write as there are multiple ways to configure this

As long as it's consistent, concise and clear I think it's enough. By this I mean trying to stick to a specific way of configuring Neovim if provided by the plugin manager instead of mixing/matching different ways of configuring it (say vimscript + lua + some plugin manager setting).

For example, LazyVim provides a user plugin specification which seems to suffice. This is what I have on mine to support LSP + DAP:

$HOME/.config/nvim/lua/plugins/godot-support-spec.lua

return {
  -- add the LSP server configuration through lspconfig
  {
    "neovim/nvim-lspconfig",
    ---@class PluginLspOpts
    opts = {
      -- ---@type lspconfig.options
      servers = {
        gdscript = {}, -- NOTE: To change the port, you need to set the environment variable GDScript_Port to the correct port number.
      },
    },
  },

  -- add an nvim-dap configuration for gdscript and a DAP client adapter configuration for it.
  {
    "mfussenegger/nvim-dap",
    opts = {},
    config = function(_, opts)
      local dap = require("dap")
      dap.configurations.gdscript = {
        {
          type = "godot",
          request = "launch",
          name = "Launch scene",
          project = "${workspaceFolder}",
          launch_scene = true,
        },
      }
      dap.adapters.godot = {
        type = "server",
        host = "127.0.0.1",
        port = 6006,
      }
    end,
  },
}

The only thing missing above is syntax highlighting which is provided by nvim-treesitter but which needs to be configured in one place only. I currently have that in a separate base-spec.lua

$HOME/.config/nvim/lua/plugins/base-spec.lua

  {
    "nvim-treesitter/nvim-treesitter",
    opts = {
      ensure_installed = {
        "gdscript", -- there are other entries in this list but only gdscript is included to be concise
      },
    },
  },

That's roughly what I was planning to submit but I've not gotten around to it because I've not tested the DAP plugin thoroughly.

* `null-ls` (`gdtoolkit`: `gdformat` and `gdlint`): for formatting and linting.

Do you have this configured through a LazyVim plugin spec? Sounds like it would be a nice to have in the documentation.

luevano commented 5 months ago

@Rubonnek yes I'm familiar with the spec, but my config itself might be a bit of a mess. You can find my config in my nvim repo. It's just a matter of installing gdtoolkit either through mason or system package manager (or pip) and then setting the sources in null-ls (now none-ls):

https://github.com/luevano/nvim/blob/9394f1243425db00825b10091648bbd2c1f83d01/lua/plugins/null-ls.lua#L12-L14

Currently, I had to install gdtoolkit manually as well as an extra dependency missing from upstream, until they fix that then mason can be used no problem. Other than this, I have basically the same config except for the debugger as I don't really use it, I think I have nvim-dap setup for something else but I ended up not even using it.