Skip to content

Commit 4ace38d

Browse files
committed
Address review comments
1 parent 6db887d commit 4ace38d

File tree

7 files changed

+37
-40
lines changed

7 files changed

+37
-40
lines changed

language-server/src/dotty/tools/languageserver/worksheet/CancellationThread.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import java.util.concurrent.CancellationException
77
/**
88
* Regularly check whether execution has been cancelled, kill REPL if it is.
99
*/
10-
private class CancellationThread(private[this] var cancelChecker: CancelChecker,
10+
private class CancellationThread(@volatile private[this] var cancelChecker: CancelChecker,
1111
evaluator: Evaluator) extends Thread {
1212
private final val checkCancelledDelayMs = 50
1313

language-server/src/dotty/tools/languageserver/worksheet/Evaluator.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import org.eclipse.lsp4j.jsonrpc.CancelChecker
99
private object Evaluator {
1010

1111
private val javaExec: Option[String] = {
12-
val bin = new File(sys.props("java.home"), "bin")
12+
val bin = new File(scala.util.Properties.javaHome, "bin")
1313
val java = new File(bin, if (scala.util.Properties.isWin) "java.exe" else "java")
1414

1515
if (java.exists()) Some(java.getAbsolutePath())
@@ -56,8 +56,8 @@ private class Evaluator private (javaExec: String,
5656
private val process =
5757
new ProcessBuilder(
5858
javaExec,
59-
"-classpath", sys.props("java.class.path"),
60-
dotty.tools.repl.WorksheetMain.getClass.getName.init,
59+
"-classpath", scala.util.Properties.javaClassPath,
60+
dotty.tools.repl.WorksheetMain.getClass.getName.stripSuffix("$"),
6161
"-classpath", userClasspath,
6262
"-color:never")
6363
.redirectErrorStream(true)

language-server/src/dotty/tools/languageserver/worksheet/WorksheetMessages.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package dotty.tools.languageserver.worksheet
22

3-
import java.net.URI
3+
import org.eclipse.lsp4j.VersionedTextDocumentIdentifier
44

55
/** The parameter for the `worksheet/exec` request. */
6-
case class WorksheetExecParams(uri: URI) {
6+
case class WorksheetExecParams(textDocument: VersionedTextDocumentIdentifier) {
77
// Used for deserialization
88
// see https://github.com/lampepfl/dotty/pull/5102#discussion_r222055355
99
def this() = this(null)
@@ -20,7 +20,7 @@ case class WorksheetExecResponse(success: Boolean) {
2020
* A notification that tells the client that a line of a worksheet
2121
* produced the specified output.
2222
*/
23-
case class WorksheetExecOutput(uri: URI, line: Int, content: String) {
23+
case class WorksheetExecOutput(textDocument: VersionedTextDocumentIdentifier, line: Int, content: String) {
2424
// Used for deserialization
2525
// see https://github.com/lampepfl/dotty/pull/5102#discussion_r222055355
2626
def this() = this(null, 0, null)

language-server/src/dotty/tools/languageserver/worksheet/WorksheetService.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ trait WorksheetService { thisServer: DottyLanguageServer =>
1717

1818
@JsonRequest
1919
def exec(params: WorksheetExecParams): CompletableFuture[WorksheetExecResponse] = thisServer.synchronized {
20-
val uri = params.uri
20+
val uri = new URI(params.textDocument.getUri)
2121
val future =
2222
computeAsync { cancelChecker =>
2323
try {
2424
val driver = driverFor(uri)
25-
val sendMessage = (line: Int, msg: String) => client.publishOutput(WorksheetExecOutput(uri, line, msg))
25+
val sendMessage = (line: Int, msg: String) => client.publishOutput(WorksheetExecOutput(params.textDocument, line, msg))
2626
evaluateWorksheet(driver, uri, sendMessage, cancelChecker)(driver.currentCtx)
2727
WorksheetExecResponse(success = true)
2828
} catch {

language-server/test/dotty/tools/languageserver/util/actions/WorksheetAction.scala

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,19 @@ import dotty.tools.languageserver.util.embedded.CodeMarker
66
import java.net.URI
77
import java.util.concurrent.CompletableFuture
88

9-
abstract class WorksheetAction extends Action {
9+
import org.eclipse.lsp4j.VersionedTextDocumentIdentifier
1010

11-
/** Get the URI of the worksheet that contains `marker`. */
12-
def getUri(marker: CodeMarker): Exec[URI] = new URI(marker.toTextDocumentIdentifier.getUri)
11+
abstract class WorksheetAction extends Action {
1312

1413
/** Triggers the evaluation of the worksheet. */
1514
def triggerEvaluation(marker: CodeMarker): Exec[CompletableFuture[WorksheetExecResponse]] = {
16-
val uri = getUri(marker)
17-
server.exec(WorksheetExecParams(uri))
15+
server.exec(WorksheetExecParams(marker.toVersionedTextDocumentIdentifier))
1816
}
1917

2018
/** The output of the worksheet that contains `marker`. */
2119
def worksheetOutput(marker: CodeMarker): Exec[List[WorksheetExecOutput]] = {
22-
val uri = getUri(marker)
23-
client.worksheetOutput.get.filter(_.uri == uri)
20+
val textDocument = marker.toVersionedTextDocumentIdentifier
21+
client.worksheetOutput.get.filter(_.textDocument.getUri == textDocument.getUri)
2422
}
2523

2624
}

language-server/test/dotty/tools/languageserver/util/embedded/CodeMarker.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class CodeMarker(val name: String) extends Embedded {
4040
def toTextDocumentIdentifier: PosCtx[TextDocumentIdentifier] =
4141
new TextDocumentIdentifier(file.uri)
4242

43+
def toVersionedTextDocumentIdentifier: PosCtx[VersionedTextDocumentIdentifier] =
44+
new VersionedTextDocumentIdentifier(file.uri, 0)
45+
4346
def toReferenceParams(withDecl: Boolean): PosCtx[ReferenceParams] = {
4447
val rp = new ReferenceParams(new ReferenceContext(withDecl))
4548
rp.setTextDocument(toTextDocumentIdentifier)

vscode-dotty/src/worksheet.ts

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as vscode from 'vscode'
2-
import { LanguageClient } from 'vscode-languageclient'
3-
import * as rpc from 'vscode-jsonrpc'
42
import { client } from './extension'
3+
import { VersionedTextDocumentIdentifier } from 'vscode-languageserver-protocol'
54

65
/** A worksheet managed by vscode */
76
class Worksheet {
@@ -59,23 +58,23 @@ class Worksheet {
5958
}
6059

6160
/** The parameter for the `worksheet/exec` request. */
62-
class WorksheetExec {
63-
constructor(uri: string) {
64-
this.uri = uri
61+
class WorksheetExecParams {
62+
constructor(textDocument: vscode.TextDocument) {
63+
this.textDocument = VersionedTextDocumentIdentifier.create(textDocument.uri.toString(), textDocument.version)
6564
}
6665

67-
readonly uri: string
66+
readonly textDocument: VersionedTextDocumentIdentifier
6867
}
6968

7069
/** The parameter for the `worksheet/publishOutput` notification. */
7170
class WorksheetOutput {
72-
constructor(uri: vscode.Uri, line: number, content: string) {
73-
this.uri = uri
71+
constructor(textDocument: VersionedTextDocumentIdentifier, line: number, content: string) {
72+
this.textDocument = textDocument
7473
this.line = line
7574
this.content = content
7675
}
7776

78-
readonly uri: vscode.Uri
77+
readonly textDocument: VersionedTextDocumentIdentifier
7978
readonly line: number
8079
readonly content: string
8180
}
@@ -136,7 +135,7 @@ export function evaluateWorksheet(document: vscode.TextDocument): Thenable<{}> {
136135
title: "Evaluating worksheet",
137136
cancellable: true
138137
}, (_, token) => {
139-
return client.sendRequest("worksheet/exec", new WorksheetExec(worksheet.document.uri.toString()), token)
138+
return client.sendRequest("worksheet/exec", new WorksheetExecParams(worksheet.document), token)
140139
})
141140
} else {
142141
return Promise.reject()
@@ -173,8 +172,8 @@ function _prepareWorksheet(worksheet: Worksheet) {
173172
export function handleMessage(output: WorksheetOutput) {
174173

175174
const editor = vscode.window.visibleTextEditors.find(e => {
176-
let uri = e.document.uri
177-
return uri == output.uri
175+
let uri = e.document.uri.toString()
176+
return uri == output.textDocument.uri
178177
})
179178

180179
if (editor) {
@@ -196,18 +195,15 @@ export function handleMessage(output: WorksheetOutput) {
196195
* @return a new `TextEditorDecorationType`.
197196
*/
198197
function worksheetCreateDecoration(margin: number, text: string) {
199-
const decorationType =
200-
vscode.window.createTextEditorDecorationType({
201-
isWholeLine: true,
202-
after: {
203-
contentText: text,
204-
margin: `0px 0px 0px ${margin}ch`,
205-
fontStyle: "italic",
206-
color: "light gray",
207-
}
208-
})
209-
210-
return decorationType
198+
return vscode.window.createTextEditorDecorationType({
199+
isWholeLine: true,
200+
after: {
201+
contentText: text,
202+
margin: `0px 0px 0px ${margin}ch`,
203+
fontStyle: "italic",
204+
color: "light gray",
205+
}
206+
})
211207
}
212208

213209
/**

0 commit comments

Comments
 (0)