# coc-spring-dashboard

Spring Boot dashboard for [coc.nvim](https://github.com/neoclide/coc.nvim):
tree views of the Spring Boot apps of the workspace, their beans, endpoint
mappings, properties and memory, and signs on bean definitions and request
mappings in the code.

It is a port of
[microsoft/vscode-spring-boot-dashboard](https://github.com/microsoft/vscode-spring-boot-dashboard)
(MIT). See [NOTICE](NOTICE) and [LICENSE](LICENSE).

Using it inside Neovim is described in the help page:
`:help coc-spring-dashboard`.

## Requirements

- coc-java and coc-springboot, installed and active (declared as extension
  dependencies). The dashboard gets all of its data through them and waits
  for their servers to start, the Java server until it has imported the
  projects; until then it says "Java server starting" or "Spring Boot server
  not running".
- For live data (running state, live beans and mappings, properties,
  memory), a running app with `spring-boot-starter-actuator` on its
  classpath, started with these JVM arguments (the dashboard adds them to the
  apps it starts, from the `vmArgs` of `spring.dashboard.launch.defaults`):

  ```
  -Dspring.jmx.enabled=true -Dmanagement.endpoints.jmx.exposure.include=*
  -Dmanagement.endpoint.env.show-values=ALWAYS
  ```

- Apps started by the dashboard connect by their pid and need no setting.
  Other apps connect through Attach to a remote app
  (`spring-boot-dashboard.app.remote.attach`),
  or through coc-springboot's `springboot.app.connect` picker, which offers the
  apps on your machine only with this coc-springboot setting in
  `coc-settings.json` (see `:help coc-springboot-local-apps`):

  ```json
  "boot-java.live-information.all-local-java-processes": true
  ```

- For Debug, Attach debugger and the debug half of Attach to a remote app,
  [nvim-dap](https://github.com/mfussenegger/nvim-dap)
  in Neovim or [vimspector](https://github.com/puremourning/vimspector) in Vim
  and Neovim. Run needs no debugger.

Run, Debug and Stop are done by the dashboard: it opens a
launch panel (profiles, server port, logging, JVM options, program arguments
and environment, remembered per app), starts the JVM in a tab per app, the
dashboard of the app (Beans, Mappings, Properties and Memory over the terminal), and stops it with SIGTERM and then SIGKILL. The JMX arguments above
are added for you for apps it starts.

## Installation

```vim
:CocInstall coc-spring-dashboard
```

Or build a checkout and add its folder to the runtimepath with your plugin
manager:

```sh
npm ci
npm run build
```

## Settings

Set these keys in `coc-settings.json` (`:CocConfig` opens it).

| Key | Type | Default | Effect |
| --- | --- | --- | --- |
| `spring.dashboard.openUrl` | string | `"{protocol}://{hostname}:{port}{contextPath}"` | Url template of an app, {protocol} {hostname} {port} {contextPath}. |
| `spring.dashboard.memory-view.fetch-data.delay-in-milliseconds` | number | `5000` | Interval of the memory metrics poll. |
| `spring.dashboard.memory-view.display-data.max-datapoints` | number | `10` | Width of the memory sparklines. |
| `spring.dashboard.enableGutter` | string (`on`, `off`) | `"on"` | Signs on the bean definitions and request mappings. |
| `spring.dashboard.debug.attachTimeout` | number | `30` | Seconds to wait for the debugger to attach (Debug, Attach debugger, Attach to a remote app). An app started with Debug is stopped after that; the others keep running. |
| `spring.dashboard.stop.gracePeriod` | number | `10` | Seconds between Stop (SIGTERM) and the kill (SIGKILL). |
| `spring.dashboard.launch.prompt` | string | `always` | When the launch panel opens: `always` (every Run and Debug), `first` (first time per app) or `never`. |
| `spring.dashboard.layout.terminalHeight` | number | `65` | Percent (10 to 90) of the height of an app dashboard tab given to the terminal under the views. |
| `spring.dashboard.layout.components` | array | all five | The panes of an app dashboard tab: `beans`, `endpoints`, `properties`, `memory`, `terminal`. They keep their fixed places (views side by side on top, terminal below); a left out view is not shown anywhere, a left out terminal keeps running without a window. |
| `spring.dashboard.layout.cleanup` | string (`always`, `keep`) | `"always"` | When an app stops: close its dashboard tab, or keep it for the next run. |
| `spring.dashboard.layout.fallbackSize` | number | `75` | Width and height, in percent of the screen, of the float a bean, an endpoint, a relation or an nvim-dap stop opens in when the app has no source window, or there is no app. |
| `spring.dashboard.launch.defaults` | object | the live data options | The launch settings under every app: `profiles`, `port`, `logLevel`, `logPackages`, `debugReport`, `vmArgs`, `programArgs`, `envVars`. The default `vmArgs` are the options the live data needs, including `-Dmanagement.endpoint.env.show-values=ALWAYS` so that Spring Boot 3 shows property values instead of `******`; the rest is empty. |
| `spring.dashboard.launch.settings` | object | `{}` | Launch settings per app name, used until the launch panel remembers others, on top of `spring.dashboard.launch.defaults`: lists are appended without duplicates (`programArgs` replace a default with the same option name), `envVars` is merged per key, a single value replaces the default. E.g. `{ "my-app": { "vmArgs": ["-Xmx512m"] } }`. |
| `spring.dashboard.attach.defaults` | object | `localhost`, `9010`, `5005` | The attach settings under every project: `host`, `jmxPort`, `debugPort` (an empty port skips that half), and `debugVmArgs`, `jmxVmArgs`, the JVM options Copy app startup options gives for the debugger and the live data half, with `${host}`, `${jmxPort}`, `${debugPort}` filled in. The default `jmxVmArgs` are the JMX port options followed by the live data options. |
| `spring.dashboard.attach.settings` | object | `{}` | Attach settings per project name, on top of `spring.dashboard.attach.defaults`: a key that is set replaces the default. The host and ports apply until an attach to the project remembers others; the JVM options always come from the settings (here or `spring.dashboard.attach.defaults`). E.g. `{ "orders-service": { "host": "10.0.0.5" } }`. |

Connect (`spring-boot-dashboard.app.remote.connect`) serves the items of `boot-java.remote-apps`, a
coc-springboot setting (see `:help coc-springboot-remote-apps` and `:help coc-spring-dashboard-remote`).
Disconnect (`spring-boot-dashboard.app.remote.disconnect`) disconnects any remote app the dashboard
connected, from that list or by Attach to a remote app; a local app follows its own start and stop.
Apps the dashboard starts connect by themselves; for any other app use
Attach to a remote app.

Attach to a remote app (`spring-boot-dashboard.app.remote.attach`) connects the live data over
JMX and attaches the debugger over JDWP for an app the dashboard did not start
(another machine, a container, a forwarded port, a JVM you started yourself).
An empty port skips that half. A panel asks for the host,
the JMX port, the debug port and the project, and can copy the matching JVM
options. See `:help coc-spring-dashboard-attach`.

## Troubleshooting

- Failed requests to the Spring language server are logged to the output
  channel "Spring Dashboard":
  `:CocCommand workspace.showOutput Spring Dashboard`.
- Jumps from the views and nvim-dap stops open in the source window of the app:
  the window Run, Debug or Attach was started from, or the first file window of
  its tab; without one, or outside an app tab, in a float.
- No trees, or a warning that coc-springboot or coc-java is not active:
  check `:CocList extensions` and open a Java file of the project.
- An app stays `○ stopped` while it runs: check the actuator dependency, the
  JVM arguments above, then run `:CocCommand spring-boot-dashboard.livedata.refresh`.
- Every message the dashboard shows is explained in
  `:help coc-spring-dashboard-messages`.

## Development

```sh
npm ci
npm run build
npm run typecheck
```
