This took longer than I care to admit. I work both in MacOS and Windows daily. Recently I wanted to setup Godot’s LSP with neovim on Windows and it turned out more tricky than I would have liked. The crux of the issue was trying to get the LSP configured to use netcat instead on windows. I’m also using the LazyVim distro. Long story short, under my plugins folder I have a lsp.lua file that does some custom configuration and this is what I had to do to get it to finally work:

return {
  "neovim/nvim-lspconfig",
  opts = {
    servers = {
      gdscript = {
        cmd = { "ncat", "localhost", "6005" },
      },
    },
  },
}

The prerequisites for this:

  • Having netcat installed (for scoops users that’s scoop install nmap) and in your path.
  • Using a LazyVim distro. If your using a custom configuration the premise is the same, just do whatever you need to configure your LSP to use it.

Why did it take longer than expected? I was getting messages in the godot editor saying an LSP client was connecting. Yet I was getting no auto-completions. After going down several rabbit holes I looked at the built-in config from nvim-lspconfig:

local util = require 'lspconfig.util'

local port = os.getenv 'GDScript_Port' or '6005'
local cmd = { 'nc', 'localhost', port }

if vim.fn.has 'nvim-0.8' == 1 then
  cmd = vim.lsp.rpc.connect('127.0.0.1', port)
end

return {
  default_config = {
    cmd = cmd,
    filetypes = { 'gd', 'gdscript', 'gdscript3' },
    root_dir = util.root_pattern('project.godot', '.git'),
  },
  docs = {
    description = [[
https://github.com/godotengine/godot

Language server for GDScript, used by Godot Engine.
]],
    default_config = {
      root_dir = [[util.root_pattern("project.godot", ".git")]],
    },
  },
}

The issue was that it was invoking nc instead of ncat. Ugh. I’ve gone back and forth on rolling my own config vs using a distro. This is one of those cases where had I rolled my own, I would’ve resolved this way quicker. Oh well.

Other issues with Neovim and Godot

Another thing I ran into was spaces vs tabs. I couldn’t quite get to the bottom of it, but Godot was very upset about using spaces instead of tabs. My solution was to create a ftplugin. To do so:

  1. create a folder called ftplugin containing a file called gdscript.lua in your nvim config (:echo stdpath('config')).
  2. using these settings:
vim.o.tabstop = 4 -- A TAB character looks like 4 spaces
vim.o.expandtab = false -- Pressing the TAB key will insert spaces instead of a TAB character
vim.o.softtabstop = 4 -- Number of spaces inserted instead of a TAB character
vim.o.shiftwidth = 4 -- Number of spaces inserted when indenting
vim.o.commentstring = "# %s" -- add comment support

More docs on ftplugin can be found here.

Here’s a few other links I found while trying to figure out WTF was wrong that may apply to your setup: