MCPcopy
hub / github.com/microsoft/vscode-js-debug / DebugLinkUi

Class DebugLinkUi

src/ui/debugLinkUI.ts:58–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56
57@injectable()
58export class DebugLinkUi implements IExtensionContribution {
59 private mostRecentLink: string | undefined;
60
61 constructor(
62 @inject(IDefaultBrowserProvider) private defaultBrowser: IDefaultBrowserProvider,
63 @inject(ExtensionContext) private context: vscode.ExtensionContext,
64 ) {}
65
66 /**
67 * Registers the link UI for the extension.
68 */
69 public register(context: vscode.ExtensionContext) {
70 context.subscriptions.push(
71 vscode.commands.registerCommand(Commands.DebugLink, link => this.handle(link)),
72 );
73 }
74
75 /**
76 * Handles a command, optionally called with a link.
77 */
78 public async handle(link?: string) {
79 link = link ?? (await this.getLinkFromTextEditor()) ?? (await this.getLinkFromQuickInput());
80 if (!link) {
81 return;
82 }
83
84 let debugType: DebugType.Chrome | DebugType.Edge = DebugType.Chrome;
85 try {
86 if ((await this.defaultBrowser.lookup()) === DefaultBrowser.Edge) {
87 debugType = DebugType.Edge;
88 }
89 } catch {
90 // ignored
91 }
92
93 const baseConfig = readConfig(vscode.workspace, Configuration.DebugByLinkOptions) ?? {};
94 const config = {
95 ...(typeof baseConfig === 'string' ? {} : baseConfig),
96 type: getPreferredOrDebugType(debugType),
97 name: link,
98 request: 'launch',
99 url: link,
100 };
101
102 vscode.debug.startDebugging(vscode.workspace.workspaceFolders?.[0], config);
103 this.persistConfig(config);
104 }
105
106 private getLinkFromTextEditor() {
107 const editor = vscode.window.activeTextEditor;
108 if (!editor) {
109 return;
110 }
111
112 return getPossibleUrl(editor.document.getText(editor.selection), true);
113 }
114
115 private async getLinkFromQuickInput() {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected