Skip to content

Commit 53a41d1

Browse files
committed
Optimise
1 parent bee578b commit 53a41d1

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

src/extension-node.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,32 +55,25 @@ export function configureLuaLibrary(folder: string, enable: boolean) {
5555

5656
const folderPath = path.join(extensionPath, "EmmyLua", folder);
5757
const config = vscode.workspace.getConfiguration("Lua");
58-
const library: string[] | undefined = config.get("workspace.library");
58+
let library: string[] | undefined = config.get("workspace.library");
5959
if (library === undefined) {
6060
return;
6161
}
6262

6363
if (library && extensionPath) {
6464
// remove any older versions of our path
65-
for (let i = library.length - 1; i >= 0; i--) {
66-
const item = library[i];
67-
const isSelfExtension = item.indexOf(extensionId) > -1;
68-
const isCurrentVersion = item.indexOf(extensionPath) > -1;
69-
if (isSelfExtension && !isCurrentVersion) {
70-
library.splice(i, 1);
71-
}
72-
}
65+
library = library.filter(path =>
66+
!path.includes(extensionId) ||
67+
path.includes(extensionPath));
7368

7469
const index = library.indexOf(folderPath);
7570
if (enable) {
76-
if (index === -1) {
71+
if (index < 0) {
7772
library.push(folderPath);
7873
}
7974
}
80-
else {
81-
if (index > -1) {
82-
library.splice(index, 1);
83-
}
75+
else if (index >= 0) {
76+
library.splice(index, 1);
8477
}
8578
config.update("workspace.library", library, false);
8679
}

0 commit comments

Comments
 (0)