Skip to content

Commit

Permalink
Move off startSessionCommand and startDebug.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanTup committed Oct 13, 2017
1 parent d5f1a21 commit e26f46a
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 66 deletions.
19 changes: 1 addition & 18 deletions package.json
Expand Up @@ -5,7 +5,7 @@
"version": "2.4.3-dev",
"publisher": "DanTup",
"engines": {
"vscode": "^1.16.0"
"vscode": "^1.17.0"
},
"license": "SEE LICENSE IN LICENSE",
"bugs": {
Expand Down Expand Up @@ -417,7 +417,6 @@
},
"program": "./out/src/debug/dart_debug_entry.js",
"runtime": "node",
"startSessionCommand": "_dart.startDebugSession",
"configurationAttributes": {
"launch": {
"required": [
Expand Down Expand Up @@ -448,14 +447,6 @@
}
}
},
"initialConfigurations": [
{
"name": "Dart command line",
"type": "dart-cli",
"request": "launch",
"program": "${workspaceRoot}/bin/main.dart"
}
],
"configurationSnippets": [
{
"label": "Dart command line",
Expand All @@ -479,7 +470,6 @@
},
"program": "./out/src/debug/flutter_debug_entry.js",
"runtime": "node",
"startSessionCommand": "_dart.startDebugSession",
"configurationAttributes": {
"launch": {
"properties": {
Expand All @@ -490,13 +480,6 @@
}
}
},
"initialConfigurations": [
{
"name": "Flutter mobile app",
"type": "flutter",
"request": "launch"
}
],
"configurationSnippets": [
{
"label": "Flutter mobile app",
Expand Down
70 changes: 22 additions & 48 deletions src/commands/sdk.ts
Expand Up @@ -22,48 +22,26 @@ export class SdkCommands {
this.deviceManager = deviceManager;
}

registerCommands(context: vs.ExtensionContext) {
function setupDebugConfig(debugConfig: FlutterLaunchRequestArguments, sdks: Sdks, deviceId: string) {
analytics.logDebuggerStart();

const dartExec = isWin ? "dart.exe" : "dart";
const flutterExec = isWin ? "flutter.bat" : "flutter";

// Attach any properties that weren't explicitly set.
debugConfig.cwd = debugConfig.cwd || "${workspaceRoot}";
debugConfig.args = debugConfig.args || [];
debugConfig.dartPath = debugConfig.dartPath || path.join(sdks.dart, "bin", dartExec);
debugConfig.observatoryLogFile = debugConfig.observatoryLogFile || config.observatoryLogFile;
debugConfig.debugSdkLibraries = debugConfig.debugSdkLibraries || config.debugSdkLibraries;
debugConfig.debugExternalLibraries = debugConfig.debugExternalLibraries || config.debugExternalLibraries;
if (debugConfig.checkedMode === undefined)
debugConfig.checkedMode = true;
debugConfig.flutterPath = debugConfig.flutterPath || (sdks.flutter ? path.join(sdks.flutter, "bin", flutterExec) : null);
debugConfig.flutterRunLogFile = debugConfig.flutterRunLogFile || config.flutterRunLogFile;
debugConfig.deviceId = debugConfig.deviceId || deviceId;
}
// TODO: This is probably a bad place for these... They were pulled up here and made static as part of moving debug config
// out from hee to a DebugConfigProvider. Possibly they should all go into the DebugConfigProvider now (which should probably
// have a Flutter-specific one rather than the if statements in it).
static debugPaintingEnabled = false;
static performanceOverlayEnabled = false;
static repaintRainbowEnabled = false;
static timeDilation = 1.0;
static slowModeBannerEnabled = true;
static paintBaselinesEnabled = false;

public static resetFlutterSettings() {
// TODO: Make this better? We need to reset on new debug sessions, but copy/pasting the above is a bit naff.
this.debugPaintingEnabled = false, this.performanceOverlayEnabled = false, this.repaintRainbowEnabled = false, this.timeDilation = 1.0, this.slowModeBannerEnabled = true, this.paintBaselinesEnabled = false;
}

registerCommands(context: vs.ExtensionContext) {
// SDK commands.
const sdkManager = new SdkManager();
context.subscriptions.push(vs.commands.registerCommand("dart.changeSdk", () => sdkManager.changeSdk(this.sdks.dart)));

// Debug commands.
context.subscriptions.push(vs.commands.registerCommand("_dart.startDebugSession", (debugConfig: FlutterLaunchRequestArguments) => {
const keys = Object.keys(debugConfig);
if (keys.length == 0 || (keys.length == 1 && keys[0] == "noDebug"))
return { status: 'initialConfiguration' };

setupDebugConfig(debugConfig, this.sdks, this.deviceManager && this.deviceManager.currentDevice ? this.deviceManager.currentDevice.id : null);

if (isFlutterProject) {
resetFlutterSettings();
debugConfig.program = debugConfig.program || "${workspaceRoot}/lib/main.dart"; // Set Flutter default path.
}

vs.commands.executeCommand('vscode.startDebug', debugConfig);
return { status: 'ok' };
}));

// Pub commands.
context.subscriptions.push(vs.commands.registerCommand("pub.get", selection => {
if (isFlutterProject) {
Expand Down Expand Up @@ -92,17 +70,13 @@ export class SdkCommands {
}));

// Debug service commands.
let debugPaintingEnabled = false, performanceOverlayEnabled = false, repaintRainbowEnabled = false, timeDilation = 1.0, slowModeBannerEnabled = true, paintBaselinesEnabled = false;
function resetFlutterSettings() {
// TODO: Make this better? We need to reset on new debug sessions, but copy/pasting the above is a bit naff.
debugPaintingEnabled = false, performanceOverlayEnabled = false, repaintRainbowEnabled = false, timeDilation = 1.0, slowModeBannerEnabled = true, paintBaselinesEnabled = false;
}
context.subscriptions.push(vs.commands.registerCommand("flutter.toggleDebugPainting", () => this.runBoolServiceCommand("ext.flutter.debugPaint", debugPaintingEnabled = !debugPaintingEnabled)));
context.subscriptions.push(vs.commands.registerCommand("flutter.togglePerformanceOverlay", () => this.runBoolServiceCommand("ext.flutter.showPerformanceOverlay", performanceOverlayEnabled = !performanceOverlayEnabled)));
context.subscriptions.push(vs.commands.registerCommand("flutter.toggleRepaintRainbow", () => this.runBoolServiceCommand("ext.flutter.repaintRainbow", repaintRainbowEnabled = !repaintRainbowEnabled)));
context.subscriptions.push(vs.commands.registerCommand("flutter.toggleSlowAnimations", () => this.runServiceCommand("ext.flutter.timeDilation", { timeDilation: timeDilation = 6.0 - timeDilation })));
context.subscriptions.push(vs.commands.registerCommand("flutter.toggleSlowModeBanner", () => this.runBoolServiceCommand("ext.flutter.debugAllowBanner", slowModeBannerEnabled = !slowModeBannerEnabled)));
context.subscriptions.push(vs.commands.registerCommand("flutter.togglePaintBaselines", () => this.runBoolServiceCommand("ext.flutter.debugPaintBaselinesEnabled", paintBaselinesEnabled = !paintBaselinesEnabled)));

context.subscriptions.push(vs.commands.registerCommand("flutter.toggleDebugPainting", () => this.runBoolServiceCommand("ext.flutter.debugPaint", SdkCommands.debugPaintingEnabled = !SdkCommands.debugPaintingEnabled)));
context.subscriptions.push(vs.commands.registerCommand("flutter.togglePerformanceOverlay", () => this.runBoolServiceCommand("ext.flutter.showPerformanceOverlay", SdkCommands.performanceOverlayEnabled = !SdkCommands.performanceOverlayEnabled)));
context.subscriptions.push(vs.commands.registerCommand("flutter.toggleRepaintRainbow", () => this.runBoolServiceCommand("ext.flutter.repaintRainbow", SdkCommands.repaintRainbowEnabled = !SdkCommands.repaintRainbowEnabled)));
context.subscriptions.push(vs.commands.registerCommand("flutter.toggleSlowAnimations", () => this.runServiceCommand("ext.flutter.timeDilation", { timeDilation: SdkCommands.timeDilation = 6.0 - SdkCommands.timeDilation })));
context.subscriptions.push(vs.commands.registerCommand("flutter.toggleSlowModeBanner", () => this.runBoolServiceCommand("ext.flutter.debugAllowBanner", SdkCommands.slowModeBannerEnabled = !SdkCommands.slowModeBannerEnabled)));
context.subscriptions.push(vs.commands.registerCommand("flutter.togglePaintBaselines", () => this.runBoolServiceCommand("ext.flutter.debugPaintBaselinesEnabled", SdkCommands.paintBaselinesEnabled = !SdkCommands.paintBaselinesEnabled)));

// Misc custom debug commands.
context.subscriptions.push(vs.commands.registerCommand("flutter.fullRestart", () => vs.commands.executeCommand('workbench.customDebugRequest', "fullRestart")));
Expand Down
6 changes: 6 additions & 0 deletions src/extension.ts
Expand Up @@ -34,9 +34,11 @@ import { promptUserForConfigs } from "./user_config_prompts";
import { FlutterWidgetConstructorDecoratorProvider } from "./providers/flutter_widget_constructor_decoration";
import { DartPackageFileContentProvider } from "./providers/dart_package_file_content_provider";
import { ClosingLabelsDecorations } from "./decorations/closing_labels_decorations";
import { DebugConfigProvider, DART_CLI_DEBUG_TYPE, FLUTTER_DEBUG_TYPE } from "./providers/debug_config_provider";

const DART_MODE: vs.DocumentFilter[] = [{ language: "dart", scheme: "file" }, { language: "dart", scheme: "dart-package" }];
const HTML_MODE: vs.DocumentFilter[] = [{ language: "html", scheme: "file" }, { language: "html", scheme: "dart-package" }];

const DART_DOWNLOAD_URL = "https://www.dartlang.org/install";
const FLUTTER_DOWNLOAD_URL = "https://flutter.io/setup/";

Expand Down Expand Up @@ -224,6 +226,10 @@ export function activate(context: vs.ExtensionContext) {
}));
}

// Set up debug stuff.
let debugType = util.isFlutterProject ? FLUTTER_DEBUG_TYPE : DART_CLI_DEBUG_TYPE;
context.subscriptions.push(vs.debug.registerDebugConfigurationProvider(debugType, new DebugConfigProvider(debugType, sdks, flutterDaemon && flutterDaemon.deviceManager)));

// Setup that requires server version/capabilities.
let connectedSetup = analyzer.registerForServerConnected(sc => {
connectedSetup.dispose();
Expand Down
77 changes: 77 additions & 0 deletions src/providers/debug_config_provider.ts
@@ -0,0 +1,77 @@
"use strict";

import * as path from "path";
import { analytics } from "../analytics";
import { config } from "../config";
import { DebugConfigurationProvider, WorkspaceFolder, CancellationToken, DebugConfiguration, ProviderResult } from "vscode";
import { FlutterLaunchRequestArguments, isWin } from "../debug/utils";
import { Sdks, isFlutterProject } from "../utils";
import { FlutterDeviceManager } from "../flutter/device_manager";
import { SdkCommands } from "../commands/sdk";

export const DART_CLI_DEBUG_TYPE = "dart-cli";
export const FLUTTER_DEBUG_TYPE = "flutter";

export class DebugConfigProvider implements DebugConfigurationProvider {
private debugType: String;
private sdks: Sdks;
private deviceManager: FlutterDeviceManager;

constructor(debugType: String, sdks: Sdks, deviceManager: FlutterDeviceManager) {
this.debugType = debugType;
this.sdks = sdks;
this.deviceManager = deviceManager;
}

// TODO: This file has two ways of knowing whether it's a Flutter debug session - this.debugType and util.isFlutterProject.
// Hopefully these will always match, but since a user can edit launch.json it's not guaranteed. We should probably
// do something to consolidate these and/or reject when the launch config doesn't match the proejct type.

provideDebugConfigurations(folder: WorkspaceFolder | undefined, token?: CancellationToken): ProviderResult<DebugConfiguration[]> {
if (this.debugType == DART_CLI_DEBUG_TYPE)
return [{
"name": "Dart command line",
"type": "dart-cli",
"request": "launch",
"program": "${workspaceRoot}/bin/main.dart"
}];
else if (this.debugType == FLUTTER_DEBUG_TYPE)
return [{
"name": "Flutter mobile app",
"type": "flutter",
"request": "launch"
}];
}

resolveDebugConfiguration(folder: WorkspaceFolder | undefined, debugConfig: DebugConfiguration, token?: CancellationToken): ProviderResult<DebugConfiguration> {
// TODO: This cast feels nasty?
this.setupDebugConfig(<FlutterLaunchRequestArguments><any>debugConfig, this.sdks, this.deviceManager && this.deviceManager.currentDevice ? this.deviceManager.currentDevice.id : null);

if (isFlutterProject) {
SdkCommands.resetFlutterSettings();
debugConfig.program = debugConfig.program || "${workspaceRoot}/lib/main.dart"; // Set Flutter default path.
}

return debugConfig;
}

private setupDebugConfig(debugConfig: FlutterLaunchRequestArguments, sdks: Sdks, deviceId: string) {
analytics.logDebuggerStart();

const dartExec = isWin ? "dart.exe" : "dart";
const flutterExec = isWin ? "flutter.bat" : "flutter";

// Attach any properties that weren't explicitly set.
debugConfig.cwd = debugConfig.cwd || "${workspaceRoot}";
debugConfig.args = debugConfig.args || [];
debugConfig.dartPath = debugConfig.dartPath || path.join(sdks.dart, "bin", dartExec);
debugConfig.observatoryLogFile = debugConfig.observatoryLogFile || config.observatoryLogFile;
debugConfig.debugSdkLibraries = debugConfig.debugSdkLibraries || config.debugSdkLibraries;
debugConfig.debugExternalLibraries = debugConfig.debugExternalLibraries || config.debugExternalLibraries;
if (debugConfig.checkedMode === undefined)
debugConfig.checkedMode = true;
debugConfig.flutterPath = debugConfig.flutterPath || (sdks.flutter ? path.join(sdks.flutter, "bin", flutterExec) : null);
debugConfig.flutterRunLogFile = debugConfig.flutterRunLogFile || config.flutterRunLogFile;
debugConfig.deviceId = debugConfig.deviceId || deviceId;
}
}

0 comments on commit e26f46a

Please sign in to comment.