Skip to content

Commit

Permalink
一些重启相关的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Jun 7, 2024
1 parent 688ef13 commit a65829e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/console/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as tools from '../tools';
import { ConsoleServer } from './server';
import { registerMethod } from './client';
import * as debug from '../debug';
import * as vscode from 'vscode';

function setPort(port: number) {
if (!env.scriptUri) {
Expand Down Expand Up @@ -49,7 +50,20 @@ function registerAllMethods() {
client.treeViewManager.refreshTreeNode(params.id);
});

registerMethod('startDebuggerAttach', async (client) => {
interface startDebuggerParams {
delay?: number;
}

registerMethod('startDebugger', async (client, params: startDebuggerParams) => {
if (await debug.getSession()) {
return {
suc: false,
err: '调试器已经启动',
};
}
if (params.delay) {
await new Promise(resolve => setTimeout(resolve, params.delay! * 1000));
}
try {
let suc = await debug.attach();
if (suc) {
Expand Down Expand Up @@ -83,6 +97,20 @@ function registerAllMethods() {
};
}
});

registerMethod('hasDebugger', async (client) => {
return debug.getSession() !== undefined;
});

interface CommandParams {
command: string;
args?: any[];
}

registerMethod('command', async (client, params: CommandParams) => {
let res = await vscode.commands.executeCommand(params.command, ...(params.args || []));
return res;
});
}

export function init() {
Expand Down
4 changes: 4 additions & 0 deletions src/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,7 @@ export async function attach() {
export async function stop() {
await vscode.debug.stopDebugging();
}

export async function getSession() {
return vscode.debug.activeDebugSession;
}

0 comments on commit a65829e

Please sign in to comment.