Skip to content

Commit accb8fd

Browse files
add neovim plugin (#59)
1 parent d9d0f4e commit accb8fd

File tree

8 files changed

+176
-65
lines changed

8 files changed

+176
-65
lines changed

README.md

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

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

73-
- [Neovim](docs/editor-setup/neovim.md)
73+
- [Neovim](docs/editors/neovim.md)
7474

7575
Got it working in your editor? [Help us add setup instructions!](#testing-and-documenting-editor-setup)
7676

docs/editor-setup/neovim.md

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

docs/editors/neovim.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: Neovim
3+
---
4+
5+
# djls.nvim
6+
7+
A Neovim plugin for the Django Language Server.
8+
9+
!!! note
10+
11+
This plugin is a temporary solution until the project is mature enough to be integrated into [mason.nvim](https://github.com/williamboman/mason.nvim) and [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig).
12+
13+
## Installation
14+
15+
### [lazy.nvim](https://github.com/folke/lazy.nvim)
16+
17+
Minimal setup:
18+
19+
```lua
20+
{
21+
"joshuadavidthomas/django-language-server",
22+
}
23+
```
24+
25+
The plugin takes advantage of lazy.nvim's spec loading by providing a `lazy.lua` at the root of the repository to handle setup and runtime path configuration automatically. This handles adding the plugin subdirectory to Neovim's runtime path and initializing the LSP client:
26+
27+
```lua
28+
{
29+
"joshuadavidthomas/django-language-server",
30+
dependencies = {
31+
"neovim/nvim-lspconfig",
32+
},
33+
config = function(plugin, opts)
34+
vim.opt.rtp:append(plugin.dir .. "/editors/nvim")
35+
require("djls").setup(opts)
36+
end,
37+
}
38+
```
39+
40+
The spec can also serve as a reference for a more detailed installation if needed or desired.
41+
42+
## Configuration
43+
44+
Default configuration options:
45+
46+
```lua
47+
{
48+
cmd = { "djls", "serve" },
49+
filetypes = { "django-html", "htmldjango", "python" },
50+
root_dir = function(fname)
51+
local util = require("lspconfig.util")
52+
local root = util.root_pattern("manage.py", "pyproject.toml")(fname)
53+
return root or vim.fn.getcwd()
54+
end,
55+
settings = {},
56+
}
57+
```

docs/index.md

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

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

79-
- [Neovim](editor-setup/neovim.md)
79+
- [Neovim](editors/neovim.md)
8080

8181
Got it working in your editor? [Help us add setup instructions!](#testing-and-documenting-editor-setup)
8282

docs/processor.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -499,28 +499,48 @@ def replace_link(match: re.Match[str]) -> str:
499499

500500

501501
def main():
502-
console.print("[bold blue]File Processor[/bold blue]")
502+
"""Process documentation files."""
503+
console.print("[bold blue]Documentation Processor[/bold blue]")
503504

504-
processors = [
505-
add_frontmatter({"title": "Home"}),
505+
common_processors = [
506506
convert_admonitions,
507507
convert_repo_links(
508508
"https://github.com/joshuadavidthomas/django-language-server"
509509
),
510510
]
511511

512-
success = process_file(
512+
readme_success = process_file(
513513
input="README.md",
514514
output="docs/index.md",
515-
processors=processors,
515+
processors=[
516+
add_frontmatter({"title": "Home"}),
517+
*common_processors,
518+
],
516519
preview=True,
517520
description="README.md → docs/index.md",
518521
)
519522

520-
if success:
521-
console.print("\n[green]✨ Processing completed successfully![/green]")
523+
nvim_success = process_file(
524+
input="editors/nvim/README.md",
525+
output="docs/editors/neovim.md",
526+
processors=[
527+
add_frontmatter({"title": "Neovim"}),
528+
*common_processors,
529+
],
530+
preview=True,
531+
description="Neovim docs → docs/editors/neovim.md",
532+
)
533+
534+
if readme_success and nvim_success:
535+
console.print("\n[green]✨ All files processed successfully![/green]")
522536
else:
523-
console.print("\n[red]Processing failed![/red]")
537+
console.print("\n[red]Some files failed to process:[/red]")
538+
for name, success in [
539+
("README.md → docs/index.md", readme_success),
540+
("Neovim docs → docs/editors/neovim.md", nvim_success),
541+
]:
542+
status = "[green]✓[/green]" if success else "[red]✗[/red]"
543+
console.print(f"{status} {name}")
524544

525545

526546
if __name__ == "__main__":

editors/nvim/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# djls.nvim
2+
3+
A Neovim plugin for the Django Language Server.
4+
5+
> [!NOTE]
6+
> This plugin is a temporary solution until the project is mature enough to be integrated into [mason.nvim](https://github.com/williamboman/mason.nvim) and [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig).
7+
8+
## Installation
9+
10+
### [lazy.nvim](https://github.com/folke/lazy.nvim)
11+
12+
Minimal setup:
13+
14+
```lua
15+
{
16+
"joshuadavidthomas/django-language-server",
17+
}
18+
```
19+
20+
The plugin takes advantage of lazy.nvim's spec loading by providing a `lazy.lua` at the root of the repository to handle setup and runtime path configuration automatically. This handles adding the plugin subdirectory to Neovim's runtime path and initializing the LSP client:
21+
22+
```lua
23+
{
24+
"joshuadavidthomas/django-language-server",
25+
dependencies = {
26+
"neovim/nvim-lspconfig",
27+
},
28+
config = function(plugin, opts)
29+
vim.opt.rtp:append(plugin.dir .. "/editors/nvim")
30+
require("djls").setup(opts)
31+
end,
32+
}
33+
```
34+
35+
The spec can also serve as a reference for a more detailed installation if needed or desired.
36+
37+
## Configuration
38+
39+
Default configuration options:
40+
41+
```lua
42+
{
43+
cmd = { "djls", "serve" },
44+
filetypes = { "django-html", "htmldjango", "python" },
45+
root_dir = function(fname)
46+
local util = require("lspconfig.util")
47+
local root = util.root_pattern("manage.py", "pyproject.toml")(fname)
48+
return root or vim.fn.getcwd()
49+
end,
50+
settings = {},
51+
}
52+
```

editors/nvim/lua/djls/init.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
local M = {}
2+
3+
M.defaults = {
4+
cmd = { "djls", "serve" },
5+
filetypes = { "django-html", "htmldjango", "python" },
6+
root_dir = function(fname)
7+
local util = require("lspconfig.util")
8+
local root = util.root_pattern("manage.py", "pyproject.toml")(fname)
9+
return root or vim.fn.getcwd()
10+
end,
11+
settings = {},
12+
}
13+
14+
function M.setup(opts)
15+
opts = vim.tbl_deep_extend("force", M.defaults, opts or {})
16+
17+
local configs = require("lspconfig.configs")
18+
if not configs.djls then
19+
configs.djls = {
20+
default_config = opts,
21+
}
22+
end
23+
24+
require("lspconfig").djls.setup(opts)
25+
end
26+
27+
return M

lazy.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
return {
2+
"joshuadavidthomas/django-language-server",
3+
dependencies = {
4+
"neovim/nvim-lspconfig",
5+
},
6+
config = function(plugin, opts)
7+
vim.opt.rtp:append(plugin.dir .. "/editors/nvim")
8+
require("djls").setup(opts)
9+
end,
10+
}

0 commit comments

Comments
 (0)