Skip to content

add: enable addons using placeholder #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2024
Merged
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
22 changes: 15 additions & 7 deletions client/src/addon_manager/commands/enable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createChildLogger } from "../services/logging.service";
import { setConfig } from "../../languageserver";
import { WebVue } from "../panels/WebVue";
import { NotificationLevels } from "../types/webvue";
import { ADDONS_DIRECTORY } from "../config";

type Message = {
data: {
Expand All @@ -20,7 +21,7 @@ export default async (context: vscode.ExtensionContext, message: Message) => {
if (!addon || !workspaceFolders) {
return;
}

let selectedFolders: vscode.WorkspaceFolder[];

if (workspaceFolders && workspaceFolders.length === 1) {
Expand All @@ -38,16 +39,23 @@ export default async (context: vscode.ExtensionContext, message: Message) => {
await addon.setLock(false);
return;
}
selectedFolders = pickResult.map((selection) => {
return workspaceFolders.find(
(folder) => folder.name === selection.label
);
}).filter((folder) => !!folder);
selectedFolders = pickResult
.map((selection) => {
return workspaceFolders.find(
(folder) => folder.name === selection.label
);
})
.filter((folder) => !!folder);
}

for (const folder of selectedFolders) {
try {
await addon.enable(folder);
const installLocation = vscode.Uri.joinPath(
context.globalStorageUri,
"addonManager",
ADDONS_DIRECTORY
);
await addon.enable(folder, installLocation);
} catch (e) {
const message = `Failed to enable ${addon.name}!`;
localLogger.error(message, { report: false });
Expand Down
18 changes: 11 additions & 7 deletions client/src/addon_manager/models/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,7 @@ export class Addon {
* @param libraryPaths An array of paths from the `Lua.workspace.library` setting.
*/
public checkIfEnabled(libraryPaths: string[]) {
const regex = new RegExp(
`[/\\\\]+sumneko.lua[/\\\\]+addonManager[/\\\\]+addons[/\\\\]+${this.name}`,
"g"
);
const regex = new RegExp(`${this.name}\/module\/library`, "g");

const index = libraryPaths.findIndex((path) => regex.test(path));
return index !== -1;
Expand Down Expand Up @@ -207,7 +204,10 @@ export class Addon {
return folderStates;
}

public async enable(folder: vscode.WorkspaceFolder) {
public async enable(
folder: vscode.WorkspaceFolder,
installLocation: vscode.Uri
) {
const librarySetting = ((await getConfig(
LIBRARY_SETTING,
folder.uri
Expand Down Expand Up @@ -240,7 +240,11 @@ export class Addon {
}

// Apply addon settings
const libraryUri = vscode.Uri.joinPath(this.uri, "module", "library");
const libraryPath = vscode.Uri.joinPath(
this.uri,
"module",
"library"
).path.replace(installLocation.path, "${addons}");

const configValues = await this.getConfigurationFile();

Expand All @@ -249,7 +253,7 @@ export class Addon {
{
action: "add",
key: LIBRARY_SETTING,
value: filesystem.unixifyPath(libraryUri),
value: libraryPath,
uri: folder.uri,
},
]);
Expand Down
8 changes: 1 addition & 7 deletions client/src/addon_manager/services/settings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ export const getLibraryPaths = async (): Promise<

for (const folder of vscode.workspace.workspaceFolders) {
const libraries = await getConfig(LIBRARY_SETTING, folder.uri);
const libraryPaths = libraries.map((libraryPath: string) => {
if (path.isAbsolute(libraryPath)) {
return libraryPath;
}
return path.join(folder.uri.fsPath, libraryPath);
})
result.push({ folder, paths: libraryPaths ?? [] });
result.push({ folder, paths: libraries });
}

return result;
Expand Down
Loading