add neovim plugin (#59)

This commit is contained in:
Josh Thomas 2025-01-03 08:55:54 -06:00 committed by GitHub
parent d9d0f4ee87
commit accb8fdfb4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 176 additions and 65 deletions

View file

@ -70,7 +70,7 @@ The package provides pre-built wheels with the Rust-based LSP server compiled fo
The Django Language Server works with any editor that supports the Language Server Protocol (LSP). We currently have setup instructions for:
- [Neovim](docs/editor-setup/neovim.md)
- [Neovim](docs/editors/neovim.md)
Got it working in your editor? [Help us add setup instructions!](#testing-and-documenting-editor-setup)

View file

@ -1,55 +0,0 @@
# Neovim
Using <https://github.com/folke/lazy.nvim> and <https://github.com/neovim/nvim-lspconfig>:
```lua
{
"neovim/nvim-lspconfig",
opts = {
servers = {
djls = {},
},
setup = {
djls = function(_, opts)
local configs = require("lspconfig.configs")
local util = require("lspconfig.util")
if not configs.djls then
configs.djls = {
default_config = {
cmd = { "djls", "serve" },
filetypes = { "htmldjango" },
root_dir = function(fname)
local root = util.root_pattern("manage.py", "pyproject.toml")(fname)
vim.notify("LSP root dir: " .. (root or "nil"))
return root or vim.fn.getcwd()
end,
handlers = {
["window/logMessage"] = function(_, params, _)
local message_type = {
[1] = vim.log.levels.ERROR,
[2] = vim.log.levels.WARN,
[3] = vim.log.levels.INFO,
[4] = vim.log.levels.DEBUG,
}
vim.notify(params.message, message_type[params.type], {
title = "djls",
})
end,
},
on_attach = function(client, bufnr)
vim.notify("djls attached to buffer: " .. bufnr)
end,
},
}
end
require("lspconfig").djls.setup({})
end,
},
},
}
```
!!! note
This configuration is copied straight from my Neovim setup and includes a logging setup that sends LSP messages to Neovim's notification system. You can remove all the references to `vim.notify` if you don't care about this functionality.

57
docs/editors/neovim.md Normal file
View file

@ -0,0 +1,57 @@
---
title: Neovim
---
# djls.nvim
A Neovim plugin for the Django Language Server.
!!! note
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).
## Installation
### [lazy.nvim](https://github.com/folke/lazy.nvim)
Minimal setup:
```lua
{
"joshuadavidthomas/django-language-server",
}
```
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:
```lua
{
"joshuadavidthomas/django-language-server",
dependencies = {
"neovim/nvim-lspconfig",
},
config = function(plugin, opts)
vim.opt.rtp:append(plugin.dir .. "/editors/nvim")
require("djls").setup(opts)
end,
}
```
The spec can also serve as a reference for a more detailed installation if needed or desired.
## Configuration
Default configuration options:
```lua
{
cmd = { "djls", "serve" },
filetypes = { "django-html", "htmldjango", "python" },
root_dir = function(fname)
local util = require("lspconfig.util")
local root = util.root_pattern("manage.py", "pyproject.toml")(fname)
return root or vim.fn.getcwd()
end,
settings = {},
}
```

View file

@ -76,7 +76,7 @@ The package provides pre-built wheels with the Rust-based LSP server compiled fo
The Django Language Server works with any editor that supports the Language Server Protocol (LSP). We currently have setup instructions for:
- [Neovim](editor-setup/neovim.md)
- [Neovim](editors/neovim.md)
Got it working in your editor? [Help us add setup instructions!](#testing-and-documenting-editor-setup)

View file

@ -499,28 +499,48 @@ def convert_repo_links(repo_url: str) -> ProcessingFunc:
def main():
console.print("[bold blue]File Processor[/bold blue]")
"""Process documentation files."""
console.print("[bold blue]Documentation Processor[/bold blue]")
processors = [
add_frontmatter({"title": "Home"}),
common_processors = [
convert_admonitions,
convert_repo_links(
"https://github.com/joshuadavidthomas/django-language-server"
),
]
success = process_file(
readme_success = process_file(
input="README.md",
output="docs/index.md",
processors=processors,
processors=[
add_frontmatter({"title": "Home"}),
*common_processors,
],
preview=True,
description="README.md → docs/index.md",
)
if success:
console.print("\n[green]✨ Processing completed successfully![/green]")
nvim_success = process_file(
input="editors/nvim/README.md",
output="docs/editors/neovim.md",
processors=[
add_frontmatter({"title": "Neovim"}),
*common_processors,
],
preview=True,
description="Neovim docs → docs/editors/neovim.md",
)
if readme_success and nvim_success:
console.print("\n[green]✨ All files processed successfully![/green]")
else:
console.print("\n[red]Processing failed![/red]")
console.print("\n[red]Some files failed to process:[/red]")
for name, success in [
("README.md → docs/index.md", readme_success),
("Neovim docs → docs/editors/neovim.md", nvim_success),
]:
status = "[green]✓[/green]" if success else "[red]✗[/red]"
console.print(f"{status} {name}")
if __name__ == "__main__":

52
editors/nvim/README.md Normal file
View file

@ -0,0 +1,52 @@
# djls.nvim
A Neovim plugin for the Django Language Server.
> [!NOTE]
> 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).
## Installation
### [lazy.nvim](https://github.com/folke/lazy.nvim)
Minimal setup:
```lua
{
"joshuadavidthomas/django-language-server",
}
```
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:
```lua
{
"joshuadavidthomas/django-language-server",
dependencies = {
"neovim/nvim-lspconfig",
},
config = function(plugin, opts)
vim.opt.rtp:append(plugin.dir .. "/editors/nvim")
require("djls").setup(opts)
end,
}
```
The spec can also serve as a reference for a more detailed installation if needed or desired.
## Configuration
Default configuration options:
```lua
{
cmd = { "djls", "serve" },
filetypes = { "django-html", "htmldjango", "python" },
root_dir = function(fname)
local util = require("lspconfig.util")
local root = util.root_pattern("manage.py", "pyproject.toml")(fname)
return root or vim.fn.getcwd()
end,
settings = {},
}
```

View file

@ -0,0 +1,27 @@
local M = {}
M.defaults = {
cmd = { "djls", "serve" },
filetypes = { "django-html", "htmldjango", "python" },
root_dir = function(fname)
local util = require("lspconfig.util")
local root = util.root_pattern("manage.py", "pyproject.toml")(fname)
return root or vim.fn.getcwd()
end,
settings = {},
}
function M.setup(opts)
opts = vim.tbl_deep_extend("force", M.defaults, opts or {})
local configs = require("lspconfig.configs")
if not configs.djls then
configs.djls = {
default_config = opts,
}
end
require("lspconfig").djls.setup(opts)
end
return M

10
lazy.lua Normal file
View file

@ -0,0 +1,10 @@
return {
"joshuadavidthomas/django-language-server",
dependencies = {
"neovim/nvim-lspconfig",
},
config = function(plugin, opts)
vim.opt.rtp:append(plugin.dir .. "/editors/nvim")
require("djls").setup(opts)
end,
}