Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Commit

Permalink
Initial implementation of the tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
xnkevinnguyen committed Feb 20, 2020
1 parent 5ab2a1b commit c480348
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@
"svg-inline-react": "^3.1.0",
"ts-jest": "^25.0.0",
"util": "^0.12.1",
"vscode-debugprotocol": "^1.28.0",
"vscode-extension-telemetry": "^0.1.1",
"vscode-nls": "^4.1.0"
},
Expand All @@ -322,4 +323,4 @@
"extensionDependencies": [
"ms-python.python"
]
}
}
15 changes: 11 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { SimulatorDebugConfigurationProvider } from "./simulatorDebugConfigurati
import TelemetryAI from "./telemetry/telemetryAI";
import { UsbDetector } from "./usbDetector";
import { VSCODE_MESSAGES_TO_WEBVIEW, WEBVIEW_MESSAGES } from "./view/constants";
import { DebugAdapterFactory } from "./extension_utils/debugAdapter";

let currentFileAbsPath: string = "";
let currentTextDocument: vscode.TextDocument;
Expand Down Expand Up @@ -141,7 +142,6 @@ export async function activate(context: vscode.ExtensionContext) {
}
);


currentPanel.webview.html = getWebviewContent(context);

if (messageListener !== undefined) {
Expand Down Expand Up @@ -451,7 +451,7 @@ export async function activate(context: vscode.ExtensionContext) {
const runSimulatorCommand = async () => {
// Prevent running new code if a debug session is active
if (inDebugMode) {
console.log("debug mode not running simulator command")
console.log("debug mode not running simulator command");
vscode.window.showErrorMessage(
CONSTANTS.ERROR.DEBUGGING_SESSION_IN_PROGESS
);
Expand Down Expand Up @@ -570,7 +570,7 @@ export async function activate(context: vscode.ExtensionContext) {
childProcess.stdout.on("data", data => {
dataFromTheProcess = data.toString();
if (currentPanel) {
console.log("receiving message")
console.log("receiving message");
// Process the data from the process and send one state at a time
dataFromTheProcess.split("\0").forEach(message => {
if (
Expand Down Expand Up @@ -916,6 +916,13 @@ export async function activate(context: vscode.ExtensionContext) {
utils.getPathToScript(context, "out/", "debug_user_code.py")
);

const debugAdapterFactory = new DebugAdapterFactory(
vscode.debug.activeDebugSession
);
vscode.debug.registerDebugAdapterTrackerFactory(
"python",
debugAdapterFactory
);
// On Debug Session Start: Init comunication
const debugSessionsStarted = vscode.debug.onDidStartDebugSession(() => {
if (simulatorDebugConfiguration.deviceSimulatorExpressDebug) {
Expand Down Expand Up @@ -1023,7 +1030,7 @@ const updateCurrentFileIfPython = async (
if (
currentTextDocument &&
utils.getActiveEditorFromPath(currentTextDocument.fileName) ===
undefined
undefined
) {
await vscode.window.showTextDocument(
currentTextDocument,
Expand Down
39 changes: 39 additions & 0 deletions src/extension_utils/debugAdapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
DebugAdapterTracker,
DebugAdapterTrackerFactory,
DebugSession,
DebugConsole,
ProviderResult,
} from "vscode";
import { DebugProtocol } from "vscode-debugprotocol";

export class DebugAdapter implements DebugAdapterTracker {
private readonly console: DebugConsole | undefined;
constructor(debugSession: DebugSession) {
this.console = debugSession.configuration.console;
}
onWillStartSession() {
console.log("--debugadapter onWillStartSession");
}
onWillReceiveMessage(message: any): void {
console.log("--debugadapter onWillReceiveMessage");
console.log(JSON.stringify(message));
}
onExit() {
console.log("--debugadapter onExit");
}
}

export class DebugAdapterFactory implements DebugAdapterTrackerFactory {
private debugSession: DebugSession;
constructor(debugSession: DebugSession) {
console.log("New debug factory");
this.debugSession = debugSession;
}
public createDebugAdapterTracker(
session: DebugSession
): ProviderResult<DebugAdapterTracker> {
console.log("It created an adapter tracker");
return new DebugAdapter(session);
}
}

0 comments on commit c480348

Please sign in to comment.