diff --git a/.gitignore b/.gitignore index 2131474c..2f0cf7f3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,9 @@ /publish/ /luadoc/out/ /ovsx-token + +luamake.exe +main.lua +/package/ +/.vscode/ +package* \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index d2384881..9b74762c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "server"] path = server - url = https://github.com/LuaLS/lua-language-server + url = https://github.com/SuperMan20231030/lua-language-server.git [submodule "client/3rd/vscode-lua-doc"] path = client/3rd/vscode-lua-doc url = https://github.com/LuaLS/vscode-lua-doc diff --git a/.vscode/settings.json b/.vscode/settings.json index d58da988..c0dba773 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,8 @@ { + "editor.tabSize": 4, "Lua.runtime.version": "Lua 5.4", - "Lua.workspace.library": { - "server/script-beta": true - }, - "Lua.workspace.checkThirdParty": false -} + "Lua.workspace.library": [ + "server/script/meta" + ], + "Lua.workspace.checkThirdParty": false, +} \ No newline at end of file diff --git a/client/src/extension.ts b/client/src/extension.ts index e4bea0db..8e9f2773 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -31,6 +31,6 @@ export function activate(context: vscode.ExtensionContext) { }; } -export function deactivate() { - languageserver.deactivate(); +export function deactivate(context: vscode.ExtensionContext) { + languageserver.deactivate(context); } diff --git a/client/src/languageserver.ts b/client/src/languageserver.ts index 11deafbe..2f708031 100644 --- a/client/src/languageserver.ts +++ b/client/src/languageserver.ts @@ -24,6 +24,7 @@ import { export let defaultClient: LuaClient | null; let outputChannel: vscode.OutputChannel | undefined; +let outputTimer: NodeJS.Timeout | null; function registerCustomCommands(context: ExtensionContext) { context.subscriptions.push(Commands.registerCommand('lua.config', (changes) => { @@ -89,12 +90,12 @@ function registerCustomCommands(context: ExtensionContext) { })) context.subscriptions.push(Commands.registerCommand('lua.startServer', async () => { - deactivate(); + deactivate(context); createClient(context); })); context.subscriptions.push(Commands.registerCommand('lua.stopServer', async () => { - deactivate(); + deactivate(context); })); context.subscriptions.push(Commands.registerCommand('lua.showReferences', (uri: string, position: Record, locations: any[]) => { @@ -185,9 +186,9 @@ class LuaClient extends Disposable { command: command, transport: port ? { - kind: TransportKind.socket, - port: port, - } + kind: TransportKind.socket, + port: port, + } : undefined, args: commandParam, options: { @@ -428,7 +429,46 @@ class LuaClient extends Disposable { } } -export function activate(context: ExtensionContext) { +const COUNT_KEY = 'languageserver.start'; +function getSharedFilePath(context: ExtensionContext) { + /* AppData\Roaming\Code\User\globalStorage\sumneko.lua\ -> windows目录 */ + let fsPath = context.globalStorageUri.fsPath + if (!fs.existsSync(fsPath)) { + // 确保目录存在 + fs.mkdirSync(fsPath, { recursive: true }); + } + return path.join(fsPath, 'shared-state'); +} +function loadLocalConfig(context: ExtensionContext): Record { + let filePath = getSharedFilePath(context); + + let localConfig + if (fs.existsSync(filePath)) { + localConfig = JSON.parse(fs.readFileSync(filePath, 'utf-8')); + } + return typeof localConfig === 'object' ? localConfig : {} +} +function saveLocalConfig(context: ExtensionContext, localConfig: Record) { + fs.writeFileSync(getSharedFilePath(context), JSON.stringify(localConfig), 'utf-8'); +} + +function countLuaStart(context: ExtensionContext, i: number): number { + let localConfig = loadLocalConfig(context) + // 获取当前值,默认为 0 + let currentCount: number = localConfig[COUNT_KEY]; + currentCount = typeof currentCount === 'number' ? currentCount : 0 + + if (currentCount < 0) { + currentCount = 0; + } + let newCount = currentCount + i; + localConfig[COUNT_KEY] = newCount; + //使用文件记录通信,Sync锁 + saveLocalConfig(context, localConfig) + + return newCount +}; +function _activate(context: ExtensionContext) { registerCustomCommands(context); function didOpenTextDocument(document: TextDocument) { // We are only interested in language mode text @@ -446,8 +486,34 @@ export function activate(context: ExtensionContext) { Workspace.onDidOpenTextDocument(didOpenTextDocument); Workspace.textDocuments.forEach(didOpenTextDocument); } +export function activate(context: ExtensionContext) { + + let startQueueTime: number | undefined = Workspace.getConfiguration(undefined, vscode.workspace.workspaceFolders?.[0]).get("Lua.misc.startQueue"); -export async function deactivate() { + startQueueTime = typeof startQueueTime === 'number' ? startQueueTime : 0 + + if (startQueueTime <= 0) { + _activate(context); + return; + } + /* 实测5秒可以同时 open 10个LSP,(5-1)*10=45秒完成加载 */ + startQueueTime = (startQueueTime <= 20 ? startQueueTime : 20) * 1000 + /* 同时打开N个工作区时,vscode启动LSP插件会出现`not enough memory`的错误 */ + outputTimer = setTimeout(async () => { + outputTimer = setTimeout(async () => { + countLuaStart(context, -1) + outputTimer = null + }, startQueueTime); + _activate(context) + }, (countLuaStart(context, 1) - 1) * startQueueTime); //使用计时器队列开启,单个窗口不受影响,第2个窗口开始wait +} + +export async function deactivate(context: ExtensionContext) { + if (outputTimer) { + clearTimeout(outputTimer) + countLuaStart(context, -1) + outputTimer = null + } if (defaultClient) { defaultClient.stop(); defaultClient.dispose(); @@ -469,23 +535,23 @@ export async function reportAPIDoc(params: unknown) { } export type ConfigChange = { - action: "set", - key: string, - value: LSPAny, - uri: vscode.Uri, + action: "set", + key: string, + value: LSPAny, + uri: vscode.Uri, global?: boolean, } | { - action: "add", - key: string, - value: LSPAny, - uri: vscode.Uri, + action: "add", + key: string, + value: LSPAny, + uri: vscode.Uri, global?: boolean, } | { - action: "prop", - key: string, - prop: string; - value: LSPAny, - uri: vscode.Uri, + action: "prop", + key: string, + prop: string; + value: LSPAny, + uri: vscode.Uri, global?: boolean, } @@ -497,10 +563,10 @@ export async function setConfig(changes: ConfigChange[]): Promise { for (const change of changes) { params.push({ action: change.action, - prop: (change.action === "prop") ? change.prop : undefined as never, - key: change.key, - value: change.value, - uri: change.uri.toString(), + prop: (change.action === "prop") ? change.prop : undefined as never, + key: change.key, + value: change.value, + uri: change.uri.toString(), global: change.global, }); } diff --git a/package.json b/package.json index f0c6a008..0925aad6 100644 --- a/package.json +++ b/package.json @@ -2862,6 +2862,24 @@ "scope": "resource", "type": "array" }, + "Lua.misc.startQueue": { + "default": 0, + "enum": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 10, + 15, + 20 + ], + "markdownDescription": "%config.misc.startQueue%", + "scope": "resource", + "type": "integer" + }, "Lua.nameStyle.config": { "additionalProperties": false, "default": {}, diff --git a/package.nls.es-419.json b/package.nls.es-419.json index 707c67f9..c6e8de88 100644 --- a/package.nls.es-419.json +++ b/package.nls.es-419.json @@ -257,6 +257,7 @@ "config.language.fixIndent": "(Solo en VSCode) Arregla la auto-indentación incorrecta, como aquella cuando los quiebres de línea ocurren dentro de un string que contengan la palabra \"function\".", "config.misc.executablePath": "Especifica la ruta del ejecutable en VSCode.", "config.misc.parameters": "[Parámetros de la línea de comando](https://github.com/LuaLS/lua-telemetry-server/tree/master/method) para iniciar el servidor de lenguage en VSCode.", + "config.misc.startQueue": "nothing to say", "config.nameStyle.config": "Configuración de estilo para nombres.\nRevise [la documentación del formateador](https://github.com/CppCXY/EmmyLuaCodeStyle/tree/master/docs)\npara aprender más sobre su uso.\n", "config.runtime.builtin": "Ajuste de la habilitación de biblioteca interna provista. Puede deshabilitar (o redefinir) las bibliotecas inexistentes de acuerdo al ambiente de ejecución.\n\n* `default`: Indica que la biblioteca será habilitada o deshabilitada de acuerdo a la versión que se ejecuta.\n* `enable`: Habilitada\n* `disable`: Deshabilitada\n", "config.runtime.builtin.basic": "TODO: Needs documentation", diff --git a/package.nls.ja-jp.json b/package.nls.ja-jp.json index 7e6f95a5..0b5ee4a6 100644 --- a/package.nls.ja-jp.json +++ b/package.nls.ja-jp.json @@ -257,6 +257,7 @@ "config.language.fixIndent": "(VSCodeのみ) 誤った自動インデントを修正します。例えば、\"function\" を含む文字列内で改行したときの不正なインデントなど。", "config.misc.executablePath": "VSCodeでの実行可能ファイルのパスを指定します。", "config.misc.parameters": "VSCode で言語サーバーを起動するときの[コマンドライン引数](https://github.com/LuaLS/lua-telemetry-server/tree/master/method)。", + "config.misc.startQueue": "nothing to say", "config.nameStyle.config": "命名スタイル設定。\n[formatter docs](https://github.com/CppCXY/EmmyLuaCodeStyle/tree/master/docs) を参照してください。\n", "config.runtime.builtin": "組み込みライブラリの有効状態を調整します。実際のランタイム環境に応じて、存在しないライブラリを無効化(または再定義)できます。\n\n* `default`: ランタイムバージョンに応じてライブラリを有効/無効にします\n* `enable`: 常に有効\n* `disable`: 常に無効\n", "config.runtime.builtin.basic": "TODO: Needs documentation", diff --git a/package.nls.json b/package.nls.json index f5b331fb..871e7378 100644 --- a/package.nls.json +++ b/package.nls.json @@ -257,6 +257,7 @@ "config.language.fixIndent": "(VSCode only) Fix incorrect auto-indentation, such as incorrect indentation when line breaks occur within a string containing the word \"function\".", "config.misc.executablePath": "Specify the executable path in VSCode.", "config.misc.parameters": "[Command line parameters](https://github.com/LuaLS/lua-telemetry-server/tree/master/method) when starting the language server in VSCode.", + "config.misc.startQueue": "nothing to say", "config.nameStyle.config": "Set name style config.\nRead [formatter docs](https://github.com/CppCXY/EmmyLuaCodeStyle/tree/master/docs) to learn usage.\n", "config.runtime.builtin": "Adjust the enabled state of the built-in library. You can disable (or redefine) the non-existent library according to the actual runtime environment.\n\n* `default`: Indicates that the library will be enabled or disabled according to the runtime version\n* `enable`: always enable\n* `disable`: always disable\n", "config.runtime.builtin.basic": "TODO: Needs documentation", diff --git a/package.nls.pt-br.json b/package.nls.pt-br.json index 0ff588aa..c7e3dc84 100644 --- a/package.nls.pt-br.json +++ b/package.nls.pt-br.json @@ -257,6 +257,7 @@ "config.language.fixIndent": "(Somente VSCode) Corrige indentação automática incorreta, como quebras de linha dentro de uma string contendo a palavra \"function\".", "config.misc.executablePath": "Especifica o caminho do executável no VSCode.", "config.misc.parameters": "[Parâmetros de linha de comando](https://github.com/LuaLS/lua-telemetry-server/tree/master/method) ao iniciar o serviço de linguagem no VSCode.", + "config.misc.startQueue": "nothing to say", "config.nameStyle.config": "Configurações de estilo de nomes.\nConsulte a [documentação do formatador](https://github.com/CppCXY/EmmyLuaCodeStyle/tree/master/docs) para uso.\n", "config.runtime.builtin": "Ajusta o estado de habilitação das bibliotecas internas. Você pode desabilitar (ou redefinir) bibliotecas inexistentes conforme o ambiente de execução real.\n\n* `default`: a biblioteca será habilitada ou desabilitada conforme a versão do runtime\n* `enable`: sempre habilitar\n* `disable`: sempre desabilitar\n", "config.runtime.builtin.basic": "TODO: Needs documentation", diff --git a/package.nls.zh-cn.json b/package.nls.zh-cn.json index 611f0645..76f8a39c 100644 --- a/package.nls.zh-cn.json +++ b/package.nls.zh-cn.json @@ -257,6 +257,7 @@ "config.language.fixIndent": "(仅VSCode) 修复错误的自动缩进,例如在包含单词 \"function\" 的字符串中换行时出现的错误缩进。", "config.misc.executablePath": "VSCode中指定可执行文件路径。", "config.misc.parameters": "VSCode中启动语言服务时的[命令行参数](https://luals.github.io/wiki/usage#arguments)。", + "config.misc.startQueue": "VSCode中多个窗口同时启动LSP时的间隔(秒),单个窗口不受影响。", "config.nameStyle.config": "设定命名风格检查的配置。\n请查阅[格式化文档](https://github.com/CppCXY/EmmyLuaCodeStyle/tree/master/docs)了解用法。\n", "config.runtime.builtin": "调整内置库的启用状态,你可以根据实际运行环境禁用掉不存在的库(或重新定义)。\n\n* `default`: 表示库会根据运行版本启用或禁用\n* `enable`: 总是启用\n* `disable`: 总是禁用\n", "config.runtime.builtin.basic": "TODO: Needs documentation", diff --git a/package.nls.zh-tw.json b/package.nls.zh-tw.json index a23bfa53..2644fdb6 100644 --- a/package.nls.zh-tw.json +++ b/package.nls.zh-tw.json @@ -257,6 +257,7 @@ "config.language.fixIndent": "(僅限VSCode)修復自動縮排錯誤,例如在有包含 \"function\" 的字串中換行時出現的錯誤縮排。", "config.misc.executablePath": "指定VSCode內的可執行文件", "config.misc.parameters": "VSCode內啟動語言伺服時的[命令列參數](https://luals.github.io/wiki/usage#arguments)。", + "config.misc.startQueue": "nothing to say", "config.nameStyle.config": "設定檢查命名風格的組態。\n閱讀 [formatter docs](https://github.com/CppCXY/EmmyLuaCodeStyle/tree/master/docs) 了解用法。\n", "config.runtime.builtin": "調整內建庫的啟用狀態,你可以根據實際執行環境停用(或重新定義)不存在的庫。\n\n* `default`: 表示庫會根據執行版本啟用或停用\n* `enable`: 總是啟用\n* `disable`: 總是停用\n", "config.runtime.builtin.basic": "TODO: Needs documentation", diff --git a/server b/server index b144c872..d109b314 160000 --- a/server +++ b/server @@ -1 +1 @@ -Subproject commit b144c872f081373a893b55979142fed651e4425a +Subproject commit d109b31440c39290222d7a74c8bd66a7791e6e4b diff --git a/setting/schema-es-419.json b/setting/schema-es-419.json index e8d09cc1..d0d0553c 100644 --- a/setting/schema-es-419.json +++ b/setting/schema-es-419.json @@ -3003,6 +3003,9 @@ }, "parameters": { "$ref": "#/properties/misc.parameters" + }, + "startQueue": { + "$ref": "#/properties/misc.startQueue" } } }, @@ -3021,6 +3024,24 @@ "scope": "resource", "type": "array" }, + "misc.startQueue": { + "default": 0, + "enum": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 10, + 15, + 20 + ], + "markdownDescription": "nothing to say", + "scope": "resource", + "type": "integer" + }, "nameStyle": { "properties": { "config": { diff --git a/setting/schema-ja-jp.json b/setting/schema-ja-jp.json index 05f1fe45..49fc1eb1 100644 --- a/setting/schema-ja-jp.json +++ b/setting/schema-ja-jp.json @@ -3003,6 +3003,9 @@ }, "parameters": { "$ref": "#/properties/misc.parameters" + }, + "startQueue": { + "$ref": "#/properties/misc.startQueue" } } }, @@ -3021,6 +3024,24 @@ "scope": "resource", "type": "array" }, + "misc.startQueue": { + "default": 0, + "enum": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 10, + 15, + 20 + ], + "markdownDescription": "nothing to say", + "scope": "resource", + "type": "integer" + }, "nameStyle": { "properties": { "config": { diff --git a/setting/schema-pt-br.json b/setting/schema-pt-br.json index 84e989a9..9c251e9f 100644 --- a/setting/schema-pt-br.json +++ b/setting/schema-pt-br.json @@ -3003,6 +3003,9 @@ }, "parameters": { "$ref": "#/properties/misc.parameters" + }, + "startQueue": { + "$ref": "#/properties/misc.startQueue" } } }, @@ -3021,6 +3024,24 @@ "scope": "resource", "type": "array" }, + "misc.startQueue": { + "default": 0, + "enum": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 10, + 15, + 20 + ], + "markdownDescription": "nothing to say", + "scope": "resource", + "type": "integer" + }, "nameStyle": { "properties": { "config": { diff --git a/setting/schema-zh-cn.json b/setting/schema-zh-cn.json index 9c8a4e0c..61fd3489 100644 --- a/setting/schema-zh-cn.json +++ b/setting/schema-zh-cn.json @@ -3003,6 +3003,9 @@ }, "parameters": { "$ref": "#/properties/misc.parameters" + }, + "startQueue": { + "$ref": "#/properties/misc.startQueue" } } }, @@ -3021,6 +3024,24 @@ "scope": "resource", "type": "array" }, + "misc.startQueue": { + "default": 0, + "enum": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 10, + 15, + 20 + ], + "markdownDescription": "VSCode中多个窗口同时启动LSP时的间隔(秒),单个窗口不受影响。", + "scope": "resource", + "type": "integer" + }, "nameStyle": { "properties": { "config": { diff --git a/setting/schema-zh-tw.json b/setting/schema-zh-tw.json index f7a06b9a..63f19919 100644 --- a/setting/schema-zh-tw.json +++ b/setting/schema-zh-tw.json @@ -3003,6 +3003,9 @@ }, "parameters": { "$ref": "#/properties/misc.parameters" + }, + "startQueue": { + "$ref": "#/properties/misc.startQueue" } } }, @@ -3021,6 +3024,24 @@ "scope": "resource", "type": "array" }, + "misc.startQueue": { + "default": 0, + "enum": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 10, + 15, + 20 + ], + "markdownDescription": "nothing to say", + "scope": "resource", + "type": "integer" + }, "nameStyle": { "properties": { "config": { diff --git a/setting/schema.json b/setting/schema.json index 601c2bde..e7af6550 100644 --- a/setting/schema.json +++ b/setting/schema.json @@ -3003,6 +3003,9 @@ }, "parameters": { "$ref": "#/properties/misc.parameters" + }, + "startQueue": { + "$ref": "#/properties/misc.startQueue" } } }, @@ -3021,6 +3024,24 @@ "scope": "resource", "type": "array" }, + "misc.startQueue": { + "default": 0, + "enum": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 10, + 15, + 20 + ], + "markdownDescription": "nothing to say", + "scope": "resource", + "type": "integer" + }, "nameStyle": { "properties": { "config": {