Skip to content

Commit

Permalink
Lsp update (#266)
Browse files Browse the repository at this point in the history
* Fixed .vscodeignore

* You can launch applications with vcode's debugger, not actuall debugging do.

* Fixed small configuration typos
  • Loading branch information
ewoudje authored Sep 24, 2023
1 parent 488fa5c commit 11d3b86
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 110 deletions.
8 changes: 1 addition & 7 deletions dev/vscode-ext/.vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,4 @@
out
contributing.md
.travis.yml
node_modules/**
!node_modules/vscode-jsonrpc/**
!node_modules/vscode-languageclient/**
!node_modules/vscode-languageserver-protocol/**
!node_modules/vscode-languageserver-types/**
!node_modules/{minimatch,brace-expansion,concat-map,balanced-match}/**
!node_modules/{semver,lru-cache,yallist}/**
node_modules/**
109 changes: 83 additions & 26 deletions dev/vscode-ext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,53 @@
"keywords": [
"lobster"
],
"activationEvents": [],
"activationEvents": [
"onDebugResolve:lobster",
"onDebugDynamicConfigurations:lobster",
"onCommand:extension.lobster.getProgramName"
],
"main": "./webpack-out/lobster_ext.js",
"contributes": {
"menus": {
"editor/title/run": [
{
"command": "extension.lobster.runEditorContents",
"when": "resourceLangId == lobster",
"group": "navigation@1"
},
{
"command": "extension.lobster.debugEditorContents",
"when": "resourceLangId == lobster",
"group": "navigation@2"
}
],
"commandPalette": [
{
"command": "extension.lobster.debugEditorContents",
"when": "resourceLangId == lobster"
},
{
"command": "extension.lobster.runEditorContents",
"when": "resourceLangId == lobster"
}
]
},
"commands": [
{
"command": "extension.lobster.debugEditorContents",
"title": "Debug File",
"category": "Lobster",
"enablement": "!inDebugMode",
"icon": "$(debug-alt)"
},
{
"command": "extension.lobster.runEditorContents",
"title": "Run File",
"category": "Lobster",
"enablement": "!inDebugMode",
"icon": "$(play)"
}
],
"configuration": {
"type": "object",
"title": "Lobster",
Expand Down Expand Up @@ -69,28 +113,6 @@
"path": "./syntaxes/lobster.tmLanguage.json"
}
],
"taskDefinitions": [
{
"type": "lobster",
"required": [
"main"
],
"properties": {
"main": {
"type": "string",
"description": "The file to run"
},
"lobsterArgs": {
"type": "array",
"description": "The arguments to pass to lobster"
},
"programArgs": {
"type": "array",
"description": "The arguments to pass to the program"
}
}
}
],
"breakpoints": [
{
"language": "lobster"
Expand All @@ -111,14 +133,49 @@
"properties": {
"program": {
"type": "string",
"description": "Path the lobster program to debug",
"default": "${workspaceFolder}/main.lobster"
"description": "Absolute path to a text file.",
"default": "${workspaceFolder}/${command:AskForProgramName}"
},
"params": {
"type": "array",
"description": "Lobster parameters",
"default": "${workspaceFolder}/${command:AskForProgramName}"
},
"stopOnEntry": {
"type": "boolean",
"description": "Automatically stop after launch.",
"default": true
}
}
}
}
}
]
],
"initialConfigurations": [
{
"type": "lobster",
"request": "launch",
"name": "Ask for file name",
"program": "${workspaceFolder}/${command:AskForProgramName}",
"stopOnEntry": true
}
],
"configurationSnippets": [
{
"label": "Lobster: Launch",
"description": "A new configuration for 'debugging' a user selected markdown file.",
"body": {
"type": "lobster",
"request": "launch",
"name": "Ask for file name",
"program": "^\"\\${workspaceFolder}/\\${command:AskForProgramName}\"",
"stopOnEntry": true
}
}
],
"variables": {
"AskForProgramName": "extension.lobster.getProgramName"
}
},
"scripts": {
"vscode:prepublish": "npm run webpack && shx cp ../lsp/webpack-out/* ./webpack-out/ && npm run icons",
Expand Down
43 changes: 43 additions & 0 deletions dev/vscode-ext/src/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as vscode from 'vscode';

export function registerCommands(context: vscode.ExtensionContext) {
context.subscriptions.push(
vscode.commands.registerCommand('extension.lobster.runEditorContents', (resource: vscode.Uri) => {
let targetResource = resource;
if (!targetResource && vscode.window.activeTextEditor) {
targetResource = vscode.window.activeTextEditor.document.uri;
}
if (targetResource) {
vscode.debug.startDebugging(undefined, {
type: 'lobster',
name: 'Run File',
request: 'launch',
program: targetResource.fsPath
},
{ noDebug: true }
);
}
}),
vscode.commands.registerCommand('extension.lobster.debugEditorContents', (resource: vscode.Uri) => {
let targetResource = resource;
if (!targetResource && vscode.window.activeTextEditor) {
targetResource = vscode.window.activeTextEditor.document.uri;
}
if (targetResource) {
vscode.debug.startDebugging(undefined, {
type: 'lobster',
name: 'Run File',
request: 'launch',
program: targetResource.fsPath,
stopOnEntry: true
});
}
}),
vscode.commands.registerCommand('extension.lobster.getProgramName', config => {
return vscode.window.showInputBox({
placeHolder: "Please enter the name of a markdown file in the workspace folder",
value: "someFile.lobster"
});
})
);
}
4 changes: 0 additions & 4 deletions dev/vscode-ext/src/dap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@ import {
import { LobsterDebugSession } from './lobsterDebug';

export class InlineLobsterDebugAdapterFactory implements DebugAdapterDescriptorFactory {

constructor(readonly module: string) {}

createDebugAdapterDescriptor(
session: DebugSession,
executable: DebugAdapterExecutable
): ProviderResult<DebugAdapterDescriptor> {
return new DebugAdapterInlineImplementation(new LobsterDebugSession());
}

}
11 changes: 5 additions & 6 deletions dev/vscode-ext/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ServerOptions,
TransportKind
} from 'vscode-languageclient/node';
import { registerTasks } from './task';
import { registerCommands } from './commands';
import { InlineLobsterDebugAdapterFactory } from './dap';

let client: LanguageClient;
Expand Down Expand Up @@ -50,7 +50,7 @@ export function activate(context: ExtensionContext) {

context.subscriptions.push(debug.registerDebugAdapterDescriptorFactory(
'lobster',
new InlineLobsterDebugAdapterFactory("TODO")
new InlineLobsterDebugAdapterFactory()
));

context.subscriptions.push(debug.registerDebugConfigurationProvider('lobster', {
Expand All @@ -72,8 +72,7 @@ export function activate(context: ExtensionContext) {
}

if (!config.program) {
return window.showInformationMessage("Cannot find a program to debug")
.then(_ => {
return window.showInformationMessage("Cannot find a program to debug").then(_ => {
return undefined; // abort launch
});
}
Expand All @@ -93,9 +92,9 @@ export function activate(context: ExtensionContext) {
}
];
}
}, DebugConfigurationProviderTriggerKind.Dynamic));
}));

registerTasks(context);
registerCommands(context);
}

export function deactivate(): Thenable<void> | undefined {
Expand Down
43 changes: 38 additions & 5 deletions dev/vscode-ext/src/lobsterDebug.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,49 @@
import {
DebugSession
DebugSession, TerminatedEvent
} from '@vscode/debugadapter';
import { DebugProtocol } from '@vscode/debugprotocol';
import { spawn, ChildProcess } from 'child_process';
import { workspace } from 'vscode';

interface ILaunchRequestArguments extends DebugProtocol.LaunchRequestArguments {
/** An absolute path to the "program" to debug. */
program: string;

params?: string[];
/** Automatically stop target after launch. If not specified, target does not stop. */
stopOnEntry?: boolean;
/** run without debugging */
noDebug?: boolean;
}

//TODO this should be moved outside vscode extension.

export class LobsterDebugSession extends DebugSession {
process: ChildProcess;

protected launchRequest(
response: DebugProtocol.LaunchResponse,
args: DebugProtocol.LaunchRequestArguments,
request?: DebugProtocol.Request
args: ILaunchRequestArguments,
): void {
console.log("Whoa");
//TODO add actual debugging
const executable = workspace.getConfiguration('lobster').get('executable') as string;
const imports = workspace.getConfiguration('lobster').get('imports') as string[];

this.process = spawn(executable, [
...imports.map(i => "--import " + i),
args.program,
...(args.params || [])
]);

this.process.on('spawn', () => {
this.sendResponse(response);
});

this.process.on('error', (err) => {
this.sendErrorResponse(response, 1, "Error executing lobster: {message}", { message: err.message });
});

this.process.on('exit', (code, signal) => {
this.sendEvent(new TerminatedEvent());
});
}
}
62 changes: 0 additions & 62 deletions dev/vscode-ext/src/task.ts

This file was deleted.

0 comments on commit 11d3b86

Please sign in to comment.