Skip to content

Commit

Permalink
Optimise for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
davidxuang committed Mar 11, 2024
1 parent 91c59ac commit 5234cbe
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/extension-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 5234cbe

Please sign in to comment.