Skip to content

Commit 2f685d2

Browse files
authored
Merge pull request #5127 from dotty-staging/lsp-tracing
Add LSP tracing
2 parents 0fcbfdb + d3f45e9 commit 2f685d2

9 files changed

+1019
-443
lines changed

vscode-dotty/package-lock.json

Lines changed: 529 additions & 406 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vscode-dotty/package.json

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"icon": "images/dotty-logo.png",
1313
"engines": {
14-
"vscode": "^1.27.0"
14+
"vscode": "^1.27.1"
1515
},
1616
"categories": [
1717
"Languages"
@@ -48,6 +48,29 @@
4848
"type": "boolean",
4949
"default": true,
5050
"description": "If true, saving a worksheet will also run it."
51+
},
52+
"dotty.trace.remoteWorkspaceDumpUrl": {
53+
"type": "string",
54+
"default": "",
55+
"description": "Url to send local workspace dump to."
56+
},
57+
"dotty.trace.remoteTracingUrl": {
58+
"type": "string",
59+
"default": "",
60+
"description": "Url to send local LSP communication to."
61+
},
62+
"dotty.trace.machineId": {
63+
"type": [
64+
"string",
65+
"null"
66+
],
67+
"default": null,
68+
"description": "ID of your machine used when Dotty Language Server tracing is turned on."
69+
},
70+
"dotty.trace.maximumMessageSize": {
71+
"type": "number",
72+
"default": 512,
73+
"description": "Maximum size for the messages sent to remote server. Larger ones will be split."
5174
}
5275
}
5376
},
@@ -88,12 +111,18 @@
88111
"compare-versions": "^3.4.0",
89112
"vscode-languageclient": "^5.1.0",
90113
"vscode-languageserver": "^5.1.0",
91-
"vscode-jsonrpc": "4.0.0"
114+
"vscode-jsonrpc": "4.0.0",
115+
"ws": "^6.0.0",
116+
"archiver": "^3.0.0",
117+
"request": "^2.88.0"
92118
},
93119
"devDependencies": {
94120
"@types/compare-versions": "^3.0.0",
95121
"@types/mocha": "^5.2.5",
96122
"@types/node": "^8.10.32",
123+
"@types/ws": "^6.0.0",
124+
"@types/archiver": "^2.1.2",
125+
"@types/request": "^2.47.1",
97126
"typescript": "^2.9.2",
98127
"vscode": "^1.1.21"
99128
}

vscode-dotty/src/compat.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import * as vscode from 'vscode';
1+
import * as vscode from 'vscode'
22

3-
import { HoverRequest } from 'vscode-languageclient';
3+
import { HoverRequest } from 'vscode-languageclient'
44
import { MarkedString, LanguageClient, LanguageClientOptions, RevealOutputChannelOn,
5-
ServerOptions } from 'vscode-languageclient';
5+
ServerOptions } from 'vscode-languageclient'
66

77
// Fix hover functionality when using this version of vscode-dotty with Dotty
88
// Language Server 0.9 or earlier.

vscode-dotty/src/extension.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1-
'use strict';
1+
import * as fs from 'fs'
2+
import * as path from 'path'
23

3-
import * as fs from 'fs';
4-
import * as path from 'path';
4+
import * as pcp from 'promisify-child-process'
5+
import * as compareVersions from 'compare-versions'
56

6-
import * as pcp from 'promisify-child-process';
7-
import * as compareVersions from 'compare-versions';
7+
import { ChildProcess } from "child_process"
88

9-
import { ChildProcess } from "child_process";
10-
11-
import { ExtensionContext } from 'vscode';
12-
import * as vscode from 'vscode';
9+
import { ExtensionContext } from 'vscode'
10+
import * as vscode from 'vscode'
1311
import { LanguageClient, LanguageClientOptions, RevealOutputChannelOn,
14-
ServerOptions } from 'vscode-languageclient';
12+
ServerOptions } from 'vscode-languageclient'
1513
import { enableOldServerWorkaround } from './compat'
1614
import * as features from './features'
1715

1816
export let client: LanguageClient
1917

2018
import * as rpc from 'vscode-jsonrpc'
2119
import * as sbtserver from './sbt-server'
20+
import { Tracer } from './tracer'
21+
22+
export const extensionName = 'dotty'
23+
const extensionConfig = vscode.workspace.getConfiguration(extensionName)
2224

2325
let extensionContext: ExtensionContext
2426
let outputChannel: vscode.OutputChannel
27+
let tracer: Tracer
2528

2629
/** The sbt process that may have been started by this extension */
2730
let sbtProcess: ChildProcess | undefined
@@ -45,9 +48,14 @@ function isConfiguredProject() {
4548

4649
export function activate(context: ExtensionContext) {
4750
extensionContext = context
48-
outputChannel = vscode.window.createOutputChannel("Dotty");
51+
outputChannel = vscode.window.createOutputChannel("Dotty")
52+
tracer = new Tracer({
53+
extensionContext,
54+
extensionConfig,
55+
extensionOut: outputChannel,
56+
})
4957

50-
const coursierPath = path.join(extensionContext.extensionPath, "out", "coursier");
58+
const coursierPath = path.join(extensionContext.extensionPath, "out", "coursier")
5159
const dottyPluginSbtFileSource = path.join(extensionContext.extensionPath, "out", "dotty-plugin.sbt")
5260
const buildSbtFileSource = path.join(extensionContext.extensionPath, "out", "build.sbt")
5361

@@ -297,6 +305,8 @@ function bootstrapSbtProject(buildSbtFileSource: string,
297305
}
298306

299307
function run(serverOptions: ServerOptions, isOldServer: boolean) {
308+
const lspOutputChannel = tracer.run()
309+
300310
const clientOptions: LanguageClientOptions = {
301311
documentSelector: [
302312
{ scheme: 'file', pattern: '**/*.sc' },
@@ -307,11 +317,11 @@ function run(serverOptions: ServerOptions, isOldServer: boolean) {
307317
synchronize: {
308318
configurationSection: 'dotty'
309319
},
310-
outputChannel: outputChannel,
320+
outputChannel: lspOutputChannel,
311321
revealOutputChannelOn: RevealOutputChannelOn.Never
312322
}
313323

314-
client = new LanguageClient("dotty", "Dotty", serverOptions, clientOptions)
324+
client = new LanguageClient(extensionName, "Dotty", serverOptions, clientOptions)
315325
client.registerFeature(new features.WorksheetRunFeature(client))
316326

317327
if (isOldServer)

vscode-dotty/src/features.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import { WorksheetProvider } from './worksheet'
1414
// https://github.com/Microsoft/vscode-languageserver-node/issues/423 is fixed.
1515
function ensure<T, K extends keyof T>(target: T, key: K): T[K] {
1616
if (target[key] === void 0) {
17-
target[key] = {} as any;
17+
target[key] = {} as any
1818
}
19-
return target[key];
19+
return target[key]
2020
}
2121

2222
export interface WorksheetClientCapabilities {

vscode-dotty/src/passthrough-server.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict';
2-
3-
import * as net from 'net';
1+
import * as net from 'net'
42

53
let argv: string[] = process.argv.slice(2)
64
const firstArg: string | undefined = argv.shift()
@@ -22,7 +20,7 @@ client.on('data', (data) => {
2220
process.stdout.write(data.toString())
2321
})
2422
process.stdin.on('readable', () => {
25-
let chunk = process.stdin.read();
23+
let chunk = process.stdin.read()
2624
if (chunk !== null) {
2725
if (isConnected) {
2826
client.write(chunk)

vscode-dotty/src/sbt-server.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,25 @@ function connectSocket(socket: net.Socket): net.Socket {
7979
if (u.protocol == 'tcp:' && u.port) {
8080
socket.connect(+u.port, '127.0.0.1');
8181
} else if (u.protocol == 'local:' && u.hostname && os.platform() == 'win32') {
82-
let pipePath = '\\\\.\\pipe\\' + u.hostname;
83-
socket.connect(pipePath);
82+
let pipePath = '\\\\.\\pipe\\' + u.hostname
83+
socket.connect(pipePath)
8484
} else if (u.protocol == 'local:' && u.path) {
85-
socket.connect(u.path);
85+
socket.connect(u.path)
8686
} else {
87-
throw 'Unknown protocol ' + u.protocol;
87+
throw 'Unknown protocol ' + u.protocol
8888
}
89-
return socket;
89+
return socket
9090
}
9191

9292
// the port file is hardcoded to a particular location relative to the build.
9393
function discoverUrl(): url.Url {
94-
let pf = path.join(workspaceRoot, 'project', 'target', 'active.json');
95-
let portfile = JSON.parse(fs.readFileSync(pf).toString());
96-
return url.parse(portfile.uri);
94+
let pf = path.join(workspaceRoot, 'project', 'target', 'active.json')
95+
let portfile = JSON.parse(fs.readFileSync(pf).toString())
96+
return url.parse(portfile.uri)
9797
}
9898

9999
function delay(ms: number) {
100-
return new Promise(resolve => setTimeout(resolve, ms));
100+
return new Promise(resolve => setTimeout(resolve, ms))
101101
}
102102

103103
async function waitForServer(): Promise<net.Socket> {
@@ -106,12 +106,12 @@ async function waitForServer(): Promise<net.Socket> {
106106
location: vscode.ProgressLocation.Window,
107107
title: "Connecting to sbt server..."
108108
}, async _ => {
109-
let retries = 60;
109+
let retries = 60
110110
while (!socket && retries > 0) {
111111
try { socket = connectSocket(new net.Socket()) }
112112
catch (e) {
113-
retries--;
114-
await delay(1000);
113+
retries--
114+
await delay(1000)
115115
}
116116
}
117117
if (socket) return Promise.resolve(socket)

0 commit comments

Comments
 (0)