Skip to content
This repository was archived by the owner on Apr 19, 2025. It is now read-only.

Commit 445ee7e

Browse files
committed
feat(extension): replace homedir with ~
1 parent 4088e9e commit 445ee7e

File tree

8 files changed

+122
-119
lines changed

8 files changed

+122
-119
lines changed

plugin

Submodule plugin updated 66 files

src/extension.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { ExtensionContext, extensions, workspace, commands } from "vscode";
2+
import { homedir } from "os";
23

34
export const id = "overextended.cfxlua-vscode";
4-
export const path = extensions.getExtension(id)!.extensionPath;
5+
export const extensionPath = extensions
6+
.getExtension(id)!
7+
.extensionPath.replace(homedir(), "~");
58

69
import setPlugin from "./setPlugin";
710
import setLibrary from "./setLibrary";
@@ -10,29 +13,29 @@ import setNativeLibrary from "./setNativeLibrary";
1013
// this method is called when your extension is activated
1114
// your extension is activated the very first time the command is executed
1215
export async function activate(context: ExtensionContext) {
13-
const game = workspace.getConfiguration("cfxlua").get("game", "GTAV");
14-
await setPlugin(true);
15-
await setLibrary(
16-
["runtime", "natives/CFX-NATIVE", `natives/${game.toUpperCase()}`],
17-
true
18-
);
16+
const game = workspace.getConfiguration("cfxlua").get("game", "GTAV");
17+
await setPlugin(true);
18+
await setLibrary(
19+
["runtime", "natives/CFX-NATIVE", `natives/${game.toUpperCase()}`],
20+
true,
21+
);
1922

20-
context.subscriptions.push(
21-
commands.registerCommand("cfxlua.game.gtav", () => {
22-
setNativeLibrary("gtav");
23-
}),
23+
context.subscriptions.push(
24+
commands.registerCommand("cfxlua.game.gtav", () => {
25+
setNativeLibrary("gtav");
26+
}),
2427

25-
commands.registerCommand("cfxlua.game.rdr3", () => {
26-
setNativeLibrary("rdr3");
27-
})
28-
);
28+
commands.registerCommand("cfxlua.game.rdr3", () => {
29+
setNativeLibrary("rdr3");
30+
}),
31+
);
2932
}
3033

3134
// this method is called when your extension is deactivated
3235
export async function deactivate() {
33-
await setPlugin(false);
34-
await setLibrary(
35-
["runtime", "natives/CFX-NATIVE", "natives/GTAV", "natives/RDR3"],
36-
false
37-
);
36+
await setPlugin(false);
37+
await setLibrary(
38+
["runtime", "natives/CFX-NATIVE", "natives/GTAV", "natives/RDR3"],
39+
false,
40+
);
3841
}

src/getLuaConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { workspace } from "vscode";
22

33
export default function getLuaConfig() {
4-
return workspace.getConfiguration("Lua");
4+
return workspace.getConfiguration("Lua");
55
}

src/getPath.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as path from "path";
2-
import { path as extensionPath } from "./extension";
2+
import { extensionPath } from "./extension";
33

44
export default function getLuaPath(...args: string[]) {
5-
return path.join(extensionPath, "plugin", ...args);
5+
return path.join(extensionPath, "plugin", ...args);
66
}

src/getSettingsScope.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { workspace } from "vscode";
22

33
export default function getSettingsScope() {
4-
return workspace.workspaceFile ? 2 : 1;
4+
return workspace.workspaceFile ? 2 : 1;
55
}

src/setLibrary.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
import * as path from "path";
2-
import { path as extensionPath, id as extensionId } from "./extension";
2+
import { extensionPath, id as extensionId } from "./extension";
33
import getLuaPath from "./getPath";
44
import getLuaConfig from "./getLuaConfig";
55
import getSettingsScope from "./getSettingsScope";
66

77
export default async function setLibrary(folders: string[], enable: boolean) {
8-
const config = getLuaConfig();
9-
const library: string[] = config.get("workspace.library")!;
8+
const config = getLuaConfig();
9+
const library: string[] = config.get("workspace.library")!;
1010

11-
for (const folder of folders) {
12-
const folderPath = getLuaPath(path.join("library", folder));
11+
for (const folder of folders) {
12+
const folderPath = getLuaPath(path.join("library", folder));
1313

14-
for (let i = library.length - 1; i >= 0; i--) {
15-
const el = library[i];
16-
const isSelfExtension = el.includes(extensionId);
17-
const isCurrentVersion = el.includes(extensionPath);
18-
if (isSelfExtension && !isCurrentVersion) {
19-
library.splice(i, 1);
20-
}
21-
}
14+
for (let i = library.length - 1; i >= 0; i--) {
15+
const el = library[i];
16+
const isSelfExtension = el.includes(extensionId);
17+
const isCurrentVersion = el.includes(extensionPath);
18+
if (isSelfExtension && !isCurrentVersion) {
19+
library.splice(i, 1);
20+
}
21+
}
2222

23-
const index = library.indexOf(folderPath);
23+
const index = library.indexOf(folderPath);
2424

25-
if (enable) {
26-
if (index === -1) {
27-
library.push(folderPath);
28-
}
29-
} else {
30-
if (index > -1) {
31-
library.splice(index, 1);
32-
}
33-
}
34-
}
25+
if (enable) {
26+
if (index === -1) {
27+
library.push(folderPath);
28+
}
29+
} else {
30+
if (index > -1) {
31+
library.splice(index, 1);
32+
}
33+
}
34+
}
3535

36-
await config.update("workspace.library", library, getSettingsScope());
36+
await config.update("workspace.library", library, getSettingsScope());
3737
}

src/setNativeLibrary.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@ import setLibrary from "./setLibrary";
33
import getSettingsScope from "./getSettingsScope";
44

55
export default async function setNativeLibrary(game?: string) {
6-
const config = workspace.getConfiguration("cfxlua");
6+
const config = workspace.getConfiguration("cfxlua");
77

8-
if (!game) {
9-
game = config.get("game") || "gtav";
10-
}
8+
if (!game) {
9+
game = config.get("game") || "gtav";
10+
}
1111

12-
await config.update("game", game, getSettingsScope());
12+
await config.update("game", game, getSettingsScope());
1313

14-
game = game.toUpperCase();
14+
game = game.toUpperCase();
1515

16-
if (game !== "GTAV" && game !== "RDR3") {
17-
return;
18-
}
16+
if (game !== "GTAV" && game !== "RDR3") {
17+
return;
18+
}
1919

20-
if (game !== "GTAV") {
21-
await setLibrary([`natives/GTAV`], false);
22-
}
20+
if (game !== "GTAV") {
21+
await setLibrary([`natives/GTAV`], false);
22+
}
2323

24-
if (game !== "RDR3") {
25-
await setLibrary([`natives/RDR3`], false);
26-
}
24+
if (game !== "RDR3") {
25+
await setLibrary([`natives/RDR3`], false);
26+
}
2727

28-
await setLibrary([`natives/${game}`], true);
28+
await setLibrary([`natives/${game}`], true);
2929
}

src/setPlugin.ts

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,57 @@ import getLuaPath from "./getPath";
33
import getSettingsScope from "./getSettingsScope";
44

55
export default async function setPlugin(enable: boolean) {
6-
const config = getLuaConfig();
7-
const pluginPath = getLuaPath("plugin.lua");
8-
const settingsScope = getSettingsScope();
9-
10-
if (enable) {
11-
await config.update("runtime.version", "Lua 5.4", settingsScope);
12-
await config.update("runtime.plugin", pluginPath, settingsScope);
13-
14-
// Support extra symbols in LuaParser
15-
const nonstandardSymbol: string[] =
16-
config.get("runtime.nonstandardSymbol") || [];
17-
[
18-
"/**/",
19-
"`",
20-
"+=",
21-
"-=",
22-
"*=",
23-
"/=",
24-
"<<=",
25-
">>=",
26-
"&=",
27-
"|=",
28-
"^=",
29-
].forEach((item) => {
30-
if (!nonstandardSymbol.includes(item)) {
31-
nonstandardSymbol.push(item);
32-
}
33-
});
34-
35-
await config.update(
36-
"runtime.nonstandardSymbol",
37-
nonstandardSymbol,
38-
settingsScope
39-
);
40-
41-
// Disable diagnostics for files/directories (using .gitignore grammar)
42-
// Drastically improves time to load workspace
43-
const ignoreDir: string[] = config.get("workspace.ignoreDir") || [];
44-
45-
[".vscode", ".git", ".github", "node_modules"].forEach((item) => {
46-
if (!ignoreDir.includes(item)) {
47-
ignoreDir.push(item);
48-
}
49-
});
50-
51-
await config.update("workspace.ignoreDir", ignoreDir, settingsScope);
52-
53-
return;
54-
}
55-
56-
if (config.get("runtime.plugin") === pluginPath) {
57-
await config.update("runtime.plugin", undefined, settingsScope);
58-
}
6+
const config = getLuaConfig();
7+
const pluginPath = getLuaPath("plugin.lua");
8+
const settingsScope = getSettingsScope();
9+
10+
if (enable) {
11+
await config.update("runtime.version", "Lua 5.4", settingsScope);
12+
await config.update("runtime.plugin", pluginPath, settingsScope);
13+
14+
// Support extra symbols in LuaParser
15+
const nonstandardSymbol: string[] =
16+
config.get("runtime.nonstandardSymbol") || [];
17+
[
18+
"/**/",
19+
"`",
20+
"+=",
21+
"-=",
22+
"*=",
23+
"/=",
24+
"<<=",
25+
">>=",
26+
"&=",
27+
"|=",
28+
"^=",
29+
].forEach((item) => {
30+
if (!nonstandardSymbol.includes(item)) {
31+
nonstandardSymbol.push(item);
32+
}
33+
});
34+
35+
await config.update(
36+
"runtime.nonstandardSymbol",
37+
nonstandardSymbol,
38+
settingsScope,
39+
);
40+
41+
// Disable diagnostics for files/directories (using .gitignore grammar)
42+
// Drastically improves time to load workspace
43+
const ignoreDir: string[] = config.get("workspace.ignoreDir") || [];
44+
45+
[".vscode", ".git", ".github", "node_modules"].forEach((item) => {
46+
if (!ignoreDir.includes(item)) {
47+
ignoreDir.push(item);
48+
}
49+
});
50+
51+
await config.update("workspace.ignoreDir", ignoreDir, settingsScope);
52+
53+
return;
54+
}
55+
56+
if (config.get("runtime.plugin") === pluginPath) {
57+
await config.update("runtime.plugin", undefined, settingsScope);
58+
}
5959
}

0 commit comments

Comments
 (0)