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

language server protocol (VS Code integration) #3524

Merged
merged 6 commits into from Oct 3, 2017

Conversation

Projects
None yet
8 participants
@eed3si9n
Member

eed3si9n commented Sep 13, 2017

This is a work in progress branch to support Language Server Protocol (Visual Studio Code integration) on sbt server.

The initial goal is to invoke compile on save. The details are written up in this blog post http://eed3si9n.com/scala-language-server-using-sbt

Depends on:

@smarter

This comment has been minimized.

Show comment
Hide comment
@smarter

smarter Sep 13, 2017

Contributor

Wow, nice! This might be enough motivation for me to finish upgrading dotty to sbt 1. I think it'd be very cool if JSON-RPC was the only protocol used to communicate with sbt server mode. We could define a build server protocol that complements the language server protocol.

Contributor

smarter commented Sep 13, 2017

Wow, nice! This might be enough motivation for me to finish upgrading dotty to sbt 1. I think it'd be very cool if JSON-RPC was the only protocol used to communicate with sbt server mode. We could define a build server protocol that complements the language server protocol.

@eed3si9n

This comment has been minimized.

Show comment
Hide comment
@eed3si9n

eed3si9n Sep 13, 2017

Member

I think it'd be very cool if JSON-RPC was the only protocol used to communicate with sbt server mode. We could define a build server protocol that complements the language server protocol.

I agree. While there's no clients or documentations yet, we should try to switch to JSON-RPC as the wire protocol if we can.

Member

eed3si9n commented Sep 13, 2017

I think it'd be very cool if JSON-RPC was the only protocol used to communicate with sbt server mode. We could define a build server protocol that complements the language server protocol.

I agree. While there's no clients or documentations yet, we should try to switch to JSON-RPC as the wire protocol if we can.

@eed3si9n

This comment has been minimized.

Show comment
Hide comment
@eed3si9n

eed3si9n Sep 15, 2017

Member

With f6bd70b, VS Code now talks to sbt server and invokes compile at the root level.

Member

eed3si9n commented Sep 15, 2017

With f6bd70b, VS Code now talks to sbt server and invokes compile at the root level.

@@ -387,6 +387,41 @@ lazy val sbtProj = (project in file("sbt"))
)
.configure(addSbtCompilerBridge)
lazy val vscodePlugin = (project in file("vscode-sbt-scala"))

This comment has been minimized.

@smarter

smarter Sep 18, 2017

Contributor

@eed3si9n eed3si9n changed the title from (wip) language server protocol to (wip) language server protocol (VS Code integration) Sep 19, 2017

@eed3si9n eed3si9n added this to the 1.1.0 milestone Sep 27, 2017

@eed3si9n eed3si9n changed the title from (wip) language server protocol (VS Code integration) to language server protocol (VS Code integration) Oct 2, 2017

/**
* Implements Language Server Protocol <https://github.com/Microsoft/language-server-protocol>.
*/
private[sbt] trait LanguageServerProtocol extends CommandChannel {

This comment has been minimized.

@eed3si9n

eed3si9n Oct 2, 2017

Member

@dwijnand The key logic should mostly be in this file.

@eed3si9n

eed3si9n Oct 2, 2017

Member

@dwijnand The key logic should mostly be in this file.

begins language server protocol
This is the first cut for the Language Server Protocol on top of server that is still work in progress.

With this change, sbt is able to invoke `compile` task on saving files in VS Code.
@guillaumebort

This comment has been minimized.

Show comment
Hide comment
@guillaumebort

guillaumebort Oct 2, 2017

Contributor

Interesting. I did the same thing as an experiment, but I just used the sbt server protocol directly. Works pretty well.

Contributor

guillaumebort commented Oct 2, 2017

Interesting. I did the same thing as an experiment, but I just used the sbt server protocol directly. Works pretty well.

@kiritsuku

This comment has been minimized.

Show comment
Hide comment
@kiritsuku

kiritsuku Oct 2, 2017

Contributor

I tried to run

sbt:sbtRoot> vscodePlugin/compile
Warning: Unknown Scalafmt version 1.2.0; using 1.0 interface
[warn] Credentials file /home/sschaef/.bintray/.credentials does not exist

> vscode-sbt-scala@0.0.1 compile /home/sschaef/dev/scala/sbt/vscode-sbt-scala
> tsc -p client/tsconfig.json && cd server && npm run installServer && cd .. && tsc -p server/tsconfig.json

client/node_modules/vscode-languageclient/lib/client.d.ts(1,749): error TS2307: Cannot find module 'vscode'.
client/node_modules/vscode-languageclient/lib/codeConverter.d.ts(1,23): error TS2307: Cannot find module 'vscode'.
client/node_modules/vscode-languageclient/lib/main.d.ts(5,28): error TS2307: Cannot find module 'vscode'.
client/node_modules/vscode-languageclient/lib/protocolCompletionItem.d.ts(1,23): error TS2307: Cannot find module 'vscode'.
client/node_modules/vscode-languageclient/lib/protocolConverter.d.ts(1,23): error TS2307: Cannot find module 'vscode'.
client/node_modules/vscode-languageclient/lib/workspaceFolders.proposed.d.ts(1,77): error TS2307: Cannot find module 'vscode'.
client/src/extension.ts(6,45): error TS2307: Cannot find module 'vscode'.

npm ERR! Linux 4.4.0-96-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "run" "compile"
npm ERR! node v6.11.3
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! vscode-sbt-scala@0.0.1 compile: `tsc -p client/tsconfig.json && cd server && npm run installServer && cd .. && tsc -p serv
er/tsconfig.json`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the vscode-sbt-scala@0.0.1 compile script 'tsc -p client/tsconfig.json && cd server && npm run installServer &&
cd .. && tsc -p server/tsconfig.json'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the vscode-sbt-scala package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     tsc -p client/tsconfig.json && cd server && npm run installServer && cd .. && tsc -p server/tsconfig.json
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs vscode-sbt-scala
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls vscode-sbt-scala
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/sschaef/dev/scala/sbt/vscode-sbt-scala/npm-debug.log

What is the module vscode that can't be found?

Contributor

kiritsuku commented Oct 2, 2017

I tried to run

sbt:sbtRoot> vscodePlugin/compile
Warning: Unknown Scalafmt version 1.2.0; using 1.0 interface
[warn] Credentials file /home/sschaef/.bintray/.credentials does not exist

> vscode-sbt-scala@0.0.1 compile /home/sschaef/dev/scala/sbt/vscode-sbt-scala
> tsc -p client/tsconfig.json && cd server && npm run installServer && cd .. && tsc -p server/tsconfig.json

client/node_modules/vscode-languageclient/lib/client.d.ts(1,749): error TS2307: Cannot find module 'vscode'.
client/node_modules/vscode-languageclient/lib/codeConverter.d.ts(1,23): error TS2307: Cannot find module 'vscode'.
client/node_modules/vscode-languageclient/lib/main.d.ts(5,28): error TS2307: Cannot find module 'vscode'.
client/node_modules/vscode-languageclient/lib/protocolCompletionItem.d.ts(1,23): error TS2307: Cannot find module 'vscode'.
client/node_modules/vscode-languageclient/lib/protocolConverter.d.ts(1,23): error TS2307: Cannot find module 'vscode'.
client/node_modules/vscode-languageclient/lib/workspaceFolders.proposed.d.ts(1,77): error TS2307: Cannot find module 'vscode'.
client/src/extension.ts(6,45): error TS2307: Cannot find module 'vscode'.

npm ERR! Linux 4.4.0-96-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "run" "compile"
npm ERR! node v6.11.3
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! vscode-sbt-scala@0.0.1 compile: `tsc -p client/tsconfig.json && cd server && npm run installServer && cd .. && tsc -p serv
er/tsconfig.json`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the vscode-sbt-scala@0.0.1 compile script 'tsc -p client/tsconfig.json && cd server && npm run installServer &&
cd .. && tsc -p server/tsconfig.json'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the vscode-sbt-scala package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     tsc -p client/tsconfig.json && cd server && npm run installServer && cd .. && tsc -p server/tsconfig.json
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs vscode-sbt-scala
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls vscode-sbt-scala
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/sschaef/dev/scala/sbt/vscode-sbt-scala/npm-debug.log

What is the module vscode that can't be found?

@dwijnand

This comment has been minimized.

Show comment
Hide comment
@dwijnand

dwijnand Oct 2, 2017

Member

@sschaef What part of tsc -p client/tsconfig.json && cd server && npm run installServer && cd .. && tsc -p server/tsconfig.json fails on your system?

Member

dwijnand commented Oct 2, 2017

@sschaef What part of tsc -p client/tsconfig.json && cd server && npm run installServer && cd .. && tsc -p server/tsconfig.json fails on your system?

@kiritsuku

This comment has been minimized.

Show comment
Hide comment
@kiritsuku

kiritsuku Oct 2, 2017

Contributor

The first command already fails:

% tsc -p client/tsconfig.json
client/node_modules/vscode-languageclient/lib/client.d.ts(1,749): error TS2307: Cannot find module 'vscode'.

I did a npm install vscode beforehand and also a sudo npm install -g vscode but tsc still can't find the vscode module.

Contributor

kiritsuku commented Oct 2, 2017

The first command already fails:

% tsc -p client/tsconfig.json
client/node_modules/vscode-languageclient/lib/client.d.ts(1,749): error TS2307: Cannot find module 'vscode'.

I did a npm install vscode beforehand and also a sudo npm install -g vscode but tsc still can't find the vscode module.

@kiritsuku

This comment has been minimized.

Show comment
Hide comment
@kiritsuku

kiritsuku Oct 2, 2017

Contributor

Ok, I fixed the problem. On sbt startup there is a npm install run on the vscode project. I removed the node_modules folder and restart sbt. Now everything works perfectly fine.

Contributor

kiritsuku commented Oct 2, 2017

Ok, I fixed the problem. On sbt startup there is a npm install run on the vscode project. I removed the node_modules folder and restart sbt. Now everything works perfectly fine.

@kiritsuku

This comment has been minimized.

Show comment
Hide comment
@kiritsuku

kiritsuku Oct 2, 2017

Contributor

In the vscode part, there are two servers. One is in vscode-sbt-scala/client/server and the other is in vscode-sbt-scala/server. Why are there two of them, isn't one enough?

What is this package-lock.json file doing? Is it required?

Contributor

kiritsuku commented Oct 2, 2017

In the vscode part, there are two servers. One is in vscode-sbt-scala/client/server and the other is in vscode-sbt-scala/server. Why are there two of them, isn't one enough?

What is this package-lock.json file doing? Is it required?

@eed3si9n

This comment has been minimized.

Show comment
Hide comment
@eed3si9n

eed3si9n Oct 2, 2017

Member

@sschaef The example extension was set up that way with "client" and "server" at the top-level, and the compiled server code copied into client.
They represent two different Node instances so I think it kind of make sense to me that the source directory is separate. In my implementation "server" just converts stdio to socket.

Member

eed3si9n commented Oct 2, 2017

@sschaef The example extension was set up that way with "client" and "server" at the top-level, and the compiled server code copied into client.
They represent two different Node instances so I think it kind of make sense to me that the source directory is separate. In my implementation "server" just converts stdio to socket.

@eed3si9n

This comment has been minimized.

Show comment
Hide comment
@eed3si9n

eed3si9n Oct 2, 2017

Member

I am not familiar with Node development, so I'm not sure, but I am guessing that package-lock.json is a dependency lock file that pins down the list of dependencies. If so I think it would make sense to commit it.

Member

eed3si9n commented Oct 2, 2017

I am not familiar with Node development, so I'm not sure, but I am guessing that package-lock.json is a dependency lock file that pins down the list of dependencies. If so I think it would make sense to commit it.

@kiritsuku

This comment has been minimized.

Show comment
Hide comment
@kiritsuku

kiritsuku Oct 2, 2017

Contributor

Ok, makes sense now. package-lock.json is indeed intended to be committed: https://docs.npmjs.com/files/package-lock.json

Contributor

kiritsuku commented Oct 2, 2017

Ok, makes sense now. package-lock.json is indeed intended to be committed: https://docs.npmjs.com/files/package-lock.json

@dwijnand

LGTM, pending Travis CI passing.

@typesafe-tools

This comment has been minimized.

Show comment
Hide comment
@typesafe-tools

typesafe-tools Oct 3, 2017

To validate this pull request against other sbt modules, please visit this link.

typesafe-tools commented Oct 3, 2017

To validate this pull request against other sbt modules, please visit this link.

### sbt/setting
```json
{ "jsonrpc": "2.0", "id": 1, "method": "sbt/setting", "params": { "setting": "root/name" } }

This comment has been minimized.

@dwijnand

dwijnand Oct 3, 2017

Member

sbt/query?

@dwijnand

dwijnand Oct 3, 2017

Member

sbt/query?

This comment has been minimized.

@eed3si9n

eed3si9n Oct 3, 2017

Member

I thought about keeping the name query in there, but the Microsoft style naming for query is using just the nouns it seems. See https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#workspace_symbol

@eed3si9n

eed3si9n Oct 3, 2017

Member

I thought about keeping the name query in there, but the Microsoft style naming for query is using just the nouns it seems. See https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#workspace_symbol

@kiritsuku

This comment has been minimized.

Show comment
Hide comment
@kiritsuku

kiritsuku Oct 3, 2017

Contributor

Is the textDocument/didSave notification already working for you? I don't receive any notifications on the server side yet.

Contributor

kiritsuku commented Oct 3, 2017

Is the textDocument/didSave notification already working for you? I don't receive any notifications on the server side yet.

@eed3si9n

This comment has been minimized.

Show comment
Hide comment
@eed3si9n

eed3si9n Oct 3, 2017

Member

@sschaef Yea, it works for me. You have to run reset.sh to make sure you are using freshly baked sbt tho.

Member

eed3si9n commented Oct 3, 2017

@sschaef Yea, it works for me. You have to run reset.sh to make sure you are using freshly baked sbt tho.

@kiritsuku

This comment has been minimized.

Show comment
Hide comment
@kiritsuku

kiritsuku Oct 3, 2017

Contributor

I think I have a problem with vscode (probably not using it correctly), because sbt doesn't even receive a notification event. The initialization routine and the shutdown event is working but nothing else. Can you edit arbitrary files or does it work only for specific files?

Contributor

kiritsuku commented Oct 3, 2017

I think I have a problem with vscode (probably not using it correctly), because sbt doesn't even receive a notification event. The initialization routine and the shutdown event is working but nothing else. Can you edit arbitrary files or does it work only for specific files?

@eed3si9n

This comment has been minimized.

Show comment
Hide comment
@eed3si9n

eed3si9n Oct 3, 2017

Member

It works for me using Hello.scala not sure if it would for other extensions.

Member

eed3si9n commented Oct 3, 2017

It works for me using Hello.scala not sure if it would for other extensions.

@smarter

This comment has been minimized.

Show comment
Hide comment
@smarter

smarter Oct 3, 2017

Contributor

@sschaef: Right now it's restricted to .scala and .java files: https://github.com/eed3si9n/sbt/blob/1ad9360e3e9446eed325fd7259c41b59541393dc/vscode-sbt-scala/client/src/extension.ts and requires a build.sbt file: https://github.com/eed3si9n/sbt/blob/1ad9360e3e9446eed325fd7259c41b59541393dc/vscode-sbt-scala/client/package.json#L21. Also make sure you don't have another language server running at the same time like vscode-dotty or https://github.com/dragos/dragos-vscode-scala, they won't work together as I explained in: #3524 (comment)

Contributor

smarter commented Oct 3, 2017

@sschaef: Right now it's restricted to .scala and .java files: https://github.com/eed3si9n/sbt/blob/1ad9360e3e9446eed325fd7259c41b59541393dc/vscode-sbt-scala/client/src/extension.ts and requires a build.sbt file: https://github.com/eed3si9n/sbt/blob/1ad9360e3e9446eed325fd7259c41b59541393dc/vscode-sbt-scala/client/package.json#L21. Also make sure you don't have another language server running at the same time like vscode-dotty or https://github.com/dragos/dragos-vscode-scala, they won't work together as I explained in: #3524 (comment)

@eed3si9n

This comment has been minimized.

Show comment
Hide comment
@eed3si9n

eed3si9n Oct 3, 2017

Member

ok. I am going to merge this and release a milestone.

Member

eed3si9n commented Oct 3, 2017

ok. I am going to merge this and release a milestone.

@eed3si9n eed3si9n merged commit 7af716f into sbt:1.x Oct 3, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@eed3si9n eed3si9n deleted the eed3si9n:wip/language_server branch Oct 3, 2017

@kiritsuku

This comment has been minimized.

Show comment
Hide comment
@kiritsuku

kiritsuku Oct 3, 2017

Contributor
Contributor

kiritsuku commented Oct 3, 2017

@wpopielarski

This comment has been minimized.

Show comment
Hide comment
@wpopielarski

wpopielarski Oct 5, 2017

Contributor

@sschaef "Ok, I fixed the problem. On sbt startup there is a npm install run on the vscode project. I removed the node_modules folder and restart sbt. Now everything works perfectly fine."
the target folder in vscode-sbt-scala needs to removed too

Contributor

wpopielarski commented Oct 5, 2017

@sschaef "Ok, I fixed the problem. On sbt startup there is a npm install run on the vscode project. I removed the node_modules folder and restart sbt. Now everything works perfectly fine."
the target folder in vscode-sbt-scala needs to removed too

@ghisvail

This comment has been minimized.

Show comment
Hide comment
@ghisvail

ghisvail Oct 6, 2017

Any chance to get something similar for Atom?

Version 1.21 got support for the language server protocol and is already used by a number of IDE integration packages such as ide-typescript or ide-java. I can picture sbt 1.1.x providing similar functionalities in a future ide-scala package.

ghisvail commented Oct 6, 2017

Any chance to get something similar for Atom?

Version 1.21 got support for the language server protocol and is already used by a number of IDE integration packages such as ide-typescript or ide-java. I can picture sbt 1.1.x providing similar functionalities in a future ide-scala package.

@wpopielarski

This comment has been minimized.

Show comment
Hide comment
@wpopielarski

wpopielarski Oct 6, 2017

Contributor
Contributor

wpopielarski commented Oct 6, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment