Skip to content
New issue

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

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

Already on GitHub? # to your account

Live updates #25

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// Place your settings in this file to overwrite default and user settings.
{

"terminal.integrated.shellArgs.linux": [
"-i"
],

"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
Expand Down
22 changes: 21 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@
}
}
},


"attach": {
"required": [
"msgPort",
Expand Down Expand Up @@ -172,16 +174,34 @@
"runtime": "PLEASE ENTER PATH TO `som` launcher",
"stopOnEntry": false
},
{
"name": "Launch and Debug Interpreter",
"type": "SOMns",
"request": "launch",
"program": "${workspaceRoot}/Application.ns",
"cwd": "${workspaceRoot}",
"runtime": "PLEASE ENTER PATH TO `som` launcher",
"runtimeArgs": ["-d"],
"stopOnEntry": false
},
{
"name": "Attach to SOM program",
"type": "SOMns",
"request": "attach",
"msgPort": 7977,
"tracePort": 7978
}

]
}
]
],

"commands": [
{
"command": "updateFile",
"title": "Update Class"
}
]
},
"scripts": {
"compile:server": "cd server && ant -e deploy",
Expand Down
4 changes: 4 additions & 0 deletions src/asyncTraceProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {TreeItem, TreeItemCollapsibleState, TreeDataProvider, Event, ProviderResult, EventEmitter, CancellationToken} from 'vscode'

import {StackFrame} from './messages'

91 changes: 86 additions & 5 deletions src/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ import { BreakpointData, Source as WDSource, Respond,
InitializeConnection, SourceMessage, IdMap, StoppedMessage,
StackTraceResponse, StackTraceRequest, ScopesRequest, ScopesResponse,
StepMessage, VariablesRequest, VariablesResponse,
createLineBreakpointData,
InitializationResponse} from './messages';
createLineBreakpointData, InitializationResponse} from './messages';
import {UpdateClass, RestartFrame, EvaluateExpressionRequest, Message} from './extension-messages'
import { determinePorts } from "./launch-connector";
import { writeFileSync } from 'fs';
import { resolveCliArgsFromVSCodeExecutablePath } from '@vscode/test-electron';
import { networkInterfaces } from 'os';
//import { window , CancellationToken, Event, TreeDataProvider, TreeItem, ProviderResult } from 'vscode';
import { VersionedTextDocumentIdentifier } from 'vscode-languageserver-protocol';
import { getVSCodeDownloadUrl } from '@vscode/test-electron/out/util';
import { normalize } from 'path';
import { Breakpoint, TreeItem, TreeItemCollapsibleState } from 'vscode';


export interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArguments {
/** Path to the main program */
Expand Down Expand Up @@ -60,9 +69,17 @@ class SomDebugSession extends DebugSession {

private varHandles : Handles<string>;


private log = "/Users/matteo/TruffleStuff/SOMns-vscode/src/log.txt";

private addToLog(text : string) {
writeFileSync(this.log,text,{flag:'a+'})
}

private /* readonly */ activityTypes: string[];
private /* readonly */ knownActivities: Map<number, DebugProtocol.Thread>;


public constructor() {
super();

Expand Down Expand Up @@ -105,10 +122,17 @@ class SomDebugSession extends DebugSession {
protected launchRequest(response: DebugProtocol.LaunchResponse,
args: LaunchRequestArguments): void {
const options = {cwd: args.cwd};
let somArgs = ['-G', '-wd', args.program];
//, '-d'
// let somArgs = ['-G' , '-wd', args.program];
// if (args.runtimeArgs) {
// somArgs = args.runtimeArgs.concat(somArgs);
// }
debugger
let somArgs = ['-G', '-wd']
if (args.runtimeArgs) {
somArgs = args.runtimeArgs.concat(somArgs);
somArgs = somArgs.concat(args.runtimeArgs)
}
somArgs = somArgs.concat(args.program)
if (args.args) {
somArgs = somArgs.concat(args.args);
}
Expand All @@ -135,6 +159,15 @@ class SomDebugSession extends DebugSession {
this.somProc.on('close', code => {
this.sendEvent(new TerminatedEvent());
})

this.addToLog("**************I AM IN THE CONSOLE!************");
//var avp = new AsyncStackViewProvider();

// try{t} catch (e) {
// this.addToLog(`${e}`);
// }

//window.registerTreeDataProvider("asyncStacksView", this.asyncStackViewProvider);
}

protected attachRequest(response: DebugProtocol.AttachResponse,
Expand Down Expand Up @@ -198,6 +231,9 @@ class SomDebugSession extends DebugSession {
case "SymbolMessage":
// Not necessary to know symbols at the moment
break;
case "resumeActorResponse":
// Currently causing error, but not supported yet
break;
default:
this.sendEvent(new OutputEvent("[didn't understand msg] " + event.data, 'dbg-adapter'));
}
Expand Down Expand Up @@ -298,12 +334,13 @@ class SomDebugSession extends DebugSession {
return id;
}

private send(respond: Respond) {
private send(respond: Respond | Message) {
if (this.socket) {
this.socket.send(JSON.stringify(respond));
}
}


private sendBreakpoint(bpP: BreakpointPair, connected: boolean): void {
if (connected) {
this.send({
Expand Down Expand Up @@ -339,13 +376,17 @@ class SomDebugSession extends DebugSession {
ideResponse: DebugProtocol.StackTraceResponse) {
const frames = [];
for (let frame of data.stackFrames) {
if (frame.parallelStacks != null){
frames.push(new StackFrame(frame.id, "PARALLEL STACKS: " + frame.parallelStacks.length));
} else {
if (frame.sourceUri) {
frames.push(new StackFrame(frame.id, frame.name,
this.vsSourceFromUri(frame.sourceUri), frame.line, frame.column));
} else {
frames.push(new StackFrame(frame.id, frame.name))
}
}
}

ideResponse.body = {
stackFrames: frames,
Expand Down Expand Up @@ -455,6 +496,46 @@ class SomDebugSession extends DebugSession {
args: DebugProtocol.PauseArguments): void {
this.sendStep("stop", response, args);
}

protected restartFrameRequest(response: DebugProtocol.RestartFrameResponse, args: DebugProtocol.RestartFrameArguments, request?: DebugProtocol.Request): void {
const message: RestartFrame = {
action: "RestartFrame",
frameId: request.arguments.frameId
};
this.send(message);
}

protected evaluateRequest(response: DebugProtocol.EvaluateResponse, args: DebugProtocol.EvaluateArguments, request?: DebugProtocol.Request): void {
const message: EvaluateExpressionRequest = {
action: "EvaluateExpressionRequest",
expression: args.expression,

frameId: args.frameId
};
this.send(message);
}

protected customRequest(command: string, response: DebugProtocol.Response, args: any): void {
switch (command) {
case 'updateClassRequest':
this.updateClassRequest(args);
break;
// case 'restartFrame':
// this.restartFrameRequest(response,args)
default:
super.customRequest(command, response, args);
break;
}
}

protected updateClassRequest(
args: String): void {
const message: UpdateClass = {
action: "UpdateClass",
classToRecompile: args};
this.send(message);
}
}


DebugSession.run(SomDebugSession);
20 changes: 20 additions & 0 deletions src/extension-messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { integer } from "vscode-languageserver-protocol";
import {Message as OrigMessage} from "./messages";

export type Message = OrigMessage | UpdateClass | RestartFrame | EvaluateExpressionRequest

/* This file adds extra messages than the ones defined in extension.ts as that file is a symbolic link to another repository */
export interface UpdateClass {
action: "UpdateClass";
classToRecompile: String;
}

export interface RestartFrame {
action: "RestartFrame";
frameId: integer;
}
export interface EvaluateExpressionRequest {
action: "EvaluateExpressionRequest",
expression: String,
frameId: integer
}
46 changes: 37 additions & 9 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
'use strict';

import { DebugSession } from '@vscode/debugadapter';
import { ChildProcess, spawn } from 'child_process';
import { Socket } from 'net';

import { workspace, ExtensionContext, window, debug, DebugConfigurationProvider, WorkspaceFolder, DebugConfiguration, CancellationToken, ProviderResult } from 'vscode';
import { workspace, ExtensionContext, window, debug, DebugConfigurationProvider, WorkspaceFolder, DebugConfiguration, CancellationToken, ProviderResult, commands, TreeDataProvider, Event, TreeItem } from 'vscode';
import { LanguageClient, LanguageClientOptions, ServerOptions, StreamInfo } from 'vscode-languageclient/node';
import { StackFrame } from './messages';

const LSPort = 8123; // TODO: make configurable
const EnableExtensionDebugging : boolean = <boolean> workspace.getConfiguration('somns').get('debugMode');
const EnableExtensionDebugging : boolean = true;//<boolean> workspace.getConfiguration('somns').get('debugMode');

export const CLIENT_OPTION: LanguageClientOptions = {
documentSelector: ['SOMns', 'SOM','simple']
Expand Down Expand Up @@ -104,18 +106,18 @@ export function startLanguageServer(asAbsolutePath: PathConverter,
const cmd = `${serverOptions.run.command} ${serverOptions.run.args.join(" ")}`;
console.log(`[SOM-EXT] spawn '${cmd}'`);
const lsProc = spawn(serverOptions.run.command, serverOptions.run.args, {shell: true});

let stderr = '';
console.log("THE CONSOLE IS HERE")
let stderrBuffer = '';

lsProc.stderr.on('data', data => {
stderr += data.toString();
stderrBuffer += data.toString();
});

lsProc.on('exit', code => {
if (code !== 0) {
console.log(`[SOM-EXT] Server processes exited with code: ${code}
-------
stderr: ${stderr}
stderr: ${stderrBuffer}
-------`);
}
});
Expand Down Expand Up @@ -159,7 +161,10 @@ export function activate(context: ExtensionContext) {
}

// Registering the configuration provider for starting opened file
debug.registerDebugConfigurationProvider('SOMns', new SOMnsConfigurationProvider)
debug.registerDebugConfigurationProvider('SOMns', new SOMnsConfigurationProvider);

// Adding commands
defineCommands(context);

// Create the language client and start the client.
client = new LanguageClient('SOMns Language Server', createLSPServer, CLIENT_OPTION);
Expand All @@ -177,6 +182,27 @@ export function deactivate(): Thenable<void> | undefined {
return client.stop();
}

export function defineCommands(ctx: ExtensionContext) : void {

const updateFileHandler = () => {
const file : String = window.activeTextEditor.document.uri.fsPath;
debug.activeDebugSession.customRequest('updateClassRequest', file);
};

registerCommand('updateFile',updateFileHandler,ctx);

// const restartFrameHandler = () => {
// debug.activeDebugSession.customRequest('restartFrame', debug.activeDebugSession.id);
// };

// registerCommand('restartFrame',restartFrameHandler,ctx);
}

function registerCommand(command: string, commandHandler : (any) => any, ctx : ExtensionContext) {

ctx.subscriptions.push(commands.registerCommand(command, commandHandler));
}

/**
* This SOMnsConfigurationProvider is a dynamic provider that can change the debug configuration parameters
*/
Expand All @@ -194,4 +220,6 @@ class SOMnsConfigurationProvider implements DebugConfigurationProvider {

return config;
}
}
}