An open API service indexing awesome lists of open source software.

https://github.com/esensar/neovim-java-plugin-host

Neovim Java plugin manager and host - Moved to https://codeberg.org/neovim-java/neovim-java-plugin-host
https://github.com/esensar/neovim-java-plugin-host

api java neovim neovim-java-plugin neovim-plugin plugin rpc

Last synced: 3 months ago
JSON representation

Neovim Java plugin manager and host - Moved to https://codeberg.org/neovim-java/neovim-java-plugin-host

Awesome Lists containing this project

README

          

# Java plugin host

Plugin enabling configuration of Neovim using Java and running JAR plugins.

**WORK IN PROGRESS - EXPERIMENTAL, USE AT YOUR OWN RISK!**

## Requirements

- [NeoVim](https://neovim.io) version 0.7.0+

## Installation

Install using favourite plugin manager.

e.g. Using [Packer.nvim](https://github.com/wbthomason/packer.nvim)

```
use { 'https://codeberg.org/neovim-java/neovim-java-plugin-host' }
```

## Usage

Call setup function and define plugins in it. The following shows default options:
```lua
require("java_plugin_host").setup {
rplugins = {
load_hosted = true, -- set to false to prevent loading hosted plugins from rplugin/hosted-jar
load_standalone = false, -- set to true to automatically load and start all plugins from rplugin/jar as standalone plugins
load_class = false, -- set to true to also load .class files from rplugin/java - useful for quick plugins
compile_java = false, -- set to true to compile .java files from rplugin/java - set load_class to true to also load them
},
common_host = {
enabled = true, -- set to false to disable common host and hosted plugins
-- Change to override default common plugins host
-- This is an executable jar which will be started and host all other plugins
-- Should be based on com.ensarsarajcic.neovim.java:plugin-host to work properly
-- Or it should be able to properly process annotations used for plugins
-- This field can also be defined as string, e.g. "com.ensarsarajcic.neovim.java:plugins-common-host:0.4.6"
name = {
group_id = "com.ensarsarajcic.neovim.java",
artifact_id = "plugins-common-host",
version = "0.4.6"
},
-- When changing common_host.name, this should also be changed to the main class
-- of the other artifact used as common host
main_class_name = "com.ensarsarajcic.neovim.java.commonhost.CommonPluginHost",
-- List hosted plugins here - artifacts from system default maven repositories
hosted_plugins = {
-- Example:
-- {
-- group_id = "com.ensarsarajcic.neovim.java",
-- artifact_id = "rplugin-hosted-example",
-- version = "0.4.2"
-- },
-- or:
-- "com.ensarsarajcic.neovim.java:rplugin-hosted-example:0.4.2"
},
-- Custom repositories
custom_repositories = {
-- Example:
-- {
-- id = "github",
-- url = "https://maven.pkg.github.com/OWNER/REPOSITORY"
-- }
}
},
-- Extend with a list of strings - additional classpath entries
-- If all classpath entries generated by the plugin are not enough
classpath_extras = {},
-- Library logging level - also affects storing of logs from the hosted plugins
log_level = "info",
autostart = true, -- set to false to prevent automatic start of plugins - must call start() then
}
```

**NOTE**: When adding `.java` classes directly in `rplugin/java`, make sure to create directories for packages starting from `rplugin/java` as root. This means that any `.java` classes found in `rplugin/java` directly should have no package at all (implicit root package).

### Functions

- `require("java_plugin_host").setup()` - main function for configuring the plugin, must be called before using any other function
- `require("java_plugin_host").start()` - start common plugin host and all standalone plugins - needed only if `autostart = false` or explicitly stopped
- `require("java_plugin_host").stop()` - stop common plugin host and all standalone plugins
- `require("java_plugin_host").restart()` - restart common plugin host and all standalone plugins - works only if already running
- `require("java_plugin_host").open_logs(key)` - open plugin logs - if key is omitted, shows common host logs, otherwise opends standalone plugin based on key - also mapped to `NeovimJavaLogs` - autocomplete is provided for keys
- `require("java_plugin_host").rebuild_classpath(callback)` - rebuild classpath used by the plugin and call callback with new classpath - can be useful to recompile all config and then restart the plugin
- `require("java_plugin_host").request(...)` - shortcut for `rpcrequest` which uses common host job id - example: `require("java_plugin_host").request("my_custom_request_handler", "arg1")`
- `require("java_plugin_host").notify(...)` - shortcut for `rpcnotify` which uses common host job id - example: `require("java_plugin_host").notify("my_custom_notification_handler", "arg1")`
- `require("java_plugin_host").get_standalone_jobs()` - returns table with all running standalone jobs

Classpath can also be directly accessed with `require("java_plugin_host").classpath` (only after `setup()` call).

### Configuring nvim-jdtls

If using [nvim-jdtls](https://github.com/mfussenegger/nvim-jdtls), it can be configured to add classpath of the common host. This enables writing configuration directly in nvim config `rplugin/java` directory, as any other configuration file. It is recommended to keep separate nvim-jdtls configuration for nvim config, to prevent showing plugin autocomplete suggestions in other Java code. Example configuration can be found in [my dotfiles](https://github.com/esensar/dotfiles/blob/main/symlinks/config/nvim/lua/esensar/lsp/jdtls_setup.lua).

```lua
config.settings = {
java = {
...
project = {
referencedLibraries = require("java_plugin_host").classpath,
},
...
},
}
```

## Writing plugins for the host

Check out examples and templates:
- **Example:** [neovim-http-api-plugin](https://codeberg.org/neovim-java/neovim-http-api-plugin) - *supports different ways of installation, highlighting differences*

## Contributing

Check out [contributing guidelines](CONTRIBUTING.md).

## License

[MIT](LICENSE)