Skip to content

Add LSP tracing #5127

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

Merged
merged 11 commits into from
Oct 31, 2018
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
935 changes: 529 additions & 406 deletions vscode-dotty/package-lock.json

Large diffs are not rendered by default.

23 changes: 21 additions & 2 deletions vscode-dotty/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"icon": "images/dotty-logo.png",
"engines": {
"vscode": "^1.27.0"
"vscode": "^1.27.1"
},
"categories": [
"Languages"
Expand Down Expand Up @@ -48,6 +48,19 @@
"type": "boolean",
"default": true,
"description": "If true, saving a worksheet will also run it."
},
"dotty.tracing.machineId": {
"type": [
"string",
"null"
],
"default": null,
"description": "ID of your machine used when Dotty Language Server tracing is turned on."
},
"dotty.tracing.maximumMessageSize": {
"type": "number",
"default": 512,
"description": "Maximum size for the messages sent to remote server. Larger ones will be split."
}
}
},
Expand Down Expand Up @@ -88,12 +101,18 @@
"compare-versions": "^3.4.0",
"vscode-languageclient": "^5.1.0",
"vscode-languageserver": "^5.1.0",
"vscode-jsonrpc": "4.0.0"
"vscode-jsonrpc": "4.0.0",
"ws": "^6.0.0",
"archiver": "^3.0.0",
"request": "^2.88.0"
},
"devDependencies": {
"@types/compare-versions": "^3.0.0",
"@types/mocha": "^5.2.5",
"@types/node": "^8.10.32",
"@types/ws": "^6.0.0",
"@types/archiver": "^2.1.2",
"@types/request": "^2.47.1",
"typescript": "^2.9.2",
"vscode": "^1.1.21"
}
Expand Down
6 changes: 3 additions & 3 deletions vscode-dotty/src/compat.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as vscode from 'vscode';
import * as vscode from 'vscode'

import { HoverRequest } from 'vscode-languageclient';
import { HoverRequest } from 'vscode-languageclient'
import { MarkedString, LanguageClient, LanguageClientOptions, RevealOutputChannelOn,
ServerOptions } from 'vscode-languageclient';
ServerOptions } from 'vscode-languageclient'

// Fix hover functionality when using this version of vscode-dotty with Dotty
// Language Server 0.9 or earlier.
Expand Down
39 changes: 25 additions & 14 deletions vscode-dotty/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
'use strict';
import * as fs from 'fs'
import * as path from 'path'

import * as fs from 'fs';
import * as path from 'path';
import * as pcp from 'promisify-child-process'
import * as compareVersions from 'compare-versions'

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

import { ChildProcess } from "child_process";

import { ExtensionContext } from 'vscode';
import * as vscode from 'vscode';
import { ExtensionContext } from 'vscode'
import * as vscode from 'vscode'
import { LanguageClient, LanguageClientOptions, RevealOutputChannelOn,
ServerOptions } from 'vscode-languageclient';
ServerOptions } from 'vscode-languageclient'
import { enableOldServerWorkaround } from './compat'
import * as features from './features'

export let client: LanguageClient

import * as rpc from 'vscode-jsonrpc'
import * as sbtserver from './sbt-server'
import { Tracer } from './tracer'

export const extensionName = 'dotty'
const extensionConfig = vscode.workspace.getConfiguration(extensionName)

let extensionContext: ExtensionContext
let outputChannel: vscode.OutputChannel
let tracer: Tracer

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

export function activate(context: ExtensionContext) {
extensionContext = context
outputChannel = vscode.window.createOutputChannel("Dotty");
outputChannel = vscode.window.createOutputChannel("Dotty")
tracer = new Tracer({
extensionContext,
extensionConfig,
extensionOut: outputChannel,
})

const coursierPath = path.join(extensionContext.extensionPath, "out", "coursier");
const coursierPath = path.join(extensionContext.extensionPath, "out", "coursier")
const dottyPluginSbtFileSource = path.join(extensionContext.extensionPath, "out", "dotty-plugin.sbt")
const buildSbtFileSource = path.join(extensionContext.extensionPath, "out", "build.sbt")

Expand Down Expand Up @@ -297,6 +305,9 @@ function bootstrapSbtProject(buildSbtFileSource: string,
}

function run(serverOptions: ServerOptions, isOldServer: boolean) {

const { lspOutputChannel } = tracer.run()

const clientOptions: LanguageClientOptions = {
documentSelector: [
{ scheme: 'file', pattern: '**/*.sc' },
Expand All @@ -307,11 +318,11 @@ function run(serverOptions: ServerOptions, isOldServer: boolean) {
synchronize: {
configurationSection: 'dotty'
},
outputChannel: outputChannel,
outputChannel: lspOutputChannel,
revealOutputChannelOn: RevealOutputChannelOn.Never
}

client = new LanguageClient("dotty", "Dotty", serverOptions, clientOptions)
client = new LanguageClient(extensionName, "Dotty", serverOptions, clientOptions)
client.registerFeature(new features.WorksheetRunFeature(client))

if (isOldServer)
Expand Down
4 changes: 2 additions & 2 deletions vscode-dotty/src/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import { WorksheetProvider } from './worksheet'
// https://github.com/Microsoft/vscode-languageserver-node/issues/423 is fixed.
function ensure<T, K extends keyof T>(target: T, key: K): T[K] {
if (target[key] === void 0) {
target[key] = {} as any;
target[key] = {} as any
}
return target[key];
return target[key]
}

export interface WorksheetClientCapabilities {
Expand Down
6 changes: 2 additions & 4 deletions vscode-dotty/src/passthrough-server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

import * as net from 'net';
import * as net from 'net'

let argv: string[] = process.argv.slice(2)
const firstArg: string | undefined = argv.shift()
Expand All @@ -22,7 +20,7 @@ client.on('data', (data) => {
process.stdout.write(data.toString())
})
process.stdin.on('readable', () => {
let chunk = process.stdin.read();
let chunk = process.stdin.read()
if (chunk !== null) {
if (isConnected) {
client.write(chunk)
Expand Down
24 changes: 12 additions & 12 deletions vscode-dotty/src/sbt-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,25 @@ function connectSocket(socket: net.Socket): net.Socket {
if (u.protocol == 'tcp:' && u.port) {
socket.connect(+u.port, '127.0.0.1');
} else if (u.protocol == 'local:' && u.hostname && os.platform() == 'win32') {
let pipePath = '\\\\.\\pipe\\' + u.hostname;
socket.connect(pipePath);
let pipePath = '\\\\.\\pipe\\' + u.hostname
socket.connect(pipePath)
} else if (u.protocol == 'local:' && u.path) {
socket.connect(u.path);
socket.connect(u.path)
} else {
throw 'Unknown protocol ' + u.protocol;
throw 'Unknown protocol ' + u.protocol
}
return socket;
return socket
}

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

function delay(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
return new Promise(resolve => setTimeout(resolve, ms))
}

async function waitForServer(): Promise<net.Socket> {
Expand All @@ -106,12 +106,12 @@ async function waitForServer(): Promise<net.Socket> {
location: vscode.ProgressLocation.Window,
title: "Connecting to sbt server..."
}, async _ => {
let retries = 60;
let retries = 60
while (!socket && retries > 0) {
try { socket = connectSocket(new net.Socket()) }
catch (e) {
retries--;
await delay(1000);
retries--
await delay(1000)
}
}
if (socket) return Promise.resolve(socket)
Expand Down
Loading