Skip to content

Commit

Permalink
fix: fix go to definition for copybook in shared drive (UNC)
Browse files Browse the repository at this point in the history
fix go to definition for copybook in shared drive (UNC).
VsCode is unable to resolve below unc path
 file:////<hostname>/Users/FILE ,
 but can resolve  file://<hostname>/Users/FILE

Signed-off-by: ap891843 <aman.prashant@broadcom.com>
  • Loading branch information
ap891843 committed Jul 23, 2024
1 parent e8331a7 commit 2e61f09
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jest.mock("url", () => {
(globSync as any) = jest.fn().mockImplementation((x: any) => [x]);
(fs.realpathSync.native as any) = jest.fn().mockImplementation((x: any) => x);
(vscode.Uri.file as any) = jest.fn().mockImplementation((x: any) => {
return { fsPath: x };
return { fsPath: x, toString: jest.fn().mockReturnValue(x) };
});

describe("Test the copybook message handler", () => {
Expand All @@ -50,21 +50,19 @@ describe("Test the copybook message handler", () => {
.fn()
.mockReturnValue(["/configured/path/from/setting"]);

expect(
await downloaderNoApi.resolveCopybookHandler(
"cobolFileName",
"copybookName",
"dialectType",
const actualResolvedPath = await downloaderNoApi.resolveCopybookHandler(
"cobolFileName",
"copybookName",
"dialectType",
);
expect(actualResolvedPath).toBe(
path.resolve(
"/configured",
"path",
"from",
"setting",
"copybookName.cpy",
),
).toBe(
"file://" +
path.resolve(
"/configured",
"path",
"from",
"setting",
"copybookName.cpy",
),
);
});

Expand All @@ -81,16 +79,15 @@ describe("Test the copybook message handler", () => {
"dialectType",
),
).toBe(
"file://" +
path.resolve(
"/storagePath",
".zowe",
".copybooks",
"testProfile",
"configured",
"path",
"copybookName",
),
path.resolve(
"/storagePath",
".zowe",
".copybooks",
"testProfile",
"configured",
"path",
"copybookName",
),
);
});

Expand All @@ -109,16 +106,15 @@ describe("Test the copybook message handler", () => {
"dialectType",
),
).toBe(
"file://" +
path.resolve(
"/storagePath",
".zowe",
".copybooks",
"testProfile",
"configured",
"path",
"copybookName",
),
path.resolve(
"/storagePath",
".zowe",
".copybooks",
"testProfile",
"configured",
"path",
"copybookName",
),
);
});
const filename = "cobolFileName";
Expand Down Expand Up @@ -225,15 +221,14 @@ describe("Test the copybook message handler", () => {
type: "type",
});
expect(target).toEqual(
"file://" +
path.resolve(
"/storagePath",
".e4e",
".copybooks",
"instance.profile",
"dataset",
"copybook",
),
path.resolve(
"/storagePath",
".e4e",
".copybooks",
"instance.profile",
"dataset",
"copybook",
),
);
});
it("checks E4E downloaded element copybooks are resolved", async () => {
Expand Down Expand Up @@ -274,19 +269,18 @@ describe("Test the copybook message handler", () => {
type: "type",
});
expect(target).toEqual(
"file://" +
path.resolve(
"/storagePath",
".e4e",
".copybooks",
"instance.profile",
"environment",
"stage",
"system",
"subsystem",
"type",
"copybook",
),
path.resolve(
"/storagePath",
".e4e",
".copybooks",
"instance.profile",
"environment",
"stage",
"system",
"subsystem",
"type",
"copybook",
),
);
});
it("checks E4E downloaded element copybooks are not resolved due to settings", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import * as fs from "fs";
import * as path from "path";
import { globSync, hasMagic } from "glob";
import * as urlUtil from "url";
import { Uri } from "vscode";
import * as vscode from "vscode";
import { Utils } from "./Utils";
Expand All @@ -38,13 +37,7 @@ export function searchCopybookInExtensionFolder(
for (const ext of extensions) {
const searchResult = globSearch(extensionFolder, p, copybookName, ext);
if (searchResult) {
const root = path.parse(searchResult).root;
const urlPath = searchResult
.substring(root.length)
.split(path.sep)
.map((s) => encodeURIComponent(s))
.join(path.sep);
return new urlUtil.URL("file://" + root + urlPath).href;
return vscode.Uri.file(searchResult).toString();
}
}
}
Expand Down

0 comments on commit 2e61f09

Please sign in to comment.