|
2 | 2 | * Copyright (C) Microsoft Corporation. All rights reserved. |
3 | 3 | *--------------------------------------------------------*/ |
4 | 4 |
|
| 5 | +import * as l10n from '@vscode/l10n'; |
5 | 6 | import { injectable } from 'inversify'; |
| 7 | +import { basename } from 'path'; |
6 | 8 | import * as vscode from 'vscode'; |
7 | 9 | import { DebugType } from '../../common/contributionUtils'; |
8 | 10 | import { |
9 | 11 | AnyEditorBrowserConfiguration, |
10 | 12 | editorBrowserAttachConfigDefaults, |
11 | 13 | editorBrowserLaunchConfigDefaults, |
| 14 | + IEditorBrowserLaunchConfiguration, |
| 15 | + ResolvingConfiguration, |
12 | 16 | ResolvingEditorBrowserConfiguration, |
13 | 17 | } from '../../configuration'; |
| 18 | +import { BaseConfigurationProvider } from './baseConfigurationProvider'; |
14 | 19 | import { BaseConfigurationResolver } from './baseConfigurationResolver'; |
15 | 20 |
|
16 | 21 | /** |
@@ -50,3 +55,47 @@ export class EditorBrowserDebugConfigurationResolver |
50 | 55 | return [config.rootPath, config.webRoot]; |
51 | 56 | } |
52 | 57 | } |
| 58 | + |
| 59 | +@injectable() |
| 60 | +export class EditorBrowserDebugConfigurationProvider |
| 61 | + extends BaseConfigurationProvider<IEditorBrowserLaunchConfiguration> |
| 62 | +{ |
| 63 | + protected getType() { |
| 64 | + return DebugType.EditorBrowser as const; |
| 65 | + } |
| 66 | + |
| 67 | + protected getTriggerKind() { |
| 68 | + return vscode.DebugConfigurationProviderTriggerKind.Initial; |
| 69 | + } |
| 70 | + |
| 71 | + protected provide(): ResolvingConfiguration<IEditorBrowserLaunchConfiguration> { |
| 72 | + return this.createLaunchConfigFromContext() || this.getDefaultLaunch(); |
| 73 | + } |
| 74 | + |
| 75 | + public createLaunchConfigFromContext(): |
| 76 | + | ResolvingConfiguration<IEditorBrowserLaunchConfiguration> |
| 77 | + | undefined |
| 78 | + { |
| 79 | + const editor = vscode.window.activeTextEditor; |
| 80 | + if (editor && editor.document.languageId === 'html') { |
| 81 | + return { |
| 82 | + type: this.getType(), |
| 83 | + request: 'launch', |
| 84 | + name: `Open ${basename(editor.document.uri.fsPath)}`, |
| 85 | + url: editor.document.uri.toString(), |
| 86 | + } as ResolvingConfiguration<IEditorBrowserLaunchConfiguration>; |
| 87 | + } |
| 88 | + |
| 89 | + return undefined; |
| 90 | + } |
| 91 | + |
| 92 | + private getDefaultLaunch(): ResolvingConfiguration<IEditorBrowserLaunchConfiguration> { |
| 93 | + return { |
| 94 | + type: this.getType(), |
| 95 | + request: 'launch', |
| 96 | + name: l10n.t('Launch Integrated Browser against localhost'), |
| 97 | + url: 'http://localhost:8080', |
| 98 | + webRoot: '${workspaceFolder}', |
| 99 | + } as ResolvingConfiguration<IEditorBrowserLaunchConfiguration>; |
| 100 | + } |
| 101 | +} |
0 commit comments