Skip to content

Commit 1039cb0

Browse files
authored
Merge pull request #204 from xuhuanzy/dev
添加"自定义运行路径"配置与整理选项
2 parents e0a7d2e + 1ad3525 commit 1039cb0

File tree

5 files changed

+32
-14
lines changed

5 files changed

+32
-14
lines changed

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,19 @@
276276
"type": "string",
277277
"default": ""
278278
},
279-
"emmylua.ls.start_parameters": {
279+
"emmylua.ls.startParameters": {
280280
"type": "array",
281281
"default": []
282282
},
283-
"emmylua.autoInsertTripleDash": {
283+
"emmylua.misc.autoInsertTripleDash": {
284284
"type": "boolean",
285285
"default": true,
286286
"description": "%config.autoInsertTripleDash.description%"
287+
},
288+
"emmylua.misc.executablePath": {
289+
"type": "string",
290+
"default": "",
291+
"description": "%config.misc.executablePath%"
287292
}
288293
}
289294
},

package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
"debug.launch.arguments": "arguments pass to executable file",
1515
"debug.launch.blockOnExit": "block process when exit",
1616
"debug.launch.newWindow": "create new windows",
17-
"config.autoInsertTripleDash.description": "Automatically insert \"---\" when line breaking after a comment"
17+
"config.autoInsertTripleDash.description": "Automatically insert \"---\" when line breaking after a comment",
18+
"config.misc.executablePath": "Specify the executable file path in VSCode"
1819
}

package.nls.zh-cn.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
"debug.launch.arguments": "传递给可执行文件的参数",
1515
"debug.launch.blockOnExit": "进程结束时是否阻塞进程保持窗口开启",
1616
"debug.launch.newWindow": "emmylua会创建一个新窗口展示这个进程",
17-
"config.autoInsertTripleDash.description": "在注解后换行时自动插入 \"---\""
17+
"config.autoInsertTripleDash.description": "在注解后换行时自动插入 \"---\"",
18+
"config.misc.executablePath": "VSCode中指定可执行文件路径"
1819
}

src/extension.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,27 @@ async function doStartServer() {
131131
return Promise.resolve(result);
132132
};
133133
} else {
134-
let platform = os.platform();
135-
let executableName = platform === 'win32' ? 'emmylua_ls.exe' : 'emmylua_ls';
136-
const exe = path.join(context.extensionPath, 'server', executableName);
137-
138-
if (platform !== 'win32') {
139-
fs.chmodSync(exe, '777');
134+
const config = vscode.workspace.getConfiguration(
135+
undefined,
136+
vscode.workspace.workspaceFolders?.[0]
137+
);
138+
let configExecutablePath = config.get<string>("emmylua.misc.executablePath")?.trim();
139+
if (!configExecutablePath || configExecutablePath.length == 0) {
140+
let platform = os.platform();
141+
let executableName = platform === 'win32' ? 'emmylua_ls.exe' : 'emmylua_ls';
142+
configExecutablePath = path.join(context.extensionPath, 'server', executableName);
143+
144+
if (platform !== 'win32') {
145+
fs.chmodSync(configExecutablePath, '777');
146+
}
140147
}
148+
141149
serverOptions = {
142-
command: exe,
150+
command: configExecutablePath,
143151
args: []
144152
};
145153

146-
let parameters = vscode.workspace.getConfiguration("emmylua").get<string[]>("ls.start_parameters");
154+
let parameters = config.get<string[]>("emmylua.ls.startParameters");
147155
if (parameters && parameters.length > 0) {
148156
serverOptions.args = parameters;
149157
}

src/languageConfiguration.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ export class LuaLanguageConfiguration implements LanguageConfiguration {
3232
];
3333

3434
// 读取配置决定是否添加三横线规则
35-
const config = workspace.getConfiguration('emmylua');
36-
const autoInsertTripleDash = config.get<boolean>('autoInsertTripleDash', true);
35+
const config = workspace.getConfiguration(
36+
undefined,
37+
workspace.workspaceFolders?.[0]
38+
);
39+
const autoInsertTripleDash = config.get<boolean>('emmylua.misc.autoInsertTripleDash', true);
3740
// 第二个参数是默认值(当配置不存在时使用)
3841
if (autoInsertTripleDash) {
3942
this.onEnterRules = [

0 commit comments

Comments
 (0)