Skip to content

feat: bridge for git initial support #2449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,6 @@ yamljs (0.3.0)
* License: MIT


io-ts (2.2.21)

* License: MIT
27 changes: 27 additions & 0 deletions clients/cobol-lsp-vscode-extension/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions clients/cobol-lsp-vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@
"@vscode/extension-telemetry": "^0.9.7",
"glob": "10.3.10",
"iconv-lite": "^0.6.3",
"io-ts": "2.2.21",
"micromatch": "^4.0.7",
"vscode-languageclient": "^8.1.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jest.mock("../services/Settings", () => ({
.fn()
.mockReturnValueOnce(undefined)
.mockReturnValue("JAVA"),
getSnippetsForCobol: jest.fn().mockReturnValue([]),
getSnippetsForCobol: jest.fn().mockReturnValue(Promise.resolve([])),
getDialects: jest.fn().mockReturnValue([]),
},
}));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Copyright (c) 2024 Broadcom.
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Broadcom, Inc. - initial API and implementation
*/

import { B4GTypeMetadata, decodeBridgeJson } from "../../services/BridgeForGit";
import { loadProcessorsConfigForDocument } from "../../services/ProcessorGroups";
import * as path from "path";

jest.mock("vscode", () => ({
Uri: {
parse: jest.fn().mockImplementation((str: string) => {
const fsPath = str.substring("file://".length).replace(/\//g, path.sep);
const p =
(str.startsWith("/") ? "" : "/") + str.substring("file://".length);
return {
path: p,
fsPath: process.platform === "win32" ? fsPath.substring(1) : fsPath,
};
}),
},
workspace: {
getConfiguration: jest.fn().mockReturnValue({
get: jest.fn(),
}),
workspaceFolders: [
{
uri: {
fsPath: "/home/",
},
},
],
},
}));
const b4gJson = {
elements: {
main: {
processorGroup: "pg2",
},
},
defaultProcessorGroup: "DEFGRP",
definedProcessorGroups: [
{
name: "pg2",
description: "A GROUP",
},
{
name: "DEFGRP",
description: "DEFAULT GROUP",
},
],
fileExtension: "cob",
};

const b4gJsonNoExt = {
elements: {
main: {
processorGroup: "pg2",
},
},
defaultProcessorGroup: "DEFGRP",
definedProcessorGroups: [
{
name: "pg2",
description: "A GROUP",
},
{
name: "DEFGRP",
description: "DEFAULT GROUP",
},
],
fileExtension: "",
};

const pgJson = [{ name: "pg1" }, { name: "pg2" }];
const pgMapJson = { pgms: [{ program: "main.cob", pgroup: "pg1" }] };

describe("Bridge for Git group tests", () => {
test("Decode b4f json", () => {
const result = decodeBridgeJson(b4gJson);
expect(result).toBeDefined();
expect(result!.elements["main"].processorGroup).toBe("pg2");
expect(Object.keys(result!.elements)[0] + "." + result!.fileExtension).toBe(
"main.cob",
);
});

test("Map file into processor group", () => {
const scopeUri = "file:///home/main.cob";
const cfg = loadProcessorsConfigForDocument(
scopeUri,
pgJson,
pgMapJson,
decodeBridgeJson(b4gJson),
);
expect(cfg?.name).toBe("pg2");
});

test("No extension case", () => {
const scopeUri = "file:///home/main";
const cfg = loadProcessorsConfigForDocument(
scopeUri,
pgJson,
pgMapJson,
decodeBridgeJson(b4gJsonNoExt),
);
expect(cfg?.name).toBe("pg2");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ jest.mock("vscode", () => ({
};
}),
joinPath: (u: any, segment: string) => {
if (segment === "../.bridge.json") {
return {
path: u.path.substring(0, u.path.lastIndexOf("/") + "/.bridge.json"),
fsPath:
u.fsPath.substring(0, u.fsPath.lastIndexOf("/")) + "/.bridge.json",
};
}
expect(segment).toBe("..");
const path = u.path;
return {
Expand All @@ -103,6 +110,11 @@ jest.mock("vscode", () => ({
}),
},
workspace: {
fs: {
readFile: jest.fn().mockImplementation(() => {
throw { code: "FileNotFound" };
}),
},
getWorkspaceFolder: jest
.fn()
.mockReturnValue({ uri: { fsPath: "file:///my/workspace" } }),
Expand All @@ -111,6 +123,7 @@ jest.mock("vscode", () => ({
}));

jest.mock("path", () => ({
...jest.requireActual("path"),
join: jest.fn().mockImplementation((...strs: string[]) => {
if (strs[1] === "pgm_conf.json") {
return "pgmCfgPath";
Expand All @@ -129,7 +142,7 @@ jest.mock("path", () => ({
sep: "/",
}));

it("Processor groups configuration provides lib path", () => {
it("Processor groups configuration provides lib path", async () => {
const item = {
scopeUri: WORKSPACE_URI + "/TEST.cob",
section: "cobol-lsp.cpy-manager.paths-local",
Expand All @@ -138,11 +151,11 @@ it("Processor groups configuration provides lib path", () => {
if (config[0] === "/copy") return ["/copy-resolved-from-glob"];
else throw Error("some issue with input param");
});
const result = loadProcessorGroupCopybookPathsConfig(item, []);
const result = await loadProcessorGroupCopybookPathsConfig(item, []);
expect(result).toStrictEqual(["/copy-resolved-from-glob"]);
});

it("Processor groups configuration understend absolute paths", () => {
it("Processor groups configuration understend absolute paths", async () => {
const item = {
scopeUri: WORKSPACE_URI + "/abs/TEST.cob",
section: "cobol-lsp.cpy-manager.paths-local",
Expand All @@ -151,86 +164,86 @@ it("Processor groups configuration understend absolute paths", () => {
if (config[0] === "/abs") return ["/copy-resolved-from-glob"];
else throw Error("some issue with input param");
});
const result = loadProcessorGroupCopybookPathsConfig(item, []);
const result = await loadProcessorGroupCopybookPathsConfig(item, []);
expect(result).toStrictEqual(["/copy-resolved-from-glob"]);
});

it("Processor groups configuration provides copybook-extensions", () => {
it("Processor groups configuration provides copybook-extensions", async () => {
const item = {
scopeUri: WORKSPACE_URI + "/TEST.cob",
section: "cobol-lsp.cpy-manager.copybook-extensions",
};
const result = loadProcessorGroupCopybookExtensionsConfig(item, []);
const result = await loadProcessorGroupCopybookExtensionsConfig(item, []);
expect(result).toStrictEqual([".copy"]);
});

it("Processor groups configuration provides copybook-file-encoding", () => {
it("Processor groups configuration provides copybook-file-encoding", async () => {
const item = {
scopeUri: WORKSPACE_URI + "/TEST.cob",
section: "cobol-lsp.cpy-manager.copybook-file-encoding",
};
const result = loadProcessorGroupCopybookEncodingConfig(item, "");
const result = await loadProcessorGroupCopybookEncodingConfig(item, "");
expect(result).toStrictEqual("UTF-8");
});

it("Processor groups configuration provides cobol-lsp.target-sql-backend", () => {
it("Processor groups configuration provides cobol-lsp.target-sql-backend", async () => {
const item = {
scopeUri: WORKSPACE_URI + "/TEST.cob",
section: "cobol-lsp.target-sql-backend",
};
const result = loadProcessorGroupSqlBackendConfig(item, "");
const result = await loadProcessorGroupSqlBackendConfig(item, "");
expect(result).toStrictEqual("DATACOM_SERVER");
});

it("Processor groups configuration provides dialect lib path", () => {
const result = loadProcessorGroupCopybookPaths(
it("Processor groups configuration provides dialect lib path", async () => {
const result = await loadProcessorGroupCopybookPaths(
WORKSPACE_URI + "/TEST.cob",
"DaCo",
);
expect(result).toStrictEqual(["/daco"]);
});

it("Processor groups configuration matches program", () => {
it("Processor groups configuration matches program", async () => {
const item = {
scopeUri: WORKSPACE_URI + "/TEST.cob",
section: "cobol-lsp.dialects",
};
const result = loadProcessorGroupDialectConfig(item, {});
const result = await loadProcessorGroupDialectConfig(item, {});
expect(result).toStrictEqual(["IDMS", "DaCo"]);
});

it("Processor groups configuration matches program relative to workspace", () => {
it("Processor groups configuration matches program relative to workspace", async () => {
const item = {
scopeUri: WORKSPACE_URI + "/IDMS/TEST.cob",
section: "cobol-lsp.dialects",
};
const result = loadProcessorGroupDialectConfig(item, {});
const result = await loadProcessorGroupDialectConfig(item, {});
expect(result).toStrictEqual(["IDMS"]);
});

it("Processor groups configuration matches program with *", () => {
it("Processor groups configuration matches program with *", async () => {
const item = {
scopeUri: WORKSPACE_URI + "/progDaF.cob",
section: "cobol-lsp.dialects",
};
const result = loadProcessorGroupDialectConfig(item, {});
const result = await loadProcessorGroupDialectConfig(item, {});
expect(result).toStrictEqual(["IDMS", "DaCo"]);
});

it("Processor groups configuration mismatches program with *", () => {
it("Processor groups configuration mismatches program with *", async () => {
const item = {
scopeUri: WORKSPACE_URI + "/progDA.cob",
section: "cobol-lsp.dialects",
};
const result = loadProcessorGroupDialectConfig(item, {});
const result = await loadProcessorGroupDialectConfig(item, {});
expect(result).toStrictEqual({});
});

it("Processor groups configuration provides compiler-options", () => {
it("Processor groups configuration provides compiler-options", async () => {
const item = {
scopeUri: WORKSPACE_URI + "/TEST.cob",
section: "cobol-lsp.compiler.options",
};
const result = loadProcessorGroupCompileOptionsConfig(item, "");
const result = await loadProcessorGroupCompileOptionsConfig(item, "");
expect(result).toStrictEqual(["QUALIFY(EXTEND)", "XMLPARSE(COMPAT)"]);
});
Loading
Loading