Files
godotdev.nvim/README.md

193 lines
7.2 KiB
Markdown
Raw Normal View History

2025-08-21 16:55:14 +02:00
<div align="center"><img src="assets/godotdev-nvim-logo.svg" width="300"></div>
2025-08-21 16:56:39 +02:00
2025-08-18 12:15:55 +02:00
# godotdev.nvim
2025-08-20 18:07:10 +02:00
2025-09-08 13:08:11 +02:00
**godotdev.nvim** is a batteries-included Neovim plugin for Godot 4.x game development.
It allows you to use Neovim as a fully featured external editor for Godot, with minimal setup.
This plugin provides:
- **LSP support** for GDScript and Godot shaders (`.gdshader` files)
- **Debugging** via `nvim-dap` for GDScript
- **Treesitter syntax highlighting** for Godot shader files
- **Automatic formatting** of `.gd` files using `gdformat`
- **Optional C# support** including LSP, debugging, and tooling
- **Built-in health checks** to verify environment, dependencies, and editor integration
2025-09-15 11:55:20 +02:00
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.
2025-08-20 18:07:10 +02:00
## Features
2025-09-08 13:08:11 +02:00
godotdev.nvim provides a complete Neovim environment for Godot 4.x development, with minimal setup. Key features include:
### LSP Support
- Full GDScript language support (Go to definition, references, hover, rename, code actions, etc.)
- `.gdshader` syntax highlighting and language features via Treesitter
- Optional C# LSP support (`csharp-ls` or OmniSharp) for Godot projects with C# scripts
### Debugging (DAP)
- Debug GDScript directly from Neovim using `nvim-dap`
2025-09-15 11:55:20 +02:00
- For setting up keymaps see: `:help dap-mappings`
2025-09-08 13:08:11 +02:00
- Optional C# debugging via `netcoredbg`
### Formatting
2025-09-08 13:10:01 +02:00
- Automatic `.gd` file formatting using [`gdtoolkit`](https://pypi.org/project/gdtoolkit/)
2025-09-08 13:08:11 +02:00
- Reloads buffer after formatting for immediate feedback
- Recommended `.editorconfig` included for consistent indentation (4 spaces per indent)
### Health Checks
- `:checkhealth godotdev` validates:
- Required dependencies: `nvim-lspconfig`, `nvim-dap`, `nvim-dap-ui`, `nvim-treesitter`
- Godot editor LSP and debug servers
- Optional C# tooling: `dotnet`, `csharp-ls`/OmniSharp, `netcoredbg`
- Formatter: `gdformat` (with installation instructions)
- Detects common issues like mixed indentation in GDScript/C# files
### Editor Integration
- Commands to start or reconnect to Godots editor LSP:
- `:GodotStartEditorServer`
- `:GodotReconnectLSP`
- 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()`
- Health checks and DAP integration included
- Supports cross-platform debugging and LSP integration
2025-08-20 18:07:10 +02:00
## Requirements
2025-09-08 10:16:54 +02:00
- Neovim 0.11+
- Godot 4.x+ with TCP LSP enabled
- `nvim-lspconfig`
- `nvim-dap` and `nvim-dap-ui` for debugging
- `nvim-treesitter`
- Windows users must have [`ncat`](https://nmap.org/ncat/) in PATH
2025-08-22 11:49:38 +02:00
- Optional C# support requires:
- .NET SDK (dotnet)
- C# LSP server (csharp-ls recommended or omnisharp)
- netcoredbg debugger
2025-08-20 18:07:10 +02:00
## Installation (Lazy.nvim)
2025-08-20 18:07:10 +02:00
```lua
{
2025-08-20 18:07:10 +02:00
'Mathijs-Bakker/godotdev.nvim',
dependencies = { 'nvim-lspconfig', 'nvim-dap', 'nvim-dap-ui', 'nvim-treesitter' },
2025-08-20 18:07:10 +02:00
}
```
2025-08-21 10:48:00 +02:00
## Quickstart
1. Open your Godot project in Neovim
1. Start Godot editor with TCP LSP enabled (Editor Settings → Network → Enable TCP LSP server)
2025-08-22 11:49:38 +02:00
1. Open a `.gd` or `.gdshader` file
1. LSP will automatically attach
2025-08-22 11:49:38 +02:00
1. Use `<leader>rn` to rename, `gd` to go to definition, `gr` for references, etc.
1. Start debugging with DAP (Launch scene configuration)
2025-08-22 11:49:38 +02:00
1. Optional: Enable C# support by setting `csharp = true` in the plugin setup
1. Run `:checkhealth godotdev` at any time to verify plugin, LSP, debug server, and C# dependencies
## Configuration
2025-08-21 18:05:23 +02:00
### Optional settings
2025-08-21 10:48:00 +02:00
```lua
vim.lsp.config("godotdev") = {
editor_host = "127.0.0.1", -- Godot editor host
2025-08-22 11:56:26 +02:00
editor_port = 6005, -- Godot LSP port
debug_port = 6006, -- Godot debugger port
csharp = true, -- Enable C# Installation Support
2025-09-08 10:16:54 +02:00
autostart_editor_server = true, -- Enable auto start Nvim server
}
2025-08-21 10:48:00 +02:00
```
2025-08-21 18:05:23 +02:00
### 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**.
2025-08-21 19:10:48 +02:00
- `Editor Settings > Text Editor > Behavior > Auto Reload Scripts on External Change`
2025-08-22 14:01:23 +02:00
<details><summary>Show Screenshot -> Godot Editor Settings</summary><img src="assets/godot-editor-auto-reload-script.png"></details>
2025-08-21 19:10:48 +02:00
- `Editor Settings > Interface > Editor > Save on Focus Loss`
2025-08-22 14:01:23 +02:00
<details><summary>Show Screenshot -> Godot Editor Settings</summary><img src="assets/godot-editor-focus.png"></details>
2025-08-21 19:10:48 +02:00
- `Editor Settings > Interface > Editor > Import Resources When Unfocused`
2025-08-21 18:05:23 +02:00
2025-08-22 14:01:23 +02:00
<details><summary>Show Screenshot -> Godot Editor Settings</summary><img src="assets/godot-editor-focus.png"></details>
2025-08-21 18:55:46 +02:00
### Open .gdscript/.gdshader from Godot in Neovim
When you click on a gdscript in Godot's FileSystem dock it doesn't open automatically in Neovim.
A [workaround](doc/neovim-external-editor-setup.md) is to to create a small script which launches the file in Neovim.
2025-08-21 18:55:46 +02:00
2025-09-01 13:01:33 +02:00
#### >> macOS/Linux
Complete instructions [here](doc/neovim-external-editor-setup.md)
2025-08-21 18:55:46 +02:00
2025-09-01 13:01:33 +02:00
#### >> Windows
2025-08-21 19:10:48 +02:00
2025-08-21 18:55:46 +02:00
1. Set Neovim to listen on a TCP port
```bash
nvim --listen 127.0.0.1:6666
```
--listen works with host:port on Windows.
1. 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.
2025-09-08 10:16:54 +02:00
## Godot editor server
You can manually start the Neovim editor server used by Godot:
```vim
:GodotStartEditorServer
```
Or automatically on plugin setup:
```lua
require("godotdev").setup({
autostart_editor_server = true,
})
```
This ensures Godot can communicate with Neovim as an external editor.
2025-09-01 13:01:33 +02:00
## Reconnect to Godot's LSP server
2025-09-08 10:16:54 +02:00
If the LSP disconnects or you opened a script before Neovim, run:
```vim
:GodotReconnectLSP
```
Reconnects **all Godot buffers** to the LSP.
2025-09-01 13:01:33 +02:00
2025-08-22 11:56:26 +02:00
## C# Installation Support
2025-08-20 18:07:10 +02:00
2025-08-22 11:49:38 +02:00
- Enable by setting `csharp = true` in `require("godotdev").setup()`
- Health checks via `:checkhealth godotdev` will verify:
- .NET SDK (`dotnet`)
- C# LSP server (`csharp-ls` or `omnisharp`)
- Debugger (`netcoredbg`)
2025-09-08 10:16:54 +02:00
## Autoformatting / Indentation
Godot expects **spaces, 4 per indent** (for both GDScript and C#).
2025-09-08 10:16:54 +02:00
This plugin automatically sets buffer options for `.gd` files.
2025-09-08 13:11:38 +02:00
Additionally, `.gd` files are autoformatted on save with [`gdtoolkit`](https://github.com/godotengine/gdtoolkit):
2025-09-08 10:16:54 +02:00
```vim
:w
```
2025-09-08 10:16:54 +02:00
Make sure `gdformat` is installed and in your PATH. If not, you will see a warning notification.
For more info on indentation: `:help godotdev-indent`
2025-08-24 13:20:08 +02:00
2025-10-02 15:32:39 +02:00
## 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](https://github.com/stevearc/oil.nvim) and [mini.files](https://github.com/nvim-mini/mini.nvim
) by filtering against their patterns.
[Show me how](doc/hide-files-in-file-explorers.md)
2025-08-28 16:53:10 +02:00