Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow editors to start an sbt session #243

Open
eed3si9n opened this issue Dec 5, 2021 · 5 comments
Open

Allow editors to start an sbt session #243

eed3si9n opened this issue Dec 5, 2021 · 5 comments

Comments

@eed3si9n
Copy link

eed3si9n commented Dec 5, 2021

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

  1. Open VS Code in a directory where I would like Metals to connect to sbt server.
  2. Suppose I've already configured to use sbt as the build server.
  3. At this point, Metals have already started an sbt session in a background process.
  4. I want to be able to interact with the sbt session.

Describe the solution you'd like

Given that LSP-capable editors like VS Code and Neovim also have a mini-shell environment, I would like Metals to ask the editor plugins to open the build server when it's an interactive build tool like sbt. (For VS Code code could look something like this - https://github.com/sbt/sbt/blob/e323f1f713251968b3d4ecda8a7f0ed52593713a/vscode-sbt-scala/client/src/extension.ts#L34-L45)

This way, we can let Metals drive majority of the interactions as save-compile, test etc, but when we want to perform some sbt commands it would use the built-in shell mechanism.

Describe alternatives you've considered

sbtn is a decent alternative, so I've tried using that. One of the issue is that sbtn was primarily designed to connect to a session that was also originally opened by sbtn, and the first session captures information regarding the terminal capability. On VS Code specifically this means that I would end up seeing error messages in black-and-white, even though the terminal is capable of colors.

So what I end up actually doing is sbtn shutdown && sbt. This shuts down the sbt session opened by Metals, and I can start a new one that Metals hopefully reconnects.

Additional contex

Previously this was filed as scalameta/metals#2152

Search terms

sbt

@tgodzik
Copy link
Contributor

tgodzik commented Dec 6, 2021

Thanks for reporting! I think we should do something along https://github.com/sbt/sbt/blob/e323f1f713251968b3d4ecda8a7f0ed52593713a/vscode-sbt-scala/client/src/extension.ts#L34-L45 with the difference being that we should use the built-in Metals way of starting sbt in case sbt is not available.

We could possibly use https://code.visualstudio.com/api/references/vscode-api#TerminalProfileProvider so users would be even able to start multiple sbt terminals. We would only need to ask Metals about the way to start an sbt session.

@eed3si9n what is the best way of connecting to sbt session? Something like sbt -client ?

@eed3si9n
Copy link
Author

eed3si9n commented Dec 6, 2021

what is the best way of connecting to sbt session? Something like sbt -client?

For BSP client, the best way to connect to an ongoing session is via following .bsp/sbt.json, which contains absolute path to java and sbt launcher.

For human users, sbt --client would connect to a session.

@tgodzik
Copy link
Contributor

tgodzik commented Dec 6, 2021

For human users, sbt --client would connect to a session.

So that would be something that we run in VS Code then?

terminal = vscode.window.createTerminal(`sbt`);
terminal.show();
terminal.sendText("sbt --client");

@eed3si9n
Copy link
Author

eed3si9n commented Dec 6, 2021

So that would be something that we run in VS Code then?

That's effectively what I mentioned in the considered alternatives section. I can already type sbtn to hook into the sbt session created by Metals. The problem is that I'd get a degraded UX because the session seems to be unaware of the terminal capability.

What I would like instead is for VS Code shell to start the initial sbt session. The benefit of this approach is that the session would be aware of the terminal capability of the VS Code shell, so it would display things in color. Other information regarding the terminal capability might include the width of the window, ANSI X3.64 control (for fancy cursor movements) etc.

On the other hand, when using Metals from Neovim, the terminal may not be capable of color, so in that case we don't want to display color.

@tgodzik
Copy link
Contributor

tgodzik commented Dec 7, 2021

Thanks for the explanation! It might harder to make the plugin start the session, but should be doable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants