From 366c2443b0e9b501da2647a2b2171dbc65df44c3 Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 20 Mar 2023 14:43:32 +0100 Subject: [PATCH] fix #138 (#140) --- src/clearcase.ts | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/clearcase.ts b/src/clearcase.ts index 120abb1..431096f 100644 --- a/src/clearcase.ts +++ b/src/clearcase.ts @@ -586,7 +586,9 @@ export class ClearCase { */ async getVersionInformation(iUri: Uri, normalize = true): Promise { return new Promise((resolve, reject) => { - if (iUri === undefined || workspace.workspaceFolders === undefined) { + if (iUri === undefined || + workspace.workspaceFolders === undefined || + this.checkIfInWorkspace(iUri.fsPath) === false) { reject(""); } else { let fileVers = ""; @@ -1041,4 +1043,26 @@ export class ClearCase { } return path; } + + /** + * check if the file is within the current workspace + * avoid error messages related to files edited outside the current workspace + */ + private checkIfInWorkspace(file: string): boolean { + let ret = false; + if (workspace.workspaceFolders && file !== "") { + for (const wsPath of workspace.workspaceFolders) { + try { + fs.accessSync(wsPath.uri.fsPath, fs.constants.F_OK); + ret = file.includes(wsPath.uri.fsPath); + if (ret === true) { + break; + } + } catch (e) { + ret = false; + } + } + } + return ret; + } }