Introduce helper method to detect folder in workspace
This commit is contained in:
@@ -255,6 +255,15 @@ export function getOnDiskWorkspaceFolders() {
|
|||||||
return diskWorkspaceFolders;
|
return diskWorkspaceFolders;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Check if folder is already present in workspace */
|
||||||
|
export function isFolderAlreadyInWorkspace(folderName: string) {
|
||||||
|
const workspaceFolders = workspace.workspaceFolders || [];
|
||||||
|
|
||||||
|
return !!workspaceFolders.find(
|
||||||
|
(workspaceFolder) => workspaceFolder.name == folderName,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a utility method to invoke a function only if a minimum time interval has elapsed since
|
* Provides a utility method to invoke a function only if a minimum time interval has elapsed since
|
||||||
* the last invocation of that function.
|
* the last invocation of that function.
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import {
|
|||||||
SecretStorageChangeEvent,
|
SecretStorageChangeEvent,
|
||||||
Uri,
|
Uri,
|
||||||
window,
|
window,
|
||||||
|
workspace,
|
||||||
|
WorkspaceFolder,
|
||||||
} from "vscode";
|
} from "vscode";
|
||||||
import { dump } from "js-yaml";
|
import { dump } from "js-yaml";
|
||||||
import * as tmp from "tmp";
|
import * as tmp from "tmp";
|
||||||
@@ -19,6 +21,7 @@ import { DirResult } from "tmp";
|
|||||||
import {
|
import {
|
||||||
getInitialQueryContents,
|
getInitialQueryContents,
|
||||||
InvocationRateLimiter,
|
InvocationRateLimiter,
|
||||||
|
isFolderAlreadyInWorkspace,
|
||||||
isLikelyDatabaseRoot,
|
isLikelyDatabaseRoot,
|
||||||
isLikelyDbLanguageFolder,
|
isLikelyDbLanguageFolder,
|
||||||
showBinaryChoiceDialog,
|
showBinaryChoiceDialog,
|
||||||
@@ -533,3 +536,21 @@ describe("walkDirectory", () => {
|
|||||||
expect(files.sort()).toEqual([file1, file2, file3, file4, file5, file6]);
|
expect(files.sort()).toEqual([file1, file2, file3, file4, file5, file6]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("isFolderAlreadyInWorkspace", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
const folders = [
|
||||||
|
{ name: "/first/path" },
|
||||||
|
{ name: "/second/path" },
|
||||||
|
] as WorkspaceFolder[];
|
||||||
|
|
||||||
|
jest.spyOn(workspace, "workspaceFolders", "get").mockReturnValue(folders);
|
||||||
|
});
|
||||||
|
it("should return true if the folder is already in the workspace", () => {
|
||||||
|
expect(isFolderAlreadyInWorkspace("/first/path")).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return false if the folder is not in the workspace", () => {
|
||||||
|
expect(isFolderAlreadyInWorkspace("/third/path")).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user