Skip to content

Commit 4f68a9b

Browse files
carsakillersumneko
authored andcommitted
add: enable addons using placeholder
1 parent 167692d commit 4f68a9b

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

client/src/addon_manager/commands/enable.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { createChildLogger } from "../services/logging.service";
44
import { setConfig } from "../../languageserver";
55
import { WebVue } from "../panels/WebVue";
66
import { NotificationLevels } from "../types/webvue";
7+
import { ADDONS_DIRECTORY } from "../config";
78

89
type Message = {
910
data: {
@@ -20,7 +21,7 @@ export default async (context: vscode.ExtensionContext, message: Message) => {
2021
if (!addon || !workspaceFolders) {
2122
return;
2223
}
23-
24+
2425
let selectedFolders: vscode.WorkspaceFolder[];
2526

2627
if (workspaceFolders && workspaceFolders.length === 1) {
@@ -38,16 +39,23 @@ export default async (context: vscode.ExtensionContext, message: Message) => {
3839
await addon.setLock(false);
3940
return;
4041
}
41-
selectedFolders = pickResult.map((selection) => {
42-
return workspaceFolders.find(
43-
(folder) => folder.name === selection.label
44-
);
45-
}).filter((folder) => !!folder);
42+
selectedFolders = pickResult
43+
.map((selection) => {
44+
return workspaceFolders.find(
45+
(folder) => folder.name === selection.label
46+
);
47+
})
48+
.filter((folder) => !!folder);
4649
}
4750

4851
for (const folder of selectedFolders) {
4952
try {
50-
await addon.enable(folder);
53+
const installLocation = vscode.Uri.joinPath(
54+
context.globalStorageUri,
55+
"addonManager",
56+
ADDONS_DIRECTORY
57+
);
58+
await addon.enable(folder, installLocation);
5159
} catch (e) {
5260
const message = `Failed to enable ${addon.name}!`;
5361
localLogger.error(message, { report: false });

client/src/addon_manager/models/addon.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,7 @@ export class Addon {
173173
* @param libraryPaths An array of paths from the `Lua.workspace.library` setting.
174174
*/
175175
public checkIfEnabled(libraryPaths: string[]) {
176-
const regex = new RegExp(
177-
`[/\\\\]+sumneko.lua[/\\\\]+addonManager[/\\\\]+addons[/\\\\]+${this.name}`,
178-
"g"
179-
);
176+
const regex = new RegExp(`${this.name}\/module\/library`, "g");
180177

181178
const index = libraryPaths.findIndex((path) => regex.test(path));
182179
return index !== -1;
@@ -207,7 +204,10 @@ export class Addon {
207204
return folderStates;
208205
}
209206

210-
public async enable(folder: vscode.WorkspaceFolder) {
207+
public async enable(
208+
folder: vscode.WorkspaceFolder,
209+
installLocation: vscode.Uri
210+
) {
211211
const librarySetting = ((await getConfig(
212212
LIBRARY_SETTING,
213213
folder.uri
@@ -240,7 +240,11 @@ export class Addon {
240240
}
241241

242242
// Apply addon settings
243-
const libraryUri = vscode.Uri.joinPath(this.uri, "module", "library");
243+
const libraryPath = vscode.Uri.joinPath(
244+
this.uri,
245+
"module",
246+
"library"
247+
).path.replace(installLocation.path, "${addons}");
244248

245249
const configValues = await this.getConfigurationFile();
246250

@@ -249,7 +253,7 @@ export class Addon {
249253
{
250254
action: "add",
251255
key: LIBRARY_SETTING,
252-
value: filesystem.unixifyPath(libraryUri),
256+
value: libraryPath,
253257
uri: folder.uri,
254258
},
255259
]);

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,7 @@ export const getLibraryPaths = async (): Promise<
2424

2525
for (const folder of vscode.workspace.workspaceFolders) {
2626
const libraries = await getConfig(LIBRARY_SETTING, folder.uri);
27-
const libraryPaths = libraries.map((libraryPath: string) => {
28-
if (path.isAbsolute(libraryPath)) {
29-
return libraryPath;
30-
}
31-
return path.join(folder.uri.fsPath, libraryPath);
32-
})
33-
result.push({ folder, paths: libraryPaths ?? [] });
27+
result.push({ folder, paths: libraries });
3428
}
3529

3630
return result;

0 commit comments

Comments
 (0)