diff --git a/README.md b/README.md index eeaaaac..690bba3 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/docs/editor-setup/neovim.md b/docs/editor-setup/neovim.md deleted file mode 100644 index 7ec734d..0000000 --- a/docs/editor-setup/neovim.md +++ /dev/null @@ -1,55 +0,0 @@ -# Neovim - -Using and : - -```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. diff --git a/docs/editors/neovim.md b/docs/editors/neovim.md new file mode 100644 index 0000000..37e47d3 --- /dev/null +++ b/docs/editors/neovim.md @@ -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 = {}, +} +``` diff --git a/docs/index.md b/docs/index.md index 326b49f..803cb82 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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) diff --git a/docs/processor.py b/docs/processor.py index adcdf50..43298af 100644 --- a/docs/processor.py +++ b/docs/processor.py @@ -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__": diff --git a/editors/nvim/README.md b/editors/nvim/README.md new file mode 100644 index 0000000..f20b7ac --- /dev/null +++ b/editors/nvim/README.md @@ -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 = {}, +} +``` diff --git a/editors/nvim/lua/djls/init.lua b/editors/nvim/lua/djls/init.lua new file mode 100644 index 0000000..db88426 --- /dev/null +++ b/editors/nvim/lua/djls/init.lua @@ -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 diff --git a/lazy.lua b/lazy.lua new file mode 100644 index 0000000..a1b1c4c --- /dev/null +++ b/lazy.lua @@ -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, +}