Path: blob/main/extensions/copilot/src/util/vs/base/common/observableInternal/debugLocation.ts
13406 views
//!!! DO NOT modify, this file was COPIED from 'microsoft/vscode'12/*---------------------------------------------------------------------------------------------3* Copyright (c) Microsoft Corporation. All rights reserved.4* Licensed under the MIT License. See License.txt in the project root for license information.5*--------------------------------------------------------------------------------------------*/67export type DebugLocation = DebugLocationImpl | undefined;89export namespace DebugLocation {10let enabled = false;1112export function enable(): void {13enabled = true;14}1516export function ofCaller(): DebugLocation {17if (!enabled) {18return undefined;19}20const Err = Error as ErrorConstructor & { stackTraceLimit: number };2122const l = Err.stackTraceLimit;23Err.stackTraceLimit = 3;24const stack = new Error().stack!;25Err.stackTraceLimit = l;2627return DebugLocationImpl.fromStack(stack, 2);28}29}3031class DebugLocationImpl implements ILocation {32public static fromStack(stack: string, parentIdx: number): DebugLocationImpl | undefined {33const lines = stack.split('\n');34const location = parseLine(lines[parentIdx + 1]);35if (location) {36return new DebugLocationImpl(37location.fileName,38location.line,39location.column,40location.id41);42} else {43return undefined;44}45}4647constructor(48public readonly fileName: string,49public readonly line: number,50public readonly column: number,51public readonly id: string,52) {53}54}555657export interface ILocation {58fileName: string;59line: number;60column: number;61id: string;62}6364function parseLine(stackLine: string): ILocation | undefined {65const match = stackLine.match(/\((.*):(\d+):(\d+)\)/);66if (match) {67return {68fileName: match[1],69line: parseInt(match[2]),70column: parseInt(match[3]),71id: stackLine,72};73}7475const match2 = stackLine.match(/at ([^\(\)]*):(\d+):(\d+)/);7677if (match2) {78return {79fileName: match2[1],80line: parseInt(match2[2]),81column: parseInt(match2[3]),82id: stackLine,83};84}8586return undefined;87}888990