Update NVIM for mariadb

This commit is contained in:
alejo committed 2026-09-30 16:29:04 -03:00
1 parent 361e1c9b51
commit 87a23b7f30
29 files changed
+1934 -1492

No files matched your search

+120 -4
View File
@@ -8,6 +8,7 @@ Supports **Fedora, Ubuntu, Debian, and Arch Linux** (and their common derivative
- [Installing](#installing)
- [What gets installed](#what-gets-installed)
- [Config layout & adding plugins](#config-layout--adding-plugins)
- [Terminal vs. desktop (Neovide)](#terminal-vs-desktop-neovide)
- [Editor basics](#editor-basics)
- [Look & feel](#look--feel)
@@ -21,6 +22,7 @@ Supports **Fedora, Ubuntu, Debian, and Arch Linux** (and their common derivative
- [Debugging (nvim-dap)](#debugging-nvim-dap)
- [Terminal](#terminal)
- [Git](#git)
- [Database (MariaDB)](#database-mariadb)
- [Hex viewer](#hex-viewer)
- [Formatting and linting](#formatting-and-linting)
- [Known quirks](#known-quirks)
@@ -56,8 +58,8 @@ First launch takes a minute or two: `lazy.nvim` bootstraps itself and installs a
Package names vary by distro (see the script for the exact list per package manager), but the same set gets installed everywhere:
- **Compilers/tools**: gcc, g++, make, cmake, clang tooling, lldb, gdb, .NET SDK 8.0, Go, nodejs/npm, python3-pip
- **CLI tools**: ripgrep, fd, git, curl, wget, unzip, fish (used only for Neovim's embedded terminal — see [Terminal](#terminal))
- **Language servers**: clangd, gopls, omnisharp, ts_ls, html, cssls (via Mason), plus `typescript-language-server` and `vscode-langservers-extracted` via npm
- **CLI tools**: ripgrep, fd, git, curl, wget, unzip, fish (used only for Neovim's embedded terminal — see [Terminal](#terminal)), and the MariaDB *client* (`mariadb`; client only, no server — see [Database (MariaDB)](#database-mariadb))
- **Language servers**: clangd, gopls, omnisharp, ts_ls, html, cssls, sqls (via Mason), plus `typescript-language-server` and `vscode-langservers-extracted` via npm
- **Debug adapter**: codelldb (auto-installed by Mason on first debug session)
- **Neovide**, optionally — see [Terminal vs. desktop (Neovide)](#terminal-vs-desktop-neovide)
@@ -65,11 +67,51 @@ Everything the script *writes* rather than installs comes from `config/`, copied
| `config/` | Copied to |
|---|---|
| `nvim/init.lua`, `nvim/lua/plugins/init.lua`, `nvim/lua/dap/configurations/cmake.lua` | `~/.config/nvim/...` (same layout) |
| `nvim/` — the whole tree: `init.lua`, `lua/plugins/*.lua`, `lua/config/…`, `lua/dap/…` (see [Config layout](#config-layout--adding-plugins)) | `~/.config/nvim/...` (same layout) |
| `clang-format` | `~/.clang-format` |
| `clang-tidy` | `~/.clang-tidy` |
| `cpp-style-guide.md` | `~/cpp-style-guide.md` |
## Config layout & adding plugins
```
config/nvim/
├── init.lua options, keymaps, Neovide settings, lazy.nvim bootstrap
└── lua/
├── plugins/ one file per plugin (or tightly coupled group)
│ ├── lsp.lua nvim-lspconfig + Mason
│ ├── completion.lua nvim-cmp + LuaSnip
│ ├── database.lua vim-dadbod + UI + completion (MariaDB)
│ ├── dap.lua nvim-dap + UI
│ └── … telescope, nvim-tree, bufferline, lualine, and so on
├── config/lsp/ helper modules that are *not* plugin specs
│ ├── servers.lua the list of language servers, plus per-server overrides
│ ├── keymaps.lua LSP keymaps, applied when a server attaches
│ └── commands.lua :LspRestart & co. for Neovim 0.12+
└── dap/configurations/ per-project debug targets (cmake.lua)
```
`init.lua` calls `require("lazy").setup("plugins")`, which makes lazy.nvim `require` every `.lua` file in `lua/plugins/` and merge what they return. Each file returns a list of plugin specs, the files don't depend on one another, and there is no central list to update. File order doesn't matter either: the colorscheme sets `priority = 1000`, and every plugin that calls into another one declares it as a dependency.
**Adding a plugin** means dropping a new file into `lua/plugins/`:
```lua
-- lua/plugins/my-plugin.lua
return {
{
"author/plugin.nvim",
event = "VeryLazy",
opts = {},
},
}
```
**Adding a language server** means adding one line to `lua/config/lsp/servers.lua` (`name = {},` — or with overrides inside the braces). That one table feeds both Mason's installer and `vim.lsp.enable()`, so there's no second list to keep in sync.
**Keep non-spec modules out of `lua/plugins/`.** lazy.nvim treats everything in that folder as a plugin spec, so a helper module placed there would be read as a (malformed) spec. Helpers go under `lua/config/` instead.
**If you copy these files over an existing `~/.config/nvim` by hand** rather than running the script (which wipes the directory first), delete the old `lua/plugins/init.lua` — lazy.nvim would still load it alongside the new files, and every plugin would be declared twice.
## Terminal vs. desktop (Neovide)
The installer asks which Neovim frontend(s) to set up:
@@ -172,7 +214,7 @@ Setting an explicit `<F1>` mapping here also overrides Neovim's built-in `<F1>`-
## LSP & code intelligence
Configured servers: **clangd** (C/C++), **gopls** (Go), **omnisharp** (C#), **ts_ls** (TS/JS), **html**, **cssls**. Diagnostics render as virtual lines directly below the offending line (not inline virtual text), with the message's leading category prefix stripped; diagnostic underlines are off.
Configured servers: **clangd** (C/C++), **gopls** (Go), **omnisharp** (C#), **ts_ls** (TS/JS), **html**, **cssls**, **sqls** (SQL — see [Database (MariaDB)](#database-mariadb)). The list lives in a single table, `lua/config/lsp/servers.lua`. Diagnostics render as virtual lines directly below the offending line (not inline virtual text), with the message's leading category prefix stripped; diagnostic underlines are off.
| Key | Action |
|---|---|
@@ -191,6 +233,18 @@ Configured servers: **clangd** (C/C++), **gopls** (Go), **omnisharp** (C#), **ts
| `]t` / `[t` | Jump to next/previous tip (LSP's "Hint" severity) |
| `<leader>cd` | Generate a Doxygen-style comment block — see [Documentation generation](#documentation-generation) |
**`:LspRestart` and friends.** Neovim 0.12 added a built-in `:lsp` command (`:lsp enable`, `:lsp disable`, `:lsp restart`, `:lsp stop`), and nvim-lspconfig responds by no longer registering its own `:LspStart` / `:LspStop` / `:LspRestart` / `:LspInfo` / `:LspLog` — so on 0.12 they simply don't exist (`E492: Not an editor command`). `lua/config/lsp/commands.lua` restores the old names as thin aliases over the built-ins:
| Command | Runs |
|---|---|
| `:LspRestart [client…]` | `:lsp restart [client…]` |
| `:LspStart [server…]` | `:lsp enable [server…]` |
| `:LspStop [server…]` | `:lsp disable [server…]` |
| `:LspInfo` (also `<leader>li`) | `:checkhealth vim.lsp` |
| `:LspLog` | opens the LSP log in a new tab |
Arguments are passed straight through and tab-complete (running clients for restart/stop, configured servers for start). On Neovim 0.11 and older there is no `:lsp`, nvim-lspconfig still provides the real commands itself, and the aliases stay out of the way.
**On `<leader>la` coming up thin:** clangd's code actions — and most of its clang-tidy checks — need real compiler flags (`-std=`, `-I`, defines) to do full semantic analysis. Without a `compile_commands.json` in the project, clangd falls back to guessed flags and the action list shrinks accordingly, often down to "No code actions available" everywhere. Generate one via CMake (`-DCMAKE_EXPORT_COMPILE_COMMANDS=ON`, then symlink or copy `build/compile_commands.json` to the project root) or `bear` for non-CMake projects.
**`<leader>lt` and the same compile database:** `<leader>lt` runs the standalone `clang-tidy` binary rather than going through clangd's code actions, so it never comes back "No code actions available" — it always runs. But it looks for that same `compile_commands.json` on its own (passed via clang-tidy's `-p` flag, found the same way as above), for the same underlying reason clangd wants one: without it, clang-tidy falls back to guessed flags and can miss checks that need real semantic analysis. It also uses `--fix` rather than `--fix-errors`, so it deliberately leaves the file untouched if clang-tidy hits real compiler errors, instead of forcing fixes onto code that doesn't currently compile.
@@ -219,6 +273,7 @@ The enclosing class is found via Treesitter by walking up from the cursor — no
- **`<CR>`**: confirm the selected completion.
- **`<Up>/<Down>/<Left>/<Right>/<Esc>`**: close the completion menu, then perform the normal cursor/escape action.
- Snippet sessions auto-close once the cursor actually leaves their text (different line, or outside the placeholder's parentheses) — so `Tab` won't unexpectedly jump back into an old, already-finished snippet later on.
- **SQL buffers** use their own source list: dadbod's table names, LSP (sqls), snippets, and buffer words (no path source). See [Database (MariaDB)](#database-mariadb).
## Documentation generation
@@ -260,6 +315,67 @@ Neovim's embedded terminal launches **fish** instead of your login shell, purely
`gitsigns` shows added/changed/removed lines in the sign column against the current git state.
## Database (MariaDB)
Two separate tools do two separate jobs here:
- **Connection and queries: [vim-dadbod](https://github.com/tpope/vim-dadbod) + [vim-dadbod-ui](https://github.com/kristijanhusak/vim-dadbod-ui).** Browse a server's tables in a sidebar, run queries, read the results in a split. dadbod doesn't speak the database protocol itself; it shells out to the `mariadb` command-line client, which the setup script installs. That's **the client only — no MariaDB server is installed or started**, so you need one running somewhere (local or remote).
- **Editing help: [sqls](https://github.com/sqls-server/sqls)**, a language server for SQL (completion, hover, formatting, code actions). There is no MariaDB-specific language server; sqls's MySQL driver speaks MariaDB's wire protocol and SQL flavor, which covers it. Mason installs it on first launch — it builds from source with `go install`, so Go has to be on `PATH` (the setup script installs it).
The two are independent: dadbod works without sqls, and sqls works without dadbod.
### Connecting
| Key | Action |
|---|---|
| `<leader>Du` | Toggle the DB UI sidebar |
| `<leader>Da` | Add a connection (same as pressing `A` inside the sidebar) |
| `<leader>Df` | Find the current buffer in the sidebar — or, for a buffer that wasn't opened from the DB UI (a plain `.sql` file), pick the connection it should run against (`:DBUIFindBuffer`) |
| `<leader>Dr` | Rename the current query buffer or saved query (a buffer has to have been written once first) |
| `<leader>Dl` | Print the last query that ran and how long it took |
`<leader>Da` asks for a URL and then a name:
```
mariadb://user:password@host:3306/dbname
```
Open the sidebar, pick a connection, and expand it to see its tables; expanding a table shows **List**, **Columns**, **Indexes**, and **Count** queries. Picking one writes the query into a buffer without running it; to write your own, choose *New query* under the connection. Either way, **saving the buffer runs it** (`:w`, and `<C-s>` works too), and dadbod-ui's own default `<leader>S` runs it without saving — the whole buffer, or only the visual selection if there is one. Results open in a split. Query buffers are temporary (they live in a temp folder and are cleared when Neovim quits) unless you save one with dadbod-ui's default `<leader>W`, which files it under the connection's *Saved queries*.
Details worth knowing:
- **Include the database name** in the URL: the sidebar lists the tables of that one database. For several databases on one server, add one connection each.
- **`localhost` vs `127.0.0.1`:** the client treats `localhost` as "use the local Unix socket" and `127.0.0.1` as "use TCP". Use whichever your server is actually set up for.
- **Special characters in the password** have to be percent-encoded in the URL (`@` → `%40`, `/` → `%2F`, and so on).
- **Keeping the password out of the URL:** leave it out and put `user=` / `password=` under `[client]` in `~/.my.cnf` instead — the `mariadb` client reads credentials from there.
- **Where connections are stored:** `~/.local/share/db_ui/connections.json`, **in plain text, password included**. That location is deliberately *outside* `~/.config/nvim` and `~/.local/share/nvim`, so re-running `setup_neovim.sh` (which wipes both) doesn't delete your connections. Nothing with credentials is ever written into the config files themselves.
- **Why `mariadb://` and not `mysql://`:** dadbod has a dedicated MariaDB adapter that runs the `mariadb` binary. The older `mysql://` scheme runs `mysql` instead, which MariaDB 11+ only ships as a deprecated alias that prints a "Deprecated program name" warning on every call — noise that ends up in query results and table lists. The trade-off is that dadbod-completion's column-level completion covers only some schemes (`mysql://` is one, `mariadb://` isn't), which is why columns come from sqls (below). Stick to `mysql://` for real MySQL servers.
### Language server (sqls)
sqls starts automatically in `sql`/`mysql` buffers and works out of the box for keyword completion and formatting (`<leader>lf`). For **table and column completion** it has to connect to the database *itself* — it does not share dadbod's connections — and it reads that from its own config file, `~/.config/sqls/config.yml`:
```yaml
lowercaseKeywords: false
connections:
- alias: local_mariadb
driver: mysql # MariaDB speaks the MySQL protocol
proto: tcp
host: 127.0.0.1
port: 3306
user: me
passwd: secret
dbName: mydb
```
The file holds a password in plain text, so `chmod 600 ~/.config/sqls/config.yml`. For a Unix-socket connection, swap the individual fields for a Go-MySQL DSN: `dataSourceName: me:secret@unix(/run/mysqld/mysqld.sock)/mydb` (the socket path varies by distro). After editing the file, `:LspRestart` restarts sqls so it picks the change up.
This file is deliberately *not* created by the setup script, so a half-filled template with a made-up password can't make sqls fail to connect on every start.
### Completion and syntax
In SQL buffers, completion draws on dadbod's table names (from the connection the buffer is attached to), sqls, snippets, and words already in the buffer. Vim's built-in SQL syntax is switched to its MySQL dialect (Vim defaults to Oracle's), the closest built-in match for MariaDB.
## Hex viewer
`<leader>h` toggles the current buffer between normal and hex-dump view (backed by `xxd`), rather than showing both simultaneously. That's deliberate: the hex dump is just ordinary buffer text under the hood, so editing it gets normal Neovim undo/redo for free, and nothing writes to disk until an explicit `:w` — same as any other file. A plugin doing a true live simultaneous hex+ASCII view was tried first, but it manages bytes with its own logic outside normal buffer editing, which is exactly why it had no undo at all.