33 * Licensed under the MIT License. See LICENSE in the package root for license information.
44 * ------------------------------------------------------------------------------------------ */
55
6- import * as vscode from 'vscode' ;
6+ import { RegisteredMemoryFile } from '@codingame/monaco-vscode-files-service-override' ;
7+ import type { Logger } from 'monaco-languageclient/common' ;
78import type { ExtensionConfig } from 'monaco-languageclient/vscodeApiWrapper' ;
8- import type { ConfigParams , InitMessage } from '../common/definitions.js' ;
9+ import * as vscode from 'vscode' ;
10+ import { Uri } from 'vscode' ;
911
1012// This is derived from:
1113// https://github.com/CodinGame/monaco-vscode-api/blob/main/demo/src/features/debugger.ts
1214// The client configuration is generic and can be used for a another language
1315
16+ export type FileDefinition = {
17+ path : string ;
18+ code : string ;
19+ uri : Uri ;
20+ }
21+
22+ export type InitMessage = {
23+ id : 'init' ,
24+ files : Record < string , FileDefinition >
25+ defaultFile : string ;
26+ debuggerExecCall : string ;
27+ } ;
28+
29+ export type ConfigParams = {
30+ extensionName : string ;
31+ version : string ;
32+ publisher : string ;
33+ languageId : string ;
34+ documentSelector : string [ ] ;
35+ homeDir : string ;
36+ workspaceRoot : string ;
37+ workspaceFile : Uri ;
38+ htmlContainer : HTMLElement ;
39+ protocol : 'ws' | 'wss' ;
40+ hostname : string ;
41+ port : number ;
42+ files : Map < string , FileDefinition > ;
43+ defaultFile : string ;
44+ helpContainerCmd : string ;
45+ debuggerExecCall : string ;
46+ }
47+
1448export const provideDebuggerExtensionConfig = ( config : ConfigParams ) : ExtensionConfig => {
1549 const filesOrContents = new Map < string , string | URL > ( ) ;
1650 filesOrContents . set ( './extension.js' , '// nothing' ) ;
1751
1852 return {
1953 config : {
2054 name : config . extensionName ,
21- publisher : 'TypeFox' ,
22- version : '1.0.0' ,
55+ publisher : config . publisher ,
56+ version : config . version ,
2357 engines : {
2458 vscode : '*'
2559 } ,
@@ -47,7 +81,7 @@ export const provideDebuggerExtensionConfig = (config: ConfigParams): ExtensionC
4781 } ;
4882} ;
4983
50- export const configureDebugging = async ( api : typeof vscode , config : ConfigParams ) => {
84+ export const configureDebugging = async ( api : typeof vscode , config : ConfigParams , logger ?: Logger ) => {
5185 class WebsocketDebugAdapter implements vscode . DebugAdapter {
5286 private websocket : WebSocket ;
5387
@@ -93,7 +127,7 @@ export const configureDebugging = async (api: typeof vscode, config: ConfigParam
93127 debuggerExecCall : config . debuggerExecCall
94128 } ;
95129 for ( const [ name , fileDef ] of config . files . entries ( ) ) {
96- console . log ( `Found: ${ name } Sending file: ${ fileDef . path } ` ) ;
130+ logger ?. info ( `Found: ${ name } Sending file: ${ fileDef . path } ` ) ;
97131 initMessage . files [ name ] = {
98132 path : fileDef . path ,
99133 code : fileDef . code ,
@@ -105,10 +139,30 @@ export const configureDebugging = async (api: typeof vscode, config: ConfigParam
105139 // eslint-disable-next-line @typescript-eslint/no-explicit-any
106140 adapter . onDidSendMessage ( ( message : any ) => {
107141 if ( message . type === 'event' && message . event === 'output' ) {
108- console . log ( 'OUTPUT' , message . body . output ) ;
142+ logger ?. info ( 'OUTPUT' , message . body . output ) ;
109143 }
110144 } ) ;
111145 return new api . DebugAdapterInlineImplementation ( adapter ) ;
112146 }
113147 } ) ;
114148} ;
149+
150+ export const createDebugLaunchConfigFile = ( workspacePath : string , type : string ) => {
151+ return new RegisteredMemoryFile (
152+ Uri . file ( `${ workspacePath } /.vscode/launch.json` ) ,
153+ JSON . stringify (
154+ {
155+ version : '0.2.0' ,
156+ configurations : [
157+ {
158+ name : 'Debugger: Lauch' ,
159+ type,
160+ request : 'attach' ,
161+ }
162+ ]
163+ } ,
164+ null ,
165+ 2
166+ )
167+ ) ;
168+ } ;
0 commit comments