Skip to content

Latest commit

 

History

History
522 lines (407 loc) · 22.5 KB

File metadata and controls

522 lines (407 loc) · 22.5 KB

BuyMeACoffee

BuyMeACoffee Godot Neovim License Release CI

godotdev.nvim

A Neovim plugin for Godot 4 that brings GDScript/GDShader LSP, DAP debugging, and formatting to your external‑editor workflow.

Screenshot of Neovim connected to Godot's LSP server, Godot's console output and documentation server.

This plugin helps you to set up:

  • LSP support for GDScript and Godot shaders (.gdshader files)
  • Godot class docs in Neovim, rendered from the official docs source as Markdown
  • Debugging via nvim-dap for GDScript
  • Optional live run output for :GodotRun* commands in a Neovim buffer or float
  • Treesitter syntax highlighting for Godot shader files
  • Automatic formatting of .gd files using gdscript-formatter
  • Optional C# support (user-managed LSP, plus debugging and tooling checks)
  • Built-in health checks to verify environment, dependencies, and editor integration

While it is possible to configure Neovim manually for Godot development, this plugin simplifies setup and ensures a consistent, cross-platform workflow. It automatically configures LSP, debugging, formatting, and environment checks, so you can focus on writing game code rather than troubleshooting editor setup.

DAP debugging within Nvim Insert a node path directly from Godot in Nvim Access Godot's documentation in/from Nvim
Screenshot: Neovim with Godot's debugger godotdev.nvim node copy. Copy a node path from Godot into nvim Example/screenshot of Neovim showing Godot documentation in a floating window.

Table of Contents

Why godotdev.nvim?

  • Turn Neovim into a first‑class external editor for Godot 4 projects.
  • Get LSP features for GDScript/GDShader without manual wiring.
  • Debug GDScript via DAP and validate setup with built‑in health checks.

Features

Below is a quick overview of what you get out of the box:

LSP Support

  • Full GDScript language support (Go to definition, references, hover, rename, code actions, etc.)
  • Optional inline hints via Neovim's built-in inlay hint API when the attached Godot LSP supports textDocument/inlayHint
  • .gdshader syntax highlighting and language features via Treesitter
  • Optional C# LSP support (user-managed csharp-ls or OmniSharp) for Godot projects with C# scripts

Debugging (DAP)

  • Debug GDScript directly from Neovim using nvim-dap
  • Optional C# debugging via netcoredbg

Formatting

  • Automatic .gd file formatting using gdscript-formatter
  • Reloads buffer after formatting for immediate feedback
  • Recommended .editorconfig included for consistent indentation (4 spaces per indent)
  • Supported formatters:

Health Checks

  • :checkhealth godotdev validates:
    • Built-in Neovim LSP support plus plugin dependencies: nvim-dap, nvim-dap-ui, nvim-treesitter
    • Godot editor LSP and debug servers
    • Floating Godot docs support (curl and active docs source configuration)
    • Optional C# tooling: dotnet, csharp-ls/OmniSharp, netcoredbg
    • Formatter: gdscript-formatter by default, with gdformat as an alternative

Editor Integration

  • Commands to start or reconnect to Godot’s editor LSP:
    • :GodotStartEditorServer
    • :GodotReconnectLSP
    • :GodotToggleInlineHints
  • Commands to run Godot from Neovim without DAP:
    • :GodotRunProject
    • :GodotRunCurrentScene
    • :GodotRunScene {path}
    • :GodotRunScenePicker (optional Telescope integration)
  • Commands to open Godot class reference docs:
    • :GodotDocs [ClassName]
    • :GodotDocsFloat [ClassName]
    • :GodotDocsBuffer [ClassName]
    • :GodotDocsBrowser [ClassName]
    • :GodotDocsCursor
  • Automatic LSP attachment for Godot filetypes (.gd, .gdshader, .gdresource, optional .cs)
  • Works cross-platform (macOS, Linux, Windows) with TCP or named pipes

Optional C# Support

  • Enable by setting csharp = true in require("godotdev").setup()
  • C# LSP is configured by you (the plugin only checks that csharp-ls or OmniSharp is installed)
  • Health checks and DAP integration included

Requirements

  • Neovim 0.11+
  • Godot 4.x+ with TCP LSP enabled
  • nvim-dap and nvim-dap-ui for debugging
  • nvim-treesitter
  • Windows users must have ncat in PATH
  • Optional C# support requires (you manage the LSP configuration):
    • .NET SDK (dotnet)
    • C# LSP server (csharp-ls recommended or omnisharp)
    • netcoredbg debugger

Installation (Lazy.nvim)

{
  'Mathijs-Bakker/godotdev.nvim',
  dependencies = { 'nvim-dap', 'nvim-dap-ui', 'nvim-treesitter' },
}

Installation (vim.pack, Neovim 0.12+)

vim.pack.add({
  "https://github.com/Mathijs-Bakker/godotdev.nvim",
  "https://github.com/mfussenegger/nvim-dap",
  "https://github.com/rcarriga/nvim-dap-ui",
  "https://github.com/nvim-treesitter/nvim-treesitter",
})

Quickstart

  1. Open your Godot project in Neovim
  2. Start Godot editor with TCP LSP enabled (Editor Settings → Network → Enable TCP LSP server)
  3. Open a .gd or .gdshader file
  4. LSP will automatically attach
  5. Use Neovim's built-in LSP mappings such as K, grr, grn, and gri, or your own custom mappings
  6. Start debugging with DAP (Launch scene configuration)
  7. Optional: Enable C# support by setting csharp = true in the plugin setup
  8. Run :checkhealth godotdev at any time to verify plugin, LSP, debug server, and C# dependencies

Configuration

Optional settings

require("godotdev").setup({
  editor_host = "127.0.0.1", -- Godot editor host
  editor_port = 6005,        -- Godot LSP port
  debug_port = 6006,         -- Godot debugger port
  csharp = true,             -- Enable C# Installation Support
  autostart_editor_server = false, -- opt-in: start a Neovim server automatically on setup
  formatter = "gdscript-formatter",    -- "gdscript-formatter" | "gdformat" | false
  formatter_cmd = nil,       -- string or argv list; default gdscript-formatter adds "--reorder-code"
  inline_hints = {
    enabled = false,         -- enable Neovim inlay hints when the attached server supports them
  },
  run = {
    console = {
      enabled = false,       -- capture :GodotRun* output in Neovim; these runs are no longer detached
      renderer = "buffer",   -- "buffer" | "float"
      buffer = {
        position = "bottom", -- "right" | "bottom" | "current"
        size = 0.3,
      },
      float = {
        width = 0.8,
        height = 0.25,
        border = "rounded",
      },
    },
  },
  editor_server = {
    address = nil,           -- nil uses the current server or the platform default
    remove_stale_socket = true,
  },
  treesitter = {
    auto_setup = true,       -- convenience default; disable if you manage nvim-treesitter yourself
    ensure_installed = { "gdscript" },
  },
  docs = {
    renderer = "float",      -- default: open docs in a floating window
    fallback_renderer = "browser", -- nil | "browser" | "buffer"; browser is the only fetch-recovery fallback
    missing_symbol_feedback = "message", -- "message" | "notify"
    version = "stable",      -- e.g. "stable", "latest", "4.5"
    language = "en",
    source_ref = "master",   -- godot-docs git ref used for floating docs
    source_base_url = nil,   -- optional override for raw docs source
    timeout_ms = 10000,
    cache = {
      enabled = true,
      max_entries = 64,
    },
    float = {
      width = 0.8,
      height = 0.8,
      border = "rounded",
    },
    buffer = {
      position = "right",    -- "right" | "bottom" | "current"
      size = 0.4,
    },
  },
})

For formatter commands with flags, prefer an argv list:

formatter_cmd = { "gdscript-formatter", "--check" }

By default, gdscript-formatter runs with:

formatter_cmd = { "gdscript-formatter", "--reorder-code" }

To disable autoformat-on-save entirely:

formatter = false

If you already manage nvim-treesitter yourself, you can disable plugin-managed setup:

treesitter = {
  auto_setup = false,
}

Default notes:

  • autostart_editor_server = false is the safer default because starting a Neovim server is an external-editor concern and should be opt-in.
  • inline_hints.enabled = false is the safer default because Godot's LSP support for inlay hints may vary by version and filetype.
  • run.console.enabled = false is the safer default because live console capture changes :GodotRun* from detached launches to attached subprocesses managed by Neovim.
  • treesitter.auto_setup = true stays enabled by default for convenience, but it is safe to turn off if you already configure nvim-treesitter yourself.
  • docs.fallback_renderer = "browser" remains the default because browser fallback is the only option that can recover when rendered .rst docs cannot be fetched.
  • The plugin uses Neovim's built-in LSP APIs; nvim-lspconfig is not required unless you want it for other servers in your own config.

If you enable inline hints, the plugin only turns them on automatically for buffers attached through this plugin's Godot GDScript LSP setup, and only when that client reports support for textDocument/inlayHint. If the current Godot GDScript LSP build does not advertise that method, no hints will appear even when inline_hints.enabled = true. C# LSP is user-managed in this plugin, so inline hints are not auto-enabled for C# buffers here. You can toggle the current buffer manually with :GodotToggleInlineHints.

Note: This plugin does not define any keymaps by default, so it will not interfere with the standard DAP mappings. If you want custom keybindings, you can configure them yourself. For example, you could map :GDebug to DapNew to start one or more new debug sessions.

See :help dap-mappings and :help dap-user-commands for more details.

Additional references:

Testing

Run the headless test suite:

nvim --headless -u NONE -i NONE -c "lua dofile('tests/run.lua')" -c qa

The same command runs in GitHub Actions on pushes to master and on pull requests.

For integration testing, also run the plugin inside Neovim against a real Godot project and verify editor server, docs, formatting, and debugging flows on your target platform.

Optimize Godot editor for Neovim

Below are the recommended settings for configuring the Godot editor for optimal integration with Neovim as your external editor. To access these settings, make sure that the Advanced Settings switch is enabled at the top of the Editor Settings dialog.

  • Editor Settings > Text Editor > Behavior > Auto Reload Scripts on External Change

    Show Screenshot -> Godot Editor Settings
  • Editor Settings > Interface > Editor > Save on Focus Loss

    Show Screenshot -> Godot Editor Settings
  • Editor Settings > Interface > Editor > Import Resources When Unfocused

    Show Screenshot -> Godot Editor Settings

Open scripts from Godot Editor in Neovim (running in a terminal)

When you click on a gdscript in Godot's FileSystem dock it doesn't open automatically in Neovim. A workaround is to to create a small script which launches the file in Neovim.

>> macOS/Linux

Complete instructions here

If you start Neovim with --listen on macOS/Linux, use the documented godotdev wrapper instead of raw nvim --listen ... so stale socket files are cleaned up automatically after crashes. If your wrapper still reports Neovim server already running at /tmp/godot.nvim after you already quit, update its probe to use nvr --nostart --servername ... --remote-expr '1'.

>> Windows

  1. Set Neovim to listen on a TCP port
    nvim --listen 127.0.0.1:6666
    --listen works with host:port on Windows.
  2. Tell Godot to connect to that port In Godot, configure your external editor or plugin to connect to 127.0.0.1:6666. Make sure the TCP port you choose is free and consistent between Neovim and Godot.

🤌🫶🏻🥹❤️‍🩹 REQUEST:
I am not using Windows, so I did not test any of this. It would be great if anyone could help me to validate this and report your findings here. 🙏

Godot editor server

You can manually start the Neovim editor server used by Godot:

:GodotStartEditorServer

If Neovim is already running with --listen, the plugin will reuse that address instead of trying to start a second server.

Or automatically on plugin setup:

require("godotdev").setup({
  autostart_editor_server = true,
})

You can also pin a specific address:

require("godotdev").setup({
  autostart_editor_server = true,
  editor_server = {
    address = "/tmp/godot.nvim",
  },
})

On macOS/Linux, plugin-managed startup removes stale Unix socket files before retrying. This hardens :GodotStartEditorServer, but it does not affect a raw shell launch like nvim --listen /tmp/godot.nvim, because that failure happens before the plugin loads.

Reconnect to Godot's LSP server

If the LSP disconnects or you opened a script before Neovim, run:

:GodotReconnectLSP

Reconnects all Godot buffers to the LSP.

Run Godot

You can run the current Godot project or scene from Neovim without using DAP:

:GodotRunProject
:GodotRunCurrentScene
:GodotRunScene scenes/Main.tscn
:GodotRunScenePicker

Notes:

  • :GodotRunProject launches Godot for the current project root.
  • :GodotRunCurrentScene works from a .tscn, or from a .gd / .cs buffer when that script is attached to a scene in the current project.
  • If the current script is attached to multiple scenes, the command uses Telescope to let you choose one when Telescope is installed.
  • :GodotRunScene {path} accepts res://..., a project-relative path, or an absolute path inside the current project.
  • :GodotRunScenePicker uses Telescope to browse .tscn files in the current project and run the selected scene.
  • These commands shell out to godot on your PATH.
  • :GodotRunScenePicker requires Telescope to be installed; the rest do not.

Optional console capture:

  • Set run.console.enabled = true to capture stdout/stderr from :GodotRun* inside Neovim.
  • Choose run.console.renderer = "buffer" for a split buffer or "float" for a floating window.
  • Use :GodotShowConsole to reopen the most recent captured console window.
  • While console capture is enabled, the launched Godot process is managed by Neovim instead of using the plugin's detached launch path.
  • This first implementation captures one active Godot run at a time; starting another captured run while one is still active shows a warning.

Godot class docs

Open the official Godot class reference from Neovim:

:GodotDocs Node

By default, :GodotDocs renders the docs in a floating window. You can also:

:GodotDocsFloat Node
:GodotDocsBuffer Node
:GodotDocsBrowser Node
:GodotDocsCursor
  • If :GodotDocs is called without an argument, it uses the symbol under the cursor. Browser opening uses your configured system opener.
  • Float and buffer rendering fetch the class reference source from godotengine/godot-docs with curl, converts the .rst to markdown, and displays that inside Neovim.
  • :GodotDocsBuffer reuses a scratch markdown buffer so the docs stay open while you keep working.
  • Configure persistent buffer placement with docs.buffer.position = "right" | "bottom" | "current" and docs.buffer.size = 0.4.
  • Docs fetches and rendered markdown are cached in memory by default. Configure this with docs.cache.enabled and docs.cache.max_entries.
  • The float and buffer renderers use the markdown filetype, so Markdown rendering plugins such as MeanderingProgrammer/render-markdown.nvim can improve its presentation.
  • docs.fallback_renderer = "browser" is the only fallback that can recover when the rendered .rst source cannot be fetched. A buffer fallback only changes presentation after rendering succeeds.
  • When a symbol does not resolve to a Godot class page, the plugin shows a regular Neovim message by default. Set docs.missing_symbol_feedback = "notify" if you prefer notifications instead.

ℹ️ Recommended docs mapping:

vim.keymap.set("n", "gK", "<cmd>GodotDocs<cr>", { desc = "Godot docs" })

If you prefer a leader mapping instead:

vim.keymap.set("n", "<leader>gd", "<cmd>GodotDocs<cr>", { desc = "Godot docs" })

Why gK:

  • K is commonly LSP hover under cursor.
  • gK is close enough semantically to “keyword docs” and is usually free.
  • gd, gD, gr are already established LSP/navigation motions.
  • <leader>gd reads like godot docs.
  • It fits well because :GodotDocs already defaults to the symbol under cursor.

C# Installation Support

  • Enable by setting csharp = true in require("godotdev").setup()
  • C# LSP setup is user-managed; :checkhealth godotdev will only verify tooling is installed:
    • .NET SDK (dotnet)
    • C# LSP server (csharp-ls or omnisharp)
    • Debugger (netcoredbg)

Autoformatting / Indentation

Godot expects spaces, 4 per indent (for both GDScript and C#). This plugin automatically sets buffer options for .gd files.

Additionally, .gd files are autoformatted on save with gdscript-formatter unless you set formatter = false:

gdscript-formatter is the default because the companion addon godotdev.nvim-node-copy relies on it, and it is also a fast formatter for the external-editor workflow.

Make sure gdscript-formatter is installed and in your PATH. If not, you will see a warning notification.

The plugin expects an executable literally named gdscript-formatter. Install or build it from:

After installation, verify it with:

gdscript-formatter --help

If you prefer gdformat, set:

formatter = "gdformat"

Supported formatter repositories:

For more info on indentation: :help godotdev-indent

Recommended Godot addon (Node Copy)

If you use godotdev.nvim as your main external-editor workflow, the companion addon godotdev.nvim-node-copy is recommended.

Why it helps:

  • Godot's built-in external editor integration does not provide drag-and-drop of nodes into Neovim.
  • The addon adds copy actions for selected nodes in the Scene Tree and 2D editor, so you can paste useful references directly into your script.
  • The addon relies on gdscript-formatter, which is why godotdev.nvim uses it as the default formatter.
  • It keeps the workflow explicit and safe: select a node in Godot, copy the reference you want, then paste it at the cursor in Neovim.

It currently supports copying:

  • node paths
  • $Node references
  • get_node(...) expressions
  • typed @onready var snippets
  • C# property snippets

Hiding Godot Project Files in oil.nvim and mini.files

Godot generates files and folders like .uid, .import, or .godot/ that can clutter your file explorer. You can hide them in both oil.nvim and mini.files by filtering against their patterns. Show me how

BuyMeACoffee