From 46e2461c5879b56178ce69ca0eaa76f430228b35 Mon Sep 17 00:00:00 2001 From: Artem Egorov Date: Mon, 30 Jul 2018 16:40:47 +0300 Subject: [PATCH] Added some logging for debug (#759) Added some logging for debug --- src/debugger/nodeDebugWrapper.ts | 2 ++ src/extension/commandPaletteHandler.ts | 33 +++++++++++++++----------- src/extension/rn-extension.ts | 13 +++++++++- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/debugger/nodeDebugWrapper.ts b/src/debugger/nodeDebugWrapper.ts index 708d5f937..7013e89a4 100644 --- a/src/debugger/nodeDebugWrapper.ts +++ b/src/debugger/nodeDebugWrapper.ts @@ -76,6 +76,7 @@ export function makeSession( private launch(request: DebugProtocol.Request): void { this.requestSetup(request.arguments) .then(() => { + logger.verbose(`Handle launch request: ${request.arguments}`); return this.remoteExtension.launch(request); }) .then(() => { @@ -98,6 +99,7 @@ export function makeSession( private attach(request: DebugProtocol.Request): void { this.requestSetup(request.arguments) .then(() => { + logger.verbose(`Handle attach request: ${request.arguments}`); return this.remoteExtension.getPackagerPort(request.arguments.program); }) .then((packagerPort: number) => { diff --git a/src/extension/commandPaletteHandler.ts b/src/extension/commandPaletteHandler.ts index f91c1db73..f42d3fc73 100644 --- a/src/extension/commandPaletteHandler.ts +++ b/src/extension/commandPaletteHandler.ts @@ -35,6 +35,7 @@ export class CommandPaletteHandler { private static logger: OutputChannelLogger = OutputChannelLogger.getMainChannel(); public static addFolder(workspaceFolder: vscode.WorkspaceFolder, stuff: IReactNativeStuff): void { + this.logger.debug(`Command palette: added folder ${workspaceFolder.uri.fsPath}`); this.projectsCache[workspaceFolder.uri.fsPath] = { ...stuff, workspaceFolder, @@ -254,19 +255,21 @@ export class CommandPaletteHandler { return TelemetryHelper.generate("RNCommand", extProps, (generator) => { generator.add("command", rnCommand, false); const projectRoot = SettingsHelper.getReactNativeProjectRoot(workspaceFolder.uri.fsPath); - return ReactNativeProjectHelper.isReactNativeProject(projectRoot).then(isRNProject => { - generator.add("isRNProject", isRNProject, false); - if (isRNProject) { - // Bring the log channel to focus - CommandPaletteHandler.logger.setFocusOnLogChannel(); - - // Execute the operation - return operation(); - } else { - vscode.window.showErrorMessage("Current workspace is not a React Native project."); - return; - } - }); + this.logger.debug(`Command palette: run project ${projectRoot} in context`); + return ReactNativeProjectHelper.isReactNativeProject(projectRoot) + .then(isRNProject => { + generator.add("isRNProject", isRNProject, false); + if (isRNProject) { + // Bring the log channel to focus + this.logger.setFocusOnLogChannel(); + + // Execute the operation + return operation(); + } else { + vscode.window.showErrorMessage(`${projectRoot} workspace is not a React Native project.`); + return; + } + }); }); } @@ -325,14 +328,16 @@ export class CommandPaletteHandler { vscode.window.showQuickPick(keys) .then((selected) => { if (selected) { + this.logger.debug(`Command palette: selected project ${selected}`); resolve(this.projectsCache[selected]); } }, reject); }); } else if (keys.length === 1) { + this.logger.debug(`Command palette: once project ${keys[0]}`); return Q.resolve(this.projectsCache[keys[0]]); } else { - return Q.reject(new Error("Current workspace is not a React Native project.")); + return Q.reject(new Error("Current workspace does not contain React Native projects.")); } } diff --git a/src/extension/rn-extension.ts b/src/extension/rn-extension.ts index 5647e44f0..33163c245 100644 --- a/src/extension/rn-extension.ts +++ b/src/extension/rn-extension.ts @@ -45,7 +45,9 @@ interface ISetupableDisposable extends vscode.Disposable { } export function activate(context: vscode.ExtensionContext): Q.Promise { - const appVersion = require("../../package.json").version; + outputChannelLogger.debug("Begin to activate..."); + const appVersion = require(path.resolve(__dirname, "../../package.json")).version; + outputChannelLogger.debug(`Extension version: ${appVersion}`); const ExtensionTelemetryReporter = require("vscode-extension-telemetry").default; const reporter = new ExtensionTelemetryReporter(APP_NAME, appVersion, Telemetry.APPINSIGHTS_INSTRUMENTATIONKEY); return entryPointHandler.runApp(APP_NAME, appVersion, ErrorHelper.getInternalError(InternalErrorCode.ExtensionActivationFailed), reporter, function activateRunApp() { @@ -59,9 +61,12 @@ export function activate(context: vscode.ExtensionContext): Q.Promise { const workspaceFolders: vscode.WorkspaceFolder[] | undefined = vscode.workspace.workspaceFolders; let promises: any = []; if (workspaceFolders) { + outputChannelLogger.debug(`Projects found: ${workspaceFolders.length}`); workspaceFolders.forEach((folder: vscode.WorkspaceFolder) => { promises.push(onFolderAdded(context, folder)); }); + } else { + outputChannelLogger.warning("Could not found workspace while activating"); } return Q.all(promises).then(() => { @@ -105,8 +110,10 @@ function onChangeConfiguration(context: vscode.ExtensionContext) { function onFolderAdded(context: vscode.ExtensionContext, folder: vscode.WorkspaceFolder): Q.Promise { let rootPath = folder.uri.fsPath; let projectRootPath = SettingsHelper.getReactNativeProjectRoot(rootPath); + outputChannelLogger.debug(`Add project: ${projectRootPath}`); return ReactNativeProjectHelper.getReactNativeVersion(projectRootPath) .then(version => { + outputChannelLogger.debug(`React Native version: ${version}`); let promises = []; if (version && isSupportedVersion(version)) { promises.push(entryPointHandler.runFunction("debugger.setupLauncherStub", ErrorHelper.getInternalError(InternalErrorCode.DebuggerStubLauncherFailed), () => { @@ -132,6 +139,8 @@ function onFolderAdded(context: vscode.ExtensionContext, folder: vscode.Workspac ErrorHelper.getInternalError(InternalErrorCode.NodeDebuggerConfigurationFailed), () => { return configureNodeDebuggerLocation(); })); + } else { + outputChannelLogger.debug(`react-native@${version} isn't supported`); } return Q.all(promises).then(() => {}); @@ -145,6 +154,7 @@ function onFolderRemoved(context: vscode.ExtensionContext, folder: vscode.Worksp project[key].dispose(); } }); + outputChannelLogger.debug(`Delete project: ${folder.uri.fsPath}`); CommandPaletteHandler.delFolder(folder); try { // Preventing memory leaks @@ -211,6 +221,7 @@ function registerVSCodeCommand(context: vscode.ExtensionContext, commandName: st isPii: false, }, }; + outputChannelLogger.debug(`Run command: ${commandName}`); return entryPointHandler.runFunctionWExtProps(`commandPalette.${commandName}`, extProps, error, commandHandler); })); }