From dc92d4ace36c38f9b324271841f06e0be34e0035 Mon Sep 17 00:00:00 2001 From: Dawei Huang Date: Thu, 2 Feb 2023 19:30:19 +0800 Subject: [PATCH 1/5] Lua integration --- .github/workflows/build-test.yaml | 2 ++ .github/workflows/markets-publish.yml | 2 ++ .gitmodules | 3 ++ EmmyLua | 1 + package.json | 3 ++ src/extension-node.ts | 47 ++++++++++++++++++++++++++- 6 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 .gitmodules create mode 160000 EmmyLua diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index dbb73f2..a951dba 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -31,6 +31,8 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 + with: + submodules: true - name: Install Node.js uses: actions/setup-node@v3 diff --git a/.github/workflows/markets-publish.yml b/.github/workflows/markets-publish.yml index 8aebe97..d837c9b 100644 --- a/.github/workflows/markets-publish.yml +++ b/.github/workflows/markets-publish.yml @@ -23,6 +23,8 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 + with: + submodules: true - name: Install Node.js uses: actions/setup-node@v3 diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..988a86b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "EmmyLua"] + path = EmmyLua + url = https://github.com/davidxuang/EmmyMediawiki.git diff --git a/EmmyLua b/EmmyLua new file mode 160000 index 0000000..bb893db --- /dev/null +++ b/EmmyLua @@ -0,0 +1 @@ +Subproject commit bb893db61c816d68256b2f83c6e0622ee3323d3c diff --git a/package.json b/package.json index 89f9354..a40653c 100644 --- a/package.json +++ b/package.json @@ -271,6 +271,9 @@ "convert": "js-yaml snippets/snippets.yaml > snippets/snippets.json && js-yaml syntaxes/wikitext.tmLanguage.yaml > syntaxes/wikitext.tmLanguage.json && js-yaml language-configuration.yaml > language-configuration.json", "package": "vsce package --yarn" }, + "extensionDependencies": [ + "sumneko.lua" + ], "devDependencies": { "@types/cheerio": "^0.22.28", "@types/glob": "^7.2.0", diff --git a/src/extension-node.ts b/src/extension-node.ts index 2d6e71b..721d0af 100644 --- a/src/extension-node.ts +++ b/src/extension-node.ts @@ -4,6 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as vscode from 'vscode'; +import path from 'path'; import { getPageViewFactory, getPreviewFactory } from './export_command/wikimedia_function/view'; import { loginFactory, logoutFactory } from './export_command/wikimedia_function/bot'; import { closeEditorFactory, postPageFactory, pullPageFactory } from './export_command/wikimedia_function/page'; @@ -30,8 +31,52 @@ export function activate(context: vscode.ExtensionContext): void { commandRegistrar.register('viewPage', getPageViewFactory); // Cite commandRegistrar.register('citeWeb', addWebCiteFactory); + + configureLuaLibrary("Scribunto", true); } export function deactivate(): void { - console.log("Extension is deactivate."); + console.log("Extension is inactive."); + configureLuaLibrary("Scribunto", false); +} + +export function configureLuaLibrary(folder: string, enable: boolean) { + const extensionId = "rowewilsonfrederiskholme.wikitext"; + const extensionPath = vscode.extensions.getExtension(extensionId)?.extensionPath; + if (extensionPath === undefined) { + return; + } + + // Use path.join to ensure the proper path seperators are used. + const folderPath = path.join(extensionPath, "EmmyLua", folder); + const config = vscode.workspace.getConfiguration("Lua"); + const library: string[] | undefined = config.get("workspace.library"); + if (library === undefined) { + return; + } + + if (library && extensionPath) { + // remove any older versions of our path + for (let i = library.length-1; i >= 0; i--) { + const item = library[i]; + const isSelfExtension = item.indexOf(extensionId) > -1; + const isCurrentVersion = item.indexOf(extensionPath) > -1; + if (isSelfExtension && !isCurrentVersion) { + library.splice(i, 1); + } + } + + const index = library.indexOf(folderPath); + if (enable) { + if (index === -1) { + library.push(folderPath); + } + } + else { + if (index > -1) { + library.splice(index, 1); + } + } + config.update("workspace.library", library, true); + } } From 91c59ac967e2409f8a6f792672e82eaeb138ed7a Mon Sep 17 00:00:00 2001 From: Dawei Huang Date: Mon, 6 Feb 2023 15:41:45 +0800 Subject: [PATCH 2/5] Use scoped configuration instead --- package.json | 9 +++++++++ src/extension-node.ts | 15 ++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index a40653c..5abf704 100644 --- a/package.json +++ b/package.json @@ -254,6 +254,15 @@ "type": "boolean", "default": false, "markdownDescription": "If `PageTitle` is filled in `PAGE_INFO`, skip entering the title when posting." + }, + "wikitext.scopedLuaIntegration": { + "type": "string", + "default": "auto", + "enum": [ + "enabled", + "auto", + "disabled" + ] } } } diff --git a/src/extension-node.ts b/src/extension-node.ts index 721d0af..f888ffb 100644 --- a/src/extension-node.ts +++ b/src/extension-node.ts @@ -32,12 +32,18 @@ export function activate(context: vscode.ExtensionContext): void { // Cite commandRegistrar.register('citeWeb', addWebCiteFactory); - configureLuaLibrary("Scribunto", true); + configureLuaLibrary( + "Scribunto", + vscode.workspace.getConfiguration("wikitext").get("scopedLuaIntegration") !== "disabled" + ); } export function deactivate(): void { console.log("Extension is inactive."); - configureLuaLibrary("Scribunto", false); + + if (vscode.workspace.getConfiguration("wikitext").get("scopedLuaIntegration") !== "enabled") { + configureLuaLibrary("Scribunto", false); + } } export function configureLuaLibrary(folder: string, enable: boolean) { @@ -47,7 +53,6 @@ export function configureLuaLibrary(folder: string, enable: boolean) { return; } - // Use path.join to ensure the proper path seperators are used. const folderPath = path.join(extensionPath, "EmmyLua", folder); const config = vscode.workspace.getConfiguration("Lua"); const library: string[] | undefined = config.get("workspace.library"); @@ -57,7 +62,7 @@ export function configureLuaLibrary(folder: string, enable: boolean) { if (library && extensionPath) { // remove any older versions of our path - for (let i = library.length-1; i >= 0; i--) { + for (let i = library.length - 1; i >= 0; i--) { const item = library[i]; const isSelfExtension = item.indexOf(extensionId) > -1; const isCurrentVersion = item.indexOf(extensionPath) > -1; @@ -77,6 +82,6 @@ export function configureLuaLibrary(folder: string, enable: boolean) { library.splice(index, 1); } } - config.update("workspace.library", library, true); + config.update("workspace.library", library, false); } } From 5234cbe881166a6c20706809b789331fc7d21163 Mon Sep 17 00:00:00 2001 From: Dawei Huang Date: Mon, 6 Feb 2023 16:55:53 +0800 Subject: [PATCH 3/5] Optimise for readability --- src/extension-node.ts | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/extension-node.ts b/src/extension-node.ts index f888ffb..2d3d2b4 100644 --- a/src/extension-node.ts +++ b/src/extension-node.ts @@ -55,32 +55,25 @@ export function configureLuaLibrary(folder: string, enable: boolean) { const folderPath = path.join(extensionPath, "EmmyLua", folder); const config = vscode.workspace.getConfiguration("Lua"); - const library: string[] | undefined = config.get("workspace.library"); + let library: string[] | undefined = config.get("workspace.library"); if (library === undefined) { return; } if (library && extensionPath) { // remove any older versions of our path - for (let i = library.length - 1; i >= 0; i--) { - const item = library[i]; - const isSelfExtension = item.indexOf(extensionId) > -1; - const isCurrentVersion = item.indexOf(extensionPath) > -1; - if (isSelfExtension && !isCurrentVersion) { - library.splice(i, 1); - } - } + library = library.filter(path => + !path.includes(extensionId) || + path.includes(extensionPath)); const index = library.indexOf(folderPath); if (enable) { - if (index === -1) { + if (index < 0) { library.push(folderPath); } } - else { - if (index > -1) { - library.splice(index, 1); - } + else if (index >= 0) { + library.splice(index, 1); } config.update("workspace.library", library, false); } From b9bd53d15523b0f19799aa0b5006faf420d881be Mon Sep 17 00:00:00 2001 From: David Huang Date: Mon, 11 Mar 2024 23:57:58 +0800 Subject: [PATCH 4/5] Update module --- EmmyLua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EmmyLua b/EmmyLua index bb893db..a654602 160000 --- a/EmmyLua +++ b/EmmyLua @@ -1 +1 @@ -Subproject commit bb893db61c816d68256b2f83c6e0622ee3323d3c +Subproject commit a65460249703d87e256cc041a8999476da296ea9 From 92b26e4dd8d661b17d56abd0ca4bab4171af6a0a Mon Sep 17 00:00:00 2001 From: David Huang Date: Tue, 12 Mar 2024 00:09:13 +0800 Subject: [PATCH 5/5] Format --- src/extension-node.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/extension-node.ts b/src/extension-node.ts index 2d3d2b4..d595f7b 100644 --- a/src/extension-node.ts +++ b/src/extension-node.ts @@ -33,29 +33,29 @@ export function activate(context: vscode.ExtensionContext): void { commandRegistrar.register('citeWeb', addWebCiteFactory); configureLuaLibrary( - "Scribunto", - vscode.workspace.getConfiguration("wikitext").get("scopedLuaIntegration") !== "disabled" + 'Scribunto', + vscode.workspace.getConfiguration('wikitext').get('scopedLuaIntegration') !== 'disabled' ); } export function deactivate(): void { console.log("Extension is inactive."); - if (vscode.workspace.getConfiguration("wikitext").get("scopedLuaIntegration") !== "enabled") { - configureLuaLibrary("Scribunto", false); + if (vscode.workspace.getConfiguration('wikitext').get('scopedLuaIntegration') !== 'enabled') { + configureLuaLibrary('Scribunto', false); } } export function configureLuaLibrary(folder: string, enable: boolean) { - const extensionId = "rowewilsonfrederiskholme.wikitext"; + const extensionId = 'rowewilsonfrederiskholme.wikitext'; const extensionPath = vscode.extensions.getExtension(extensionId)?.extensionPath; if (extensionPath === undefined) { return; } - const folderPath = path.join(extensionPath, "EmmyLua", folder); - const config = vscode.workspace.getConfiguration("Lua"); - let library: string[] | undefined = config.get("workspace.library"); + const folderPath = path.join(extensionPath, 'EmmyLua', folder); + const config = vscode.workspace.getConfiguration('Lua'); + let library: string[] | undefined = config.get('workspace.library'); if (library === undefined) { return; } @@ -75,6 +75,6 @@ export function configureLuaLibrary(folder: string, enable: boolean) { else if (index >= 0) { library.splice(index, 1); } - config.update("workspace.library", library, false); + config.update('workspace.library', library, false); } }