Skip to content

feature: support arbitrary server discovery #197

@nickjvandyke

Description

@nickjvandyke

Did you check the docs?

  • I have read all the docs

Is your feature request related to a problem? Please describe.

From the discussion in #150.

It's not practical for opencode.nvim to support all the ways users may want to find their opencode server. But I really like that convenience.

Describe the solution you'd like

Expose a way for users (and supplemental plugins like https://github.com/e-cal/opencode-tmux.nvim) to hook into the server discovery process.

Hook configuration methods

  1. opts.server.pid: a function that returns opencode server PIDs. Lowest burden on users - a PID is the simplest form possible, and then opencode.nvim converts it to a port and then server object.
  2. Extend opts.server.port to also fun(): number[]. I like that it keeps a single option. But it probably requires some user work to provide a port.
  3. opts.server.discover: a function that returns Server objects. Requires lots of work on user's end.
  4. opts.server.url: Similar to opts.server.port, but would support feature: easier way to just specify the server endpoint #190. Probably replace opts.server.port.

I would like to type this in an obvious way. Primarily, I wonder if these options should be mutually exclusive.

I also wonder if we should default the new option to find all servers, prioritizing ones with matching CWDs. The plugin already does that internally. The question is whether that should be completely overridable, or always supplement this new configured option.

Order of priority when discovering servers

Currently:

  1. Currently connected server
  2. Configured port
  3. Single server partially matching Neovim's CWD
  4. Prompt user to select from all servers

Proposed:

Depends on the configuration method chosen above. But something like:

  1. Currently connected server
  2. Configured port
  3. Single server returned by new discovery hook
  4. Prompt user to select from all servers returned by new discovery hook
  5. Single server partially matching Neovim's CWD
  6. Prompt user to select from all servers

We could expose a sort option. But I'd love to find a good enough default that that's not necessary.

Describe alternatives you've considered

Monkeypatch server.lua#get like https://github.com/e-cal/opencode-tmux.nvim does. But it's unstable and duplicates work that opencode.nvim should be able to handle on its behalf.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestquestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions