- Lua 99.9%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| doc | ||
| lsp | ||
| lua/jpa | ||
| plugin | ||
| tests | ||
| .gitignore | ||
| .luarc.json | ||
| .stylua.toml | ||
| LICENSE | ||
| Makefile | ||
| README.md | ||
jpa.nvim
JPA helpers for Neovim in the style of IntelliJ IDEA Ultimate and JPA Buddy. The
features are offered as LSP code actions (through a small in-process language
server) and as :Jpa subcommands. Spring Boot, Quarkus (including Panache) and
Micronaut projects built with Maven or Gradle are supported.
Features:
- Generate a Liquibase changeset from an entity (createTable, sequences, foreign keys, join tables, indexes, unique constraints).
- Generate an addColumn changeset for the field under the cursor or the selected fields.
- Create an entity class from a
CREATE TABLEstatement in a SQL buffer. - Generate a DTO, a repository,
equals/hashCode,toString, and explicit@Table/@Columnnames for an entity.
Requirements
- Neovim 0.11 or newer
- The
javatreesitter parser - Optional: liquibase.nvim for the Liquibase related actions. Without it, only the code generation features are offered.
Installation
With lazy.nvim:
{
url = "https://git.bivashy.dev/bivashy/jpa.nvim",
dependencies = { { url = "https://git.bivashy.dev/bivashy/liquibase.nvim" } }, -- optional
ft = { "java", "sql" },
}
For a local checkout use dir = "~/path/to/jpa.nvim" instead of url.
Usage
Place the cursor in an entity class and run vim.lsp.buf.code_action(), or use
a subcommand:
| Subcommand | Description |
|---|---|
changeset |
Liquibase changeset for the entity (file saves it) |
add-column |
addColumn changeset for the field or range (file) |
entity |
Entity class from the CREATE TABLE statement at cursor |
dto |
DTO for the entity |
repository |
Repository interface for the entity |
equals-hashcode |
Generate equals and hashCode |
tostring |
Generate toString |
explicit-names |
Add explicit table and column names |
info |
Show the detected project and entity |
No keymaps are defined. The following mappings are available (normal and
visual mode): <Plug>(jpa-changeset), <Plug>(jpa-add-column),
<Plug>(jpa-entity), <Plug>(jpa-dto), <Plug>(jpa-repository),
<Plug>(jpa-equals-hashcode), <Plug>(jpa-tostring),
<Plug>(jpa-explicit-names).
vim.keymap.set({ "n", "x" }, "<leader>jc", "<Plug>(jpa-changeset)")
The language server attaches to Java buffers that contain an @Entity,
@Embeddable or @MappedSuperclass annotation or a JPA import, and to SQL
buffers.
Configuration
No setup() call is required. Set vim.g.jpa to a table (or a function
returning one) before the plugin loads. require("jpa").setup(opts) is
equivalent.
vim.g.jpa = {
lsp = true,
naming = nil, -- nil: "snake_case" for Spring, "as_is" otherwise; or fun(name): string
string_length = 255,
entity = { style = nil, subpackage = nil }, -- style: "panache"|"lombok"|"public_fields"|"getters"
dto = { suffix = "Dto", subpackage = "dto", record = true },
repository = { suffix = "Repository", subpackage = "repository" },
}
See :help jpa for all options.
Health check
Run :checkhealth jpa to verify the Neovim version, the treesitter parser,
liquibase.nvim, the configuration and the detected project.
Tests
make test
NVIM_TEST_RTP=/path/to/liquibase.nvim make test # includes Liquibase specs