提交 5ef5a112 编写于 作者: I isidor

debugService.ts - linting

上级 f5169146
......@@ -31,7 +31,6 @@ import { IViewletService } from 'vs/workbench/services/viewlet/common/viewletSer
import { IPartService } from 'vs/workbench/services/part/common/partService';
import { ITextFileService } from 'vs/workbench/parts/files/common/files';
import { IWorkspaceContextService } from 'vs/workbench/services/workspace/common/contextService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IFileService, FileChangesEvent, FileChangeType, EventType } from 'vs/platform/files/common/files';
import { IEventService } from 'vs/platform/event/common/event';
......@@ -40,18 +39,18 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
import { IPluginService, IPluginDescription } from 'vs/platform/plugins/common/plugins';
import { IPluginService } from 'vs/platform/plugins/common/plugins';
import { IOutputService } from 'vs/workbench/parts/output/common/output';
import { IKeybindingService, IKeybindingContextKey } from 'vs/platform/keybinding/common/keybindingService';
import { IWindowService, IBroadcast } from 'vs/workbench/services/window/electron-browser/windowService';
import { ILogEntry, PLUGIN_LOG_BROADCAST_CHANNEL, PLUGIN_ATTACH_BROADCAST_CHANNEL } from 'vs/workbench/services/thread/electron-browser/threadService';
var DEBUG_BREAKPOINTS_KEY = 'debug.breakpoint';
var DEBUG_BREAKPOINTS_ACTIVATED_KEY = 'debug.breakpointactivated';
var DEBUG_FUNCTION_BREAKPOINTS_KEY = 'debug.functionbreakpoint';
var DEBUG_EXCEPTION_BREAKPOINTS_KEY = 'debug.exceptionbreakpoint';
var DEBUG_WATCH_EXPRESSIONS_KEY = 'debug.watchexpressions';
var DEBUG_SELECTED_CONFIG_NAME_KEY = 'debug.selectedconfigname';
const DEBUG_BREAKPOINTS_KEY = 'debug.breakpoint';
const DEBUG_BREAKPOINTS_ACTIVATED_KEY = 'debug.breakpointactivated';
const DEBUG_FUNCTION_BREAKPOINTS_KEY = 'debug.functionbreakpoint';
const DEBUG_EXCEPTION_BREAKPOINTS_KEY = 'debug.exceptionbreakpoint';
const DEBUG_WATCH_EXPRESSIONS_KEY = 'debug.watchexpressions';
const DEBUG_SELECTED_CONFIG_NAME_KEY = 'debug.selectedconfigname';
export class DebugService extends ee.EventEmitter implements debug.IDebugService {
public serviceId = debug.IDebugService;
......@@ -91,7 +90,7 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
this.debugStringEditorInputs = [];
this.session = null;
this.state = debug.State.Inactive;
// There is a cycle if taskService gets injected, use a workaround.
// there is a cycle if taskService gets injected, use a workaround.
this.taskService = this.instantiationService.getInstance(ITaskService);
if (!this.contextService.getWorkspace()) {
......@@ -133,20 +132,20 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
private onBroadcast(broadcast: IBroadcast): void {
// Attach: PH is ready to be attached to
// attach: PH is ready to be attached to
if (broadcast.channel === PLUGIN_ATTACH_BROADCAST_CHANNEL) {
this.rawAttach(broadcast.payload.port);
return;
}
// From this point on we require an active session
// from this point on we require an active session
let session = this.getActiveSession();
if (!session || session.getType() !== 'extensionHost') {
return; // we are only intersted if we have an active debug session for extensionHost
}
// A plugin logged output, show it inside the REPL
// a plugin logged output, show it inside the REPL
if (broadcast.channel === PLUGIN_LOG_BROADCAST_CHANNEL) {
let extensionOutput: ILogEntry = broadcast.payload;
let sev = extensionOutput.severity === 'warn' ? severity.Warning : extensionOutput.severity === 'error' ? severity.Error : severity.Info;
......@@ -159,36 +158,36 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
args.push(extensionOutput.arguments);
}
// Add output for each argument logged
// add output for each argument logged
let simpleVals: any[] = [];
for (let i = 0; i < args.length; i++) {
let a = args[i];
// Undefined gets printed as 'undefined'
// undefined gets printed as 'undefined'
if (typeof a === 'undefined') {
simpleVals.push('undefined');
}
// Null gets printed as 'null'
// null gets printed as 'null'
else if (a === null) {
simpleVals.push('null');
}
// Objects & Arrays are special because we want to inspect them in the REPL
// objects & arrays are special because we want to inspect them in the REPL
else if (types.isObject(a) || Array.isArray(a)) {
// Flush any existing simple values logged
// flush any existing simple values logged
if (simpleVals.length) {
this.logToRepl(simpleVals.join(' '), sev);
simpleVals = [];
}
// Show object
// show object
this.logToRepl(a, sev);
}
// String: watch out for % replacement directive
// String substitution and formatting @ https://developer.chrome.com/devtools/docs/console
// string: watch out for % replacement directive
// string substitution and formatting @ https://developer.chrome.com/devtools/docs/console
else if (typeof a === 'string') {
let buf = '';
......@@ -211,12 +210,12 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
}
}
// Flush simple values
// flush simple values
if (simpleVals.length) {
this.logToRepl(simpleVals.join(' '), sev);
}
// Show repl
// show repl
this.revealRepl(true /* in background */).done(null, errors.onUnexpectedError);
}
}
......@@ -229,14 +228,14 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
this.toDispose.push(this.session.addListener2(debug.SessionEvents.STOPPED, (event: DebugProtocol.StoppedEvent) => {
this.setStateAndEmit(debug.State.Stopped, event.body.reason);
var threadId = event.body.threadId;
const threadId = event.body.threadId;
this.getThreadData(threadId).then(() => {
this.session.stackTrace({ threadId: threadId, levels: 20 }).done((result) => {
this.model.rawUpdate({ threadId: threadId, callStack: result.body.stackFrames, exception: event.body && event.body.reason === 'exception' });
this.windowService.getWindow().focus();
var callStack = this.model.getThreads()[threadId].callStack;
const callStack = this.model.getThreads()[threadId].callStack;
if (callStack.length > 0) {
this.setFocusedStackFrameAndEvaluate(callStack[0]);
this.openOrRevealEditor(callStack[0].source, callStack[0].lineNumber, false, false).done(null, errors.onUnexpectedError);
......@@ -330,7 +329,7 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
}
private loadExceptionBreakpoints(): debug.IExceptionBreakpoint[] {
var result: debug.IExceptionBreakpoint[] = null;
let result: debug.IExceptionBreakpoint[] = null;
try {
result = JSON.parse(this.storageService.get(DEBUG_EXCEPTION_BREAKPOINTS_KEY, StorageScope.WORKSPACE, '[]')).map((exBreakpoint: any) => {
return new model.ExceptionBreakpoint(exBreakpoint.name, exBreakpoint.enabled);
......@@ -401,7 +400,7 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
public toggleEnablement(element: debug.IEnablement): Promise {
this.model.toggleEnablement(element);
if (element instanceof model.Breakpoint) {
var breakpoint = <model.Breakpoint> element;
const breakpoint = <model.Breakpoint> element;
return this.sendBreakpoints(breakpoint.source.uri);
} else if (element instanceof model.FunctionBreakpoint) {
// TODO@Isidor send function breakpoints and return
......@@ -532,7 +531,7 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
return Promise.as(true);
}
// Run a build task before starting a debug session
// run a build task before starting a debug session
return this.taskService.tasks().then(descriptions => {
let filteredTasks = descriptions.filter(task => task.name === config.preLaunchTask);
if (filteredTasks.length !== 1) {
......@@ -540,17 +539,17 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
return Promise.as(true);
}
// Task is already running - nothing to do.
// task is already running - nothing to do.
if (this.lastTaskEvent && this.lastTaskEvent.taskName === config.preLaunchTask) {
return Promise.as(true);
}
if (this.lastTaskEvent) {
// There is a different task running currently.
// there is a different task running currently.
return Promise.wrapError(errors.create(nls.localize('differentTaskRunning', "There is a task {0} running. Can not run pre launch task {1}.", this.lastTaskEvent.taskName, config.preLaunchTask)));
}
// No task running, execute the preLaunchTask.
// no task running, execute the preLaunchTask.
this.outputService.showOutput('Tasks', true, true);
const taskPromise = this.taskService.run(filteredTasks[0].id).then(result => {
......@@ -584,13 +583,13 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
}
public restartSession(): Promise {
return this.session ? this.session.disconnect(true).then(() => {
return this.session ? this.session.disconnect(true).then(() =>
new Promise(c => {
setTimeout(() => {
this.createSession(false).then(() => c(true));
}, 300);
});
}) : this.createSession(false);
})
) : this.createSession(false);
}
public getActiveSession(): debug.IRawDebugSession {
......@@ -601,11 +600,11 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
try {
this.debugStringEditorInputs = lifecycle.disposeAll(this.debugStringEditorInputs);
} catch (e) {
// An internal module might be open so the dispose can throw -> ignore and continue with stop session.
// an internal module might be open so the dispose can throw -> ignore and continue with stop session.
}
if (this.session) {
var bpsExist = this.model.getBreakpoints().length > 0;
const bpsExist = this.model.getBreakpoints().length > 0;
this.telemetryService.publicLog('debugSessionStop', { type: this.session.getType(), success: this.session.emittedStopped || !bpsExist, sessionLengthInSeconds: this.session.getLengthInSeconds(), breakpointCount: this.model.getBreakpoints().length });
}
this.session = null;
......@@ -616,7 +615,7 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
this.setFocusedStackFrameAndEvaluate(null);
this.setStateAndEmit(debug.State.Inactive);
// Set breakpoints back to unverified since the session ended.
// set breakpoints back to unverified since the session ended.
const data: {[id: string]: { line: number, verified: boolean } } = { };
this.model.getBreakpoints().forEach(bp => data[bp.getId()] = { line: bp.lineNumber, verified: false });
this.model.updateBreakpoints(data);
......@@ -634,7 +633,7 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
public openOrRevealEditor(source: Source, lineNumber: number, preserveFocus: boolean, sideBySide: boolean): Promise {
const visibleEditors = this.editorService.getVisibleEditors();
for (var i = 0; i < visibleEditors.length; i++) {
for (let i = 0; i < visibleEditors.length; i++) {
const fileInput = wbeditorcommon.asFileEditorInput(visibleEditors[i].input);
if (fileInput && fileInput.getResource().toString() === source.uri.toString()) {
const control = <editorbrowser.ICodeEditor>visibleEditors[i].getControl();
......@@ -649,7 +648,7 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
}
if (source.inMemory) {
// Internal module
// internal module
if (source.reference !== 0 && this.session) {
return this.session.source({ sourceReference: source.reference }).then(response => {
const editorInput = this.getDebugStringEditorInput(source, response.body.content, mime.guessMimeTypes(source.name)[0]);
......@@ -694,7 +693,7 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
public revealRepl(inBackground: boolean = false): Promise {
let editors = this.editorService.getVisibleEditors();
// First check if repl is already opened
// first check if repl is already opened
for (let i = 0; i < editors.length; i++) {
let editor = editors[i];
if (editor.input instanceof debuginputs.ReplEditorInput) {
......@@ -706,7 +705,7 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
}
}
// Then find a position but try to not replace an existing file editor in any of the positions
// then find a position but try to not replace an existing file editor in any of the positions
let position = Position.LEFT;
let lastIndex = editors.length - 1;
if (editors.length === 3) {
......@@ -751,10 +750,10 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
}
private getDebugStringEditorInput(source: Source, value: string, mtype: string): debuginputs.DebugStringEditorInput {
var filtered = this.debugStringEditorInputs.filter(input => input.getResource().toString() === source.uri.toString());
const filtered = this.debugStringEditorInputs.filter(input => input.getResource().toString() === source.uri.toString());
if (filtered.length === 0) {
var result = this.instantiationService.createInstance(debuginputs.DebugStringEditorInput, source.name, source.uri, 'internal module', value, mtype, void 0);
const result = this.instantiationService.createInstance(debuginputs.DebugStringEditorInput, source.name, source.uri, 'internal module', value, mtype, void 0);
this.debugStringEditorInputs.push(result);
return result;
} else {
......@@ -792,7 +791,7 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
return Promise.as(null);
}
var enabledExBreakpoints = this.model.getExceptionBreakpoints().filter(exb => exb.enabled);
const enabledExBreakpoints = this.model.getExceptionBreakpoints().filter(exb => exb.enabled);
return this.session.setExceptionBreakpoints({ filters: enabledExBreakpoints.map(exb => exb.name) });
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册