Skip to content

Commit 364103d

Browse files
fesilysumneko
authored andcommitted
config: add custom repository support for addonManager
1 parent ad6ca4f commit 364103d

File tree

14 files changed

+123
-10
lines changed

14 files changed

+123
-10
lines changed

client/src/addon_manager/config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
export const DEVELOPMENT_IFRAME_URL = "http://127.0.0.1:5173";
33

44
// GitHub Repository Info
5-
export const REPOSITORY_PATH = "https://github.com/LuaLS/LLS-Addons.git";
5+
export const REPOSITORY = {
6+
PATH: "https://github.com/LuaLS/LLS-Addons.git",
7+
DEFAULT_BRANCH: "main",
8+
}
69
export const REPOSITORY_OWNER = "carsakiller";
710
export const REPOSITORY_NAME = "LLS-Addons";
8-
export const REPOSITORY_DEFAULT_BRANCH = "main";
911
export const REPOSITORY_ISSUES_URL =
1012
"https://github.com/LuaLS/vscode-lua/issues/new?template=bug_report.yml";
1113
export const ADDONS_DIRECTORY = "addons";

client/src/addon_manager/registration.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { createChildLogger, logger } from "./services/logging.service";
66
import dayjs from "dayjs";
77
import RelativeTime from "dayjs/plugin/relativeTime";
88
import { git, setupGit } from "./services/git.service";
9-
import { GIT_DOWNLOAD_URL } from "./config";
9+
import { GIT_DOWNLOAD_URL, REPOSITORY } from "./config";
1010
import { NotificationLevels } from "./types/webvue";
1111
import * as languageServer from "../languageserver";
1212

@@ -28,6 +28,17 @@ export async function activate(context: vscode.ExtensionContext) {
2828
const fileLogger = new VSCodeLogFileTransport(context.logUri, {
2929
level: "debug",
3030
});
31+
32+
// update config
33+
const repository_path = globalConfig.get("repository_path") as string
34+
const repository_branch = globalConfig.get("repository_branch") as string
35+
let storageUri = context.globalStorageUri
36+
if ((repository_path || repository_branch) && context.storageUri) {
37+
REPOSITORY.PATH = repository_path ?? REPOSITORY.PATH
38+
REPOSITORY.DEFAULT_BRANCH = repository_branch ?? REPOSITORY.DEFAULT_BRANCH
39+
storageUri = context.storageUri
40+
}
41+
3142

3243
// Register command to open addon manager
3344
context.subscriptions.push(
@@ -83,7 +94,7 @@ export async function activate(context: vscode.ExtensionContext) {
8394

8495
// Set up git repository for fetching addons
8596
try {
86-
setupGit(context);
97+
setupGit(context, storageUri);
8798
} catch (e: any) {
8899
const message =
89100
"Failed to set up Git repository. Please check your connection to GitHub.";

client/src/addon_manager/services/git.service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import * as vscode from "vscode";
22
import simpleGit from "simple-git";
33
import filesystem from "./filesystem.service";
44
import { createChildLogger } from "./logging.service";
5-
import { REPOSITORY_NAME, REPOSITORY_PATH } from "../config";
5+
import { REPOSITORY_NAME, REPOSITORY } from "../config";
66

77
const localLogger = createChildLogger("Git");
88

99
export const git = simpleGit({ trimmed: true });
1010

11-
export const setupGit = async (context: vscode.ExtensionContext) => {
11+
export const setupGit = async (context: vscode.ExtensionContext, storageUri: vscode.Uri) => {
1212
const storageURI = vscode.Uri.joinPath(
13-
context.globalStorageUri,
13+
storageUri,
1414
"addonManager"
1515
);
1616
await filesystem.createDirectory(storageURI);
@@ -25,7 +25,7 @@ export const setupGit = async (context: vscode.ExtensionContext) => {
2525
`Attempting to clone ${REPOSITORY_NAME} to ${storageURI.fsPath}`
2626
);
2727
const options = { "--depth": 1 };
28-
await git.clone(REPOSITORY_PATH, storageURI.fsPath, options);
28+
await git.clone(REPOSITORY.PATH, storageURI.fsPath, options);
2929
localLogger.debug(
3030
`Cloned ${REPOSITORY_NAME} to ${storageURI.fsPath}`
3131
);
@@ -41,7 +41,7 @@ export const setupGit = async (context: vscode.ExtensionContext) => {
4141
try {
4242
await git.fetch();
4343
await git.pull();
44-
await git.checkout("main");
44+
await git.checkout(REPOSITORY.DEFAULT_BRANCH);
4545
} catch (e) {
4646
localLogger.warn(`Failed to pull ${REPOSITORY_NAME}!`);
4747
throw e;

package.nls.ja-jp.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"command.startServer": "Lua: (debug) Start Language Server",
66
"command.stopServer": "Lua: (debug) Stop Language Server",
77
"config.addonManager.enable": "Whether the addon manager is enabled or not.",
8+
"config.addonManager.repository_branch": "Specifies the git branch used by the addon manager.",
9+
"config.addonManager.repository_path": "Specifies the git path used by the addon manager.",
810
"config.codeLens.enable": "Enable code lens.",
911
"config.color.mode": "Color mode.",
1012
"config.color.mode.Grammar": "Grammar color.",

package.nls.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"command.startServer": "Lua: (debug) Start Language Server",
66
"command.stopServer": "Lua: (debug) Stop Language Server",
77
"config.addonManager.enable": "Whether the addon manager is enabled or not.",
8+
"config.addonManager.repository_branch": "Specifies the git branch used by the addon manager.",
9+
"config.addonManager.repository_path": "Specifies the git path used by the addon manager.",
810
"config.codeLens.enable": "Enable code lens.",
911
"config.color.mode": "Color mode.",
1012
"config.color.mode.Grammar": "Grammar color.",

package.nls.pt-br.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"command.startServer": "Lua: (debug) Start Language Server",
66
"command.stopServer": "Lua: (debug) Stop Language Server",
77
"config.addonManager.enable": "Whether the addon manager is enabled or not.",
8+
"config.addonManager.repository_branch": "Specifies the git branch used by the addon manager.",
9+
"config.addonManager.repository_path": "Specifies the git path used by the addon manager.",
810
"config.codeLens.enable": "Enable code lens.",
911
"config.color.mode": "Color mode.",
1012
"config.color.mode.Grammar": "Grammar color.",

package.nls.zh-cn.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"command.startServer": "Lua: (debug) 启动服务器",
66
"command.stopServer": "Lua: (debug) 停止服务器",
77
"config.addonManager.enable": "是否启用扩展的附加插件管理器(Addon Manager)",
8+
"config.addonManager.repository_branch": "插件管理器(Addon Manager)使用的git仓库分支",
9+
"config.addonManager.repository_path": "插件管理器(Addon Manager)使用的git仓库路径",
810
"config.codeLens.enable": "启用代码度量。",
911
"config.color.mode": "着色模式。",
1012
"config.color.mode.Grammar": "语法着色。",

package.nls.zh-tw.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"command.startServer": "Lua: (debug) Start Language Server",
66
"command.stopServer": "Lua: (debug) Stop Language Server",
77
"config.addonManager.enable": "Whether the addon manager is enabled or not.",
8+
"config.addonManager.repository_branch": "Specifies the git branch used by the addon manager.",
9+
"config.addonManager.repository_path": "Specifies the git path used by the addon manager.",
810
"config.codeLens.enable": "Enable code lens.",
911
"config.color.mode": "著色模式。",
1012
"config.color.mode.Grammar": "語法著色。",

setting/schema-ja-jp.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
"properties": {
66
"enable": {
77
"$ref": "#/properties/addonManager.enable"
8+
},
9+
"repository_branch": {
10+
"$ref": "#/properties/addonManager.repository_branch"
11+
},
12+
"repository_path": {
13+
"$ref": "#/properties/addonManager.repository_path"
814
}
915
}
1016
},
@@ -14,6 +20,18 @@
1420
"scope": "resource",
1521
"type": "boolean"
1622
},
23+
"addonManager.repository_branch": {
24+
"default": "",
25+
"markdownDescription": "Specifies the git branch used by the addon manager.",
26+
"scope": "resource",
27+
"type": "string"
28+
},
29+
"addonManager.repository_path": {
30+
"default": "",
31+
"markdownDescription": "Specifies the git path used by the addon manager.",
32+
"scope": "resource",
33+
"type": "string"
34+
},
1735
"codeLens": {
1836
"properties": {
1937
"enable": {

0 commit comments

Comments
 (0)