1+ import * as vscode from "vscode" ;
2+ import * as path from "path" ;
3+ import { extensionContext } from "../extension" ;
4+ import { EmmyNewDebuggerProvider } from "./new_debugger/EmmyNewDebuggerProvider" ;
5+ import { EmmyAttachDebuggerProvider } from "./attach/EmmyAttachDebuggerProvider" ;
6+ import { EmmyLaunchDebuggerProvider } from "./launch/EmmyLaunchDebuggerProvider" ;
7+ import { InlineDebugAdapterFactory } from "./DebugFactory" ;
8+
9+
10+ /**
11+ * Debugger configuration interface
12+ */
13+ interface DebuggerConfig {
14+ readonly type : string ;
15+ readonly provider : vscode . DebugConfigurationProvider ;
16+ }
17+
18+
19+ export async function insertEmmyDebugCode ( ) {
20+ const context = extensionContext . vscodeContext ;
21+ const activeEditor = vscode . window . activeTextEditor ;
22+ if ( ! activeEditor ) {
23+ return ;
24+ }
25+ const document = activeEditor . document ;
26+ if ( document . languageId !== "lua" ) {
27+ return ;
28+ }
29+
30+ let dllPath = "" ;
31+ const isWindows = process . platform === "win32" ;
32+ const isMac = process . platform === "darwin" ;
33+ const isLinux = process . platform === "linux" ;
34+ if ( isWindows ) {
35+ const arch = await vscode . window . showQuickPick ( [ "x64" , "x86" ] ) ;
36+ if ( ! arch ) {
37+ return ;
38+ }
39+ dllPath = path . join (
40+ context . extensionPath ,
41+ `debugger/emmy/windows/${ arch } /?.dll`
42+ ) ;
43+ } else if ( isMac ) {
44+ const arch = await vscode . window . showQuickPick ( [ "x64" , "arm64" ] ) ;
45+ if ( ! arch ) {
46+ return ;
47+ }
48+ dllPath = path . join (
49+ context . extensionPath ,
50+ `debugger/emmy/mac/${ arch } /emmy_core.dylib`
51+ ) ;
52+ } else if ( isLinux ) {
53+ dllPath = path . join (
54+ context . extensionPath ,
55+ `debugger/emmy/linux/emmy_core.so`
56+ ) ;
57+ }
58+
59+ const host = "localhost" ;
60+ const port = 9966 ;
61+ const ins = new vscode . SnippetString ( ) ;
62+ ins . appendText (
63+ `package.cpath = package.cpath .. ";${ dllPath . replace ( / \\ / g, "/" ) } "\n`
64+ ) ;
65+ ins . appendText ( `local dbg = require("emmy_core")\n` ) ;
66+ ins . appendText ( `dbg.tcpListen("${ host } ", ${ port } )` ) ;
67+ activeEditor . insertSnippet ( ins ) ;
68+ }
69+
70+ export function registerDebuggers ( ) : void {
71+ const context = extensionContext . vscodeContext ;
72+
73+ const debuggerConfigs : DebuggerConfig [ ] = [
74+ { type : 'emmylua_new' , provider : new EmmyNewDebuggerProvider ( 'emmylua_new' , context ) } ,
75+ { type : 'emmylua_attach' , provider : new EmmyAttachDebuggerProvider ( 'emmylua_attach' , context ) } ,
76+ { type : 'emmylua_launch' , provider : new EmmyLaunchDebuggerProvider ( 'emmylua_launch' , context ) } ,
77+ ] ;
78+
79+ debuggerConfigs . forEach ( ( { type, provider } ) => {
80+ context . subscriptions . push (
81+ vscode . debug . registerDebugConfigurationProvider ( type , provider )
82+ ) ;
83+
84+ context . subscriptions . push ( provider as vscode . Disposable ) ;
85+ } ) ;
86+
87+ if ( extensionContext . debugMode ) {
88+ const factory = new InlineDebugAdapterFactory ( ) ;
89+ debuggerConfigs . forEach ( ( { type } ) => {
90+ context . subscriptions . push (
91+ vscode . debug . registerDebugAdapterDescriptorFactory ( type , factory )
92+ ) ;
93+ } ) ;
94+ }
95+ }
0 commit comments