Skip to content

Commit

Permalink
Added some logging for debug (microsoft#759)
Browse files Browse the repository at this point in the history
Added some logging for debug
  • Loading branch information
itoys authored Jul 30, 2018
1 parent 43e1a99 commit 46e2461
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/debugger/nodeDebugWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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) => {
Expand Down
33 changes: 19 additions & 14 deletions src/extension/commandPaletteHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
});
});
}

Expand Down Expand Up @@ -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."));
}
}

Expand Down
13 changes: 12 additions & 1 deletion src/extension/rn-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ interface ISetupableDisposable extends vscode.Disposable {
}

export function activate(context: vscode.ExtensionContext): Q.Promise<void> {
const appVersion = <string>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() {
Expand All @@ -59,9 +61,12 @@ export function activate(context: vscode.ExtensionContext): Q.Promise<void> {
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(() => {
Expand Down Expand Up @@ -105,8 +110,10 @@ function onChangeConfiguration(context: vscode.ExtensionContext) {
function onFolderAdded(context: vscode.ExtensionContext, folder: vscode.WorkspaceFolder): Q.Promise<void> {
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), () => {
Expand All @@ -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(() => {});
Expand All @@ -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
Expand Down Expand Up @@ -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);
}));
}

0 comments on commit 46e2461

Please sign in to comment.