Skip to content

Commit

Permalink
Respond to more peer review
Browse files Browse the repository at this point in the history
  • Loading branch information
captainsafia committed May 11, 2020
1 parent 6757fca commit ce06cf1
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
"configurationAttributes": {
"launch": {
"properties": {
"cwd": {
"type": "string",
"description": "The directory of the Blazor WASM app, defaults to the workspace folder.",
"default": "${workspaceFolder}"
},
"env": {
"type": "object",
"description": "Environment variables passed to dotnet"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as vscode from 'vscode';

import { RazorLogger } from './RazorLogger';
import { RazorLogger } from '../RazorLogger';

export class BlazorDebugConfigurationProvider implements vscode.DebugConfigurationProvider {

Expand All @@ -18,7 +18,7 @@ export class BlazorDebugConfigurationProvider implements vscode.DebugConfigurati
request: 'launch',
program: 'dotnet',
args: ['run'],
cwd: '${workspaceFolder}',
cwd: configuration.cwd,
env: {
ASPNETCORE_ENVIRONMENT: 'Development',
...configuration.env,
Expand All @@ -34,23 +34,31 @@ export class BlazorDebugConfigurationProvider implements vscode.DebugConfigurati
inspectUri: '{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}',
trace: configuration.trace || false,
};
let showErrorInfo = false;

try {
await this.vscodeType.debug.startDebugging(folder, app);
try {
await this.vscodeType.debug.startDebugging(folder, browser);
this.logger.logVerbose('[DEBUGGER] Launching JavaScript debugger...');
this.logger.logVerbose('[DEBUGGER] Launching browser debugger...');
} catch (error) {
this.logger.logError(
'[DEBUGGER] Error when launching browser debugger: ',
error,
);
showErrorInfo = true;
}
} catch (error) {
this.logger.logError(
'[DEBUGGER] Error when launching application: ',
error,
);
showErrorInfo = true;
}

if (showErrorInfo) {
const message = `There was an unexpected error while launching your debugging session. Check the console for helpful logs and visit https://aka.ms/blazorwasmcodedebug for more info.`;
this.vscodeType.window.showErrorMessage(message);
}

return undefined;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */

import { exec } from 'child_process';
import * as psList from 'ps-list';
import { DebugSession } from 'vscode';

import { RazorLogger } from '../RazorLogger';

export async function onDidTerminateDebugSession(
event: DebugSession,
logger: RazorLogger,
) {
logger.logVerbose('Terminating debugging session...');
if (process.platform !== 'win32') {
try {
const processes = await psList();
const devserver = processes.find(
(process: psList.ProcessDescriptor) =>
!!(process && process.cmd && process.cmd.includes('blazor-devserver')),
);
if (devserver) {
const command = `kill ${devserver.pid}`;
exec(command, (error) => {
if (error) {
logger.logError(
'[DEBUGGER] Error during debug process clean-up: ',
error,
);
}
return logger.logVerbose(
'[DEBUGGER] Debug process clean-up complete.',
);
});
}
} catch (error) {
logger.logError('Error retrieving processes to clean-up: ', error);
}
}
}
38 changes: 3 additions & 35 deletions src/Razor/src/Microsoft.AspNetCore.Razor.VSCode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */

import { exec } from 'child_process';
import * as psList from 'ps-list';
import * as vscode from 'vscode';
import * as vscodeapi from 'vscode';
import { ExtensionContext } from 'vscode';
import { BlazorDebugConfigurationProvider } from './BlazorDebugConfigurationProvider';
import { BlazorDebugConfigurationProvider } from './BlazorDebug/BlazorDebugConfigurationProvider';
import { onDidTerminateDebugSession } from './BlazorDebug/Events';
import { CompositeCodeActionTranslator } from './CodeActions/CompositeRazorCodeActionTranslator';
import { RazorCodeActionProvider } from './CodeActions/RazorCodeActionProvider';
import { RazorFullyQualifiedCodeActionTranslator } from './CodeActions/RazorFullyQualifiedCodeActionTranslator';
Expand Down Expand Up @@ -192,38 +191,7 @@ export async function activate(vscodeType: typeof vscodeapi, context: ExtensionC
* On non-Windows platforms, we need to terminate the Blazor
* dev server and its child processes.
*/
vscodeType.debug.onDidTerminateDebugSession(async (event) => {
logger.logVerbose('Terminating debugging session...');
if (process.platform !== 'win32') {
try {
const processes = await psList();
const devserver = processes.find(
(process: psList.ProcessDescriptor) =>
!!(
process &&
process.cmd &&
process.cmd.includes('blazor-devserver')
),
);
if (devserver) {
const command = `kill ${devserver.pid}`;
exec(command, (error) => {
if (error) {
logger.logError(
'[DEBUGGER] Error during debug process clean-up: ',
error,
);
}
return logger.logVerbose(
'[DEBUGGER] Debug process clean-up complete.',
);
});
}
} catch (error) {
logger.logError('Error retrieving processes to clean-up: ', error);
}
}
});
vscodeType.debug.onDidTerminateDebugSession(async event => onDidTerminateDebugSession(event, logger));

languageServerClient.onStarted(async () => {
await documentManager.initialize();
Expand Down

0 comments on commit ce06cf1

Please sign in to comment.