Skip to content

Commit 899bb36

Browse files
add documentation for Neovim 0.11+ and remove existing plugin (#328)
1 parent cbd2c77 commit 899bb36

File tree

6 files changed

+143
-87
lines changed

6 files changed

+143
-87
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,22 @@ and this project attempts to adhere to [Semantic Versioning](https://semver.org/
2424
- Added documentation for VS Code extension
2525
- Added documentation for Zed extension
2626
- Added documentation for setting up Sublime Text
27+
- Added documentation for setting up Neovim 0.11+ using `vim.lsp.config()` and `vim.lsp.enable()`
2728

2829
### Changed
2930

3031
- Changed user configuration directory paths to use application name only, removing organization identifiers
3132
- **Internal**: Refactored workspace to use domain types (`FileKind`) instead of LSP types (`LanguageId`)
3233
- **Internal**: Added client detection for LSP-specific workarounds (e.g., Sublime Text's `html` language ID handling)
3334

35+
### Deprecated
36+
37+
- Deprecated `lazy.lua` Neovim plugin spec. It now only shows a migration warning and will be removed in the next release. See [Neovim client docs](docs/clients/neovim.md) for the new Neovim 0.11+ configuration approach.
38+
39+
### Removed
40+
41+
- Removed `clients/nvim/` directory. Neovim 0.11+ has built-in LSP configuration via `vim.lsp.config()` which replaces the need for the custom plugin.
42+
3443
## [5.2.3]
3544

3645
### Added

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ The package provides pre-built wheels with the Rust-based LSP server compiled fo
105105

106106
The Django Language Server works with any editor that supports the Language Server Protocol (LSP). We currently have setup instructions for:
107107

108-
- [Neovim](clients/nvim/README.md)
108+
- [Neovim](docs/clients/neovim.md)
109109
- [Sublime Text](docs/clients/sublime-text.md)
110110
- [VS Code](docs/clients/vscode.md)
111111
- [Zed](docs/clients/zed.md)

clients/nvim/README.md

Lines changed: 0 additions & 52 deletions
This file was deleted.

clients/nvim/lua/djls/init.lua

Lines changed: 0 additions & 27 deletions
This file was deleted.

docs/clients/neovim.md

Lines changed: 127 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,130 @@
22
title: Neovim
33
---
44

5-
{% include-markdown "../../clients/nvim/README.md" %}
5+
# Neovim
6+
7+
## Requirements
8+
9+
- Neovim 0.11+
10+
- Django Language Server (`djls`) installed on your system. See [Installation](../index.md#installation).
11+
12+
## Configuration
13+
14+
The server can be configured using Neovim's built-in [`vim.lsp.config()`](https://neovim.io/doc/user/lsp.html#lsp-config).
15+
16+
You can define the configuration inline in your `init.lua`:
17+
18+
```lua
19+
-- In init.lua
20+
vim.lsp.config('djls', {
21+
cmd = { 'djls', 'serve' },
22+
filetypes = { 'htmldjango', 'html', 'python' },
23+
root_markers = { 'manage.py', 'pyproject.toml' },
24+
single_file_support = true,
25+
})
26+
27+
vim.lsp.enable('djls')
28+
```
29+
30+
Or create a dedicated config file in your runtimepath at `lsp/djls.lua`:
31+
32+
```lua
33+
-- In <rtp>/lsp/djls.lua (e.g., ~/.config/nvim/lsp/djls.lua)
34+
return {
35+
cmd = { 'djls', 'serve' },
36+
filetypes = { 'htmldjango', 'html', 'python' },
37+
root_markers = { 'manage.py', 'pyproject.toml' },
38+
single_file_support = true,
39+
}
40+
```
41+
42+
Then just enable it in your `init.lua`:
43+
44+
```lua
45+
-- In init.lua
46+
vim.lsp.enable('djls')
47+
```
48+
49+
### Django Settings
50+
51+
For Django project settings and other server options, see [Configuration](../configuration.md).
52+
53+
To pass settings via Neovim's LSP client, use `init_options`:
54+
55+
```lua
56+
vim.lsp.config('djls', {
57+
-- ... basic config from above
58+
init_options = {
59+
django_settings_module = "myproject.settings",
60+
venv_path = "/path/to/venv",
61+
},
62+
})
63+
```
64+
65+
### File Type Detection
66+
67+
Django templates need the correct filetype for LSP activation. The simplest approach is a pattern match:
68+
69+
```lua
70+
vim.filetype.add({
71+
pattern = {
72+
[".*/templates/.*%.html"] = "htmldjango",
73+
},
74+
})
75+
```
76+
77+
For more intelligent detection that checks if an HTML file is actually in a Django project by walking up the directory tree from the file's location to find Django project markers (`manage.py` or `pyproject.toml` with django):
78+
79+
```lua
80+
-- Detect Django projects
81+
local function is_django_project(path)
82+
local current = path
83+
while current ~= "/" do
84+
-- Check for manage.py
85+
if vim.fn.filereadable(current .. "/manage.py") == 1 then
86+
return true
87+
end
88+
89+
-- Check for pyproject.toml with django dependency
90+
-- Note: This is a naive check that just searches for "django" in the file.
91+
-- A more robust approach would parse the TOML and check dependencies properly.
92+
local pyproject = current .. "/pyproject.toml"
93+
if vim.fn.filereadable(pyproject) == 1 then
94+
local content = vim.fn.readfile(pyproject)
95+
for _, line in ipairs(content) do
96+
if line:match("django") then
97+
return true
98+
end
99+
end
100+
end
101+
102+
current = vim.fn.fnamemodify(current, ":h")
103+
end
104+
return false
105+
end
106+
107+
-- Auto-detect htmldjango filetype for Django projects
108+
vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, {
109+
pattern = "*.html",
110+
callback = function(args)
111+
local file_dir = vim.fn.fnamemodify(args.file, ":p:h")
112+
if is_django_project(file_dir) then
113+
vim.bo[args.buf].filetype = "htmldjango"
114+
end
115+
end,
116+
})
117+
```
118+
119+
## Using with nvim-lspconfig
120+
121+
[nvim-lspconfig](https://github.com/neovim/nvim-lspconfig) does not currently include a `djls` configuration, but we plan to submit one. Once available, if you have nvim-lspconfig installed, it will provide the configuration automatically and you can skip defining it yourself.
122+
123+
## Troubleshooting
124+
125+
Run `:checkhealth vim.lsp` to diagnose issues.
126+
127+
Common problems:
128+
129+
- **Server not starting**: Verify `djls` is installed (`which djls`)
130+
- **No completions**: Check that `DJANGO_SETTINGS_MODULE` is configured
131+
- **Wrong filetype**: Verify with `:set filetype?` that templates show `htmldjango` or `django-html`

lazy.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
return {
22
"joshuadavidthomas/django-language-server",
3-
dependencies = {
4-
"neovim/nvim-lspconfig",
5-
},
6-
config = function(plugin, opts)
7-
vim.opt.rtp:append(plugin.dir .. "/clients/nvim")
8-
require("djls").setup(opts)
3+
config = function()
4+
vim.notify(
5+
"lazy.lua spec for django-language-server is deprecated and will be removed in the next release.\n" ..
6+
"See https://github.com/joshuadavidthomas/django-language-server/blob/main/docs/clients/neovim.md for the new configuration using vim.lsp.config() and vim.lsp.enable().",
7+
vim.log.levels.WARN
8+
)
99
end,
1010
}

0 commit comments

Comments
 (0)