debugSource.ts 2.2 KB
Newer Older
I
isidor 已提交
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

I
isidor 已提交
6
import * as nls from 'vs/nls';
I
isidor 已提交
7
import { TPromise } from 'vs/base/common/winjs.base';
I
isidor 已提交
8
import uri from 'vs/base/common/uri';
I
isidor 已提交
9
import * as paths from 'vs/base/common/paths';
10
import { DEBUG_SCHEME } from 'vs/workbench/parts/debug/common/debug';
I
isidor 已提交
11 12
import { IRange } from 'vs/editor/common/core/range';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
I
isidor 已提交
13

I
isidor 已提交
14 15
const UNKNOWN_SOURCE_LABEL = nls.localize('unknownSource', "Unknown Source");

I
isidor 已提交
16 17
export class Source {

18
	public readonly uri: uri;
19
	public available: boolean;
I
isidor 已提交
20

A
Andre Weinand 已提交
21
	constructor(public readonly raw: DebugProtocol.Source, sessionId: string) {
I
isidor 已提交
22 23 24
		if (!raw) {
			this.raw = { name: UNKNOWN_SOURCE_LABEL };
		}
25
		this.available = this.raw.name !== UNKNOWN_SOURCE_LABEL;
26 27
		const path = this.raw.path || this.raw.name;
		if (this.raw.sourceReference > 0) {
A
Andre Weinand 已提交
28
			this.uri = uri.parse(`${DEBUG_SCHEME}:${encodeURIComponent(path)}?session=${encodeURIComponent(sessionId)}&ref=${this.raw.sourceReference}`);
29
		} else {
I
isidor 已提交
30 31 32 33 34
			if (paths.isAbsolute(path)) {
				this.uri = uri.file(path); // path should better be absolute!
			} else {
				this.uri = uri.parse(path);
			}
35
		}
I
isidor 已提交
36 37
	}

38 39 40 41 42 43 44 45
	public get name() {
		return this.raw.name;
	}

	public get origin() {
		return this.raw.origin;
	}

46 47 48 49
	public get presentationHint() {
		return this.raw.presentationHint;
	}

50 51 52 53
	public get reference() {
		return this.raw.sourceReference;
	}

54
	public get inMemory() {
55
		return this.uri.scheme === DEBUG_SCHEME;
I
isidor 已提交
56
	}
I
isidor 已提交
57 58 59 60 61 62 63 64 65 66 67 68 69 70

	public openInEditor(editorService: IWorkbenchEditorService, selection: IRange, preserveFocus?: boolean, sideBySide?: boolean): TPromise<any> {
		return !this.available ? TPromise.as(null) : editorService.openEditor({
			resource: this.uri,
			description: this.origin,
			options: {
				preserveFocus,
				selection,
				revealIfVisible: true,
				revealInCenterIfOutsideViewport: true,
				pinned: !preserveFocus && !this.inMemory
			}
		}, sideBySide);
	}
I
isidor 已提交
71
}