Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
/publish/
/luadoc/out/
/ovsx-token

luamake.exe
main.lua
/package/
/.vscode/
package*
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 6 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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,
}
4 changes: 2 additions & 2 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ export function activate(context: vscode.ExtensionContext) {
};
}

export function deactivate() {
languageserver.deactivate();
export function deactivate(context: vscode.ExtensionContext) {
languageserver.deactivate(context);
}
114 changes: 90 additions & 24 deletions client/src/languageserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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<string, number>, locations: any[]) => {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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<string, any> {
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<string, any>) {
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
Expand All @@ -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();
Expand All @@ -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,
}

Expand All @@ -497,10 +563,10 @@ export async function setConfig(changes: ConfigChange[]): Promise<boolean> {
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,
});
}
Expand Down
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
Expand Down
1 change: 1 addition & 0 deletions package.nls.es-419.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions package.nls.ja-jp.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions package.nls.pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions package.nls.zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 21 additions & 0 deletions setting/schema-es-419.json
Original file line number Diff line number Diff line change
Expand Up @@ -3003,6 +3003,9 @@
},
"parameters": {
"$ref": "#/properties/misc.parameters"
},
"startQueue": {
"$ref": "#/properties/misc.startQueue"
}
}
},
Expand All @@ -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": {
Expand Down
21 changes: 21 additions & 0 deletions setting/schema-ja-jp.json
Original file line number Diff line number Diff line change
Expand Up @@ -3003,6 +3003,9 @@
},
"parameters": {
"$ref": "#/properties/misc.parameters"
},
"startQueue": {
"$ref": "#/properties/misc.startQueue"
}
}
},
Expand All @@ -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": {
Expand Down
21 changes: 21 additions & 0 deletions setting/schema-pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -3003,6 +3003,9 @@
},
"parameters": {
"$ref": "#/properties/misc.parameters"
},
"startQueue": {
"$ref": "#/properties/misc.startQueue"
}
}
},
Expand All @@ -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": {
Expand Down
Loading
Loading