-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathluapandaDebug.ts
More file actions
207 lines (170 loc) · 6.92 KB
/
luapandaDebug.ts
File metadata and controls
207 lines (170 loc) · 6.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import * as vscode from 'vscode';
import * as Net from 'net';
import { Tools } from './common/tools';
import { DebugLogger } from './common/logManager';
import { LuaDebugSession } from './debug/luaDebug';
import {LuaPath} from './common/luaPath';
// debug启动时的配置项处理
export class LuaConfigurationProvider implements vscode.DebugConfigurationProvider {
private _server?: Net.Server;
private static RunFileTerminal;
resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration, token?: vscode.CancellationToken): vscode.ProviderResult<vscode.DebugConfiguration> {
// if launch.json is missing or empty
if (!config.type && !config.name) {
const editor = vscode.window.activeTextEditor;
if (editor && editor.document.languageId === 'lua') {
vscode.window.showInformationMessage('请先正确配置launch文件!');
config.type = 'LuaHelper-Debug';
config.name = 'LuaHelper';
config.request = 'launch';
}
}
// 不调试而直接运行当前文件
if (config.noDebug) {
// 获取活跃窗口
let retObject = Tools.getVSCodeAvtiveFilePath();
if (retObject["retCode"] !== 0) {
DebugLogger.DebuggerInfo(retObject["retMsg"]);
return;
}
let filePath = retObject["filePath"];
if (LuaConfigurationProvider.RunFileTerminal) {
LuaConfigurationProvider.RunFileTerminal.dispose();
}
LuaConfigurationProvider.RunFileTerminal = vscode.window.createTerminal({
name: "Run Lua File (LuaHelper)",
env: {},
});
// 把路径加入package.path
let path = require("path");
let pathCMD = "'";
let pathArr = Tools.VSCodeExtensionPath.split(path.sep);
let stdPath = pathArr.join('/');
pathCMD = pathCMD + stdPath + "/debugger/?.lua;";
pathCMD = pathCMD + config.packagePath.join(';');
pathCMD = pathCMD + "'";
let luaPath:LuaPath = new LuaPath();
let luaPathStr:string = "";
if (config.luaPath && config.luaPath !== '') {
luaPathStr = config.luaPath;
}
let strVect:string[] = luaPath.GetLuaExeCpathStr(luaPathStr, Tools.VSCodeExtensionPath);
// 路径socket的路径加入到package.cpath中
let cpathCMD = "'";
//cpathCMD = cpathCMD + stdPath + GetLuasocketPath();
cpathCMD = cpathCMD + config.packagePath.join(';');
cpathCMD = cpathCMD + strVect[1] + ";";
cpathCMD = cpathCMD + "'";
cpathCMD = " package.cpath = " + cpathCMD + ".. package.cpath; ";
//拼接命令
pathCMD = " \"package.path = " + pathCMD + ".. package.path; ";
let doFileCMD = filePath;
let runCMD = pathCMD + cpathCMD + "\" " + doFileCMD;
let LuaCMD = strVect[0] + " -e ";
LuaConfigurationProvider.RunFileTerminal.show();
//兼容terminal启动耗时较长的情况,延迟发送命令
setTimeout(() => LuaConfigurationProvider.RunFileTerminal.sendText(LuaCMD + runCMD, true), 2000);
return;
}
// 关于打开调试控制台的自动设置
if (config.name === "LuaHelper-DebugFile") {
if (!config.internalConsoleOptions) {
config.internalConsoleOptions = "neverOpen";
}
} else {
if (!config.internalConsoleOptions) {
config.internalConsoleOptions = "openOnSessionStart";
}
}
// rootFolder 固定为 ${workspaceFolder}, 用来查找本项目的launch.json.
config.rootFolder = '${workspaceFolder}';
if (!config.TempFilePath) {
config.TempFilePath = '${workspaceFolder}';
}
// 开发模式设置
if( config.DevelopmentMode !== true ){
config.DevelopmentMode = false;
}
if(!config.program){
config.program = '';
}
if(config.packagePath == undefined){
config.packagePath = [];
}
if(config.truncatedOPath == undefined){
config.truncatedOPath = "";
}
if(config.distinguishSameNameFile == undefined){
config.distinguishSameNameFile = false;
}
if(config.dbCheckBreakpoint == undefined){
config.dbCheckBreakpoint = false;
}
if(!config.args){
config.args = new Array<string>();
}
if(config.autoPathMode == undefined){
// 默认使用自动路径模式
config.autoPathMode = true;
}
if (!config.cwd) {
config.cwd = '${workspaceFolder}';
}
if (!config.luaFileExtension) {
config.luaFileExtension = '';
}else{
// luaFileExtension 兼容 ".lua" or "lua"
let firseLetter = config.luaFileExtension.substr(0, 1);
if(firseLetter === '.'){
config.luaFileExtension = config.luaFileExtension.substr(1);
}
}
config.VSCodeExtensionPath = Tools.VSCodeExtensionPath;
if (config.stopOnEntry == undefined) {
config.stopOnEntry = true;
}
if (config.pathCaseSensitivity == undefined) {
config.pathCaseSensitivity = false;
}
if (config.connectionPort == undefined) {
config.connectionPort = 8818;
}
if (config.logLevel == undefined) {
config.logLevel = 1;
}
if (config.autoReconnect != true) {
config.autoReconnect = false;
}
if (config.updateTips == undefined) {
config.updateTips = true;
}
if (config.useCHook == undefined) {
config.useCHook = true;
}
if (config.isNeedB64EncodeStr == undefined) {
config.isNeedB64EncodeStr = true;
}
if (config.VSCodeAsClient == undefined) {
config.VSCodeAsClient = false;
}
if (config.connectionIP == undefined) {
config.connectionIP = "127.0.0.1";
}
if (!this._server) {
this._server = Net.createServer(socket => {
const session = new LuaDebugSession();
session.setRunAsServer(true);
session.start(<NodeJS.ReadableStream>socket, socket);
}).listen(0);
}
// make VS Code connect to debug server instead of launching debug adapter
let addressInfo = this._server.address() as Net.AddressInfo;
config.debugServer = addressInfo.port;
return config;
}
dispose() {
if (this._server) {
this._server.close();
}
}
}