Skip to content
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

feat: Create command to run analysis vscode command via CLI/terminal #2368

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7e8b2e2
Initial Analysis CLI command
mm-broadcom Jun 24, 2024
a8398d6
Add prompts, native builds, start copybook support
mm-broadcom Jun 24, 2024
3175a07
Add temp/unsaved file support
mm-broadcom Jun 24, 2024
4514a5b
Added documentation
mm-broadcom Jun 24, 2024
82b3ac3
Add multi-step UI input
mm-broadcom Jun 25, 2024
dddfad4
Merge remote-tracking branch 'upstream/development' into run-CLI-anal…
mm-broadcom Jun 25, 2024
c6f5fb6
Fixed function access
mm-broadcom Jun 25, 2024
c754939
Remove copybook support
mm-broadcom Jun 26, 2024
e0f3eb6
Remove fs-temp, replace with VSCode API
mm-broadcom Jun 28, 2024
9f31e77
Initial Unit Test
mm-broadcom Jun 28, 2024
2e993b9
Expanded tests to include native call
mm-broadcom Jun 28, 2024
1a6d4eb
Simplified UI code, more unit tests
mm-broadcom Jul 1, 2024
4f52896
Add Temp File Test
mm-broadcom Jul 2, 2024
8a2f528
Merge remote-tracking branch 'upstream/development' into run-CLI-anal…
mm-broadcom Jul 2, 2024
b474d08
Ran Prettier to fix format
mm-broadcom Jul 2, 2024
f8ce8d3
More unit tests
mm-broadcom Jul 2, 2024
1bf16af
Update package-lock.json
mm-broadcom Jul 2, 2024
6ca8d1f
Fix dangling promise
mm-broadcom Jul 2, 2024
6b0dfba
Ran prettier
mm-broadcom Jul 2, 2024
ce956ae
Fixed temp file analysis, addressed PR requests
mm-broadcom Jul 3, 2024
c73d9f2
Use joinPath over string concatenation
mm-broadcom Jul 3, 2024
1a937f2
Update RunAnalysisCLITest.spec.ts
mm-broadcom Jul 3, 2024
306d912
Add temp folder, delete files if exists
mm-broadcom Jul 3, 2024
eb4723c
Simplified temp folder creation, better tests
mm-broadcom Jul 5, 2024
8494062
Fixed Temp file unit test
mm-broadcom Jul 5, 2024
d807b8b
Update clients/cobol-lsp-vscode-extension/src/commands/RunAnalysisCLI.ts
mm-broadcom Jul 8, 2024
597f962
Wrap Map in Promise.all
mm-broadcom Jul 8, 2024
453f33a
Merge branch 'run-CLI-analysis-vscode-command' of https://github.com/…
mm-broadcom Jul 8, 2024
b245637
Cleaned up tests
mm-broadcom Jul 8, 2024
3f8fd6e
Ran prettier
mm-broadcom Jul 8, 2024
7496cd6
Merge remote-tracking branch 'upstream/development' into run-CLI-anal…
mm-broadcom Jul 8, 2024
0024b25
Update Copyright years
mm-broadcom Jul 10, 2024
4745793
Make temp file for any non-local source
mm-broadcom Jul 11, 2024
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
6 changes: 6 additions & 0 deletions clients/cobol-lsp-vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@
"title": "Clear Downloaded Copybooks",
"when": "!isWeb"
},
{
"command": "cobol-lsp.analysis.runAnalysis",
"category": "COBOL",
"title": "Run Analysis in CLI",
"when": "!isWeb"
},
{
"command": "cobol-lsp.snippets.insertSnippets",
"title": "Insert COBOL Snippet",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
/*
* 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 { RunAnalysis } from "../../commands/RunAnalysisCLI";
import * as vscode from "vscode";

jest.mock("vscode", () => ({
commands: {
registerCommand: jest
.fn()
.mockImplementation((command, callback) => callback()),
executeCommand: jest.fn(),
},
extensions: {
getExtension: jest.fn().mockReturnValue({ extensionPath: "/test" }),
},
FileType: {
Directory: 2,
},
languages: {
registerCodeActionsProvider: jest.fn(),
registerCompletionItemProvider: jest.fn(),
},
window: {
activeTextEditor: {
document: {
uri: {
path: "/storagePath",
fsPath: "/storagePath",
scheme: "file",
},
getText: jest.fn(),
},
},
setStatusBarMessage: jest
.fn()
.mockImplementation(
async (_text: string, _hideWhenDone: Thenable<any>) => {
return Promise.resolve(true);
},
),
showErrorMessage: jest.fn().mockReturnValue("test"),
showInformationMessage: jest
.fn()
.mockImplementation((message: string) => Promise.resolve(message)),
showQuickPick: jest.fn(),
onDidChangeActiveTextEditor: jest.fn(),
createQuickPick: jest
.fn()
.mockReturnValue({ onDidChangeSelection: jest.fn(), show: jest.fn() }),
createOutputChannel: jest.fn().mockReturnValue({
appendLine: jest.fn(),
}),
terminals: {
find: jest.fn(),
},
createTerminal: jest.fn().mockReturnValue({
sendText: jest.fn(),
show: jest.fn(),
}),
},
workspace: {
getConfiguration: jest.fn().mockReturnValue({
get: jest.fn().mockReturnValue(9),
}),
getWorkspaceFolder: jest.fn().mockReturnValue({ name: "workspaceFolder1" }),
onDidChangeConfiguration: jest
.fn()
.mockReturnValue("onDidChangeConfiguration"),
workspaceFolders: [{ uri: { fsPath: "ws-path" } } as any],
fs: {
createDirectory: jest.fn(),
readDirectory: jest.fn().mockReturnValue([]),
stat: jest.fn().mockReturnValue(2),
mm-broadcom marked this conversation as resolved.
Show resolved Hide resolved
writeFile: jest.fn(),
},
},
Uri: {
joinPath: jest.fn().mockImplementation((inputUri: vscode.Uri, path) => {
return {
path: inputUri.path + path,
fsPath: inputUri.fsPath + path,
};
}),
},
}));

const context: any = {
extensionUri: { fsPath: "/test" },
globalStorageUri: { fsPath: "/storagePath" },
subscriptions: [],
};

describe("Test Analysis CLI command functionality", () => {
test("Cobol Analysis - Java", async () => {
const testAnalysis = new RunAnalysis(
context.globalStorageUri,
context.extensionUri,
);
vscode.window.showQuickPick = jest.fn().mockReturnValue("Java");

const runCobolAnalysisCommandSpy = jest.spyOn(
testAnalysis as any,
"runCobolAnalysisCommand",
);
const getCurrentFileLocationSpy = jest.spyOn(
testAnalysis as any,
"getCurrentFileLocation",
);
const buildJavaCommandSpy = jest.spyOn(
testAnalysis as any,
"buildJavaCommand",
);
const buildNativeCommandSpy = jest.spyOn(
testAnalysis as any,
"buildNativeCommand",
);
const buildAnalysisCommandPortionSpy = jest.spyOn(
testAnalysis as any,
"buildAnalysisCommandPortion",
);
const sendToTerminalSpy = jest.spyOn(testAnalysis as any, "sendToTerminal");

await testAnalysis.runCobolAnalysisCommand();

expect(runCobolAnalysisCommandSpy).toHaveBeenCalled();
mm-broadcom marked this conversation as resolved.
Show resolved Hide resolved
expect(getCurrentFileLocationSpy).toHaveBeenCalled();
expect(buildJavaCommandSpy).toHaveBeenCalledWith("/storagePath");
expect(buildJavaCommandSpy).toHaveReturnedWith(
'java -jar "/test/server/jar/server.jar" analysis -s "/storagePath" -cf=.',
);
expect(buildAnalysisCommandPortionSpy).toHaveReturnedWith(
'analysis -s "/storagePath" -cf=.',
);
expect(sendToTerminalSpy).toHaveBeenCalled();

expect(buildNativeCommandSpy).toHaveBeenCalledTimes(0);
});

test("Cobol Analysis - Native", async () => {
const testAnalysis = new RunAnalysis(
context.globalStorageUri,
context.extensionUri,
);
vscode.window.showQuickPick = jest.fn().mockReturnValue("Native");

const runCobolAnalysisCommandSpy = jest.spyOn(
testAnalysis as any,
"runCobolAnalysisCommand",
);
const getCurrentFileLocationSpy = jest.spyOn(
testAnalysis as any,
"getCurrentFileLocation",
);
const buildJavaCommandSpy = jest.spyOn(
testAnalysis as any,
"buildJavaCommand",
);
const buildNativeCommandSpy = jest.spyOn(
testAnalysis as any,
"buildNativeCommand",
);
const buildAnalysisCommandPortionSpy = jest.spyOn(
testAnalysis as any,
"buildAnalysisCommandPortion",
);
const sendToTerminalSpy = jest.spyOn(testAnalysis as any, "sendToTerminal");

await testAnalysis.runCobolAnalysisCommand();

expect(runCobolAnalysisCommandSpy).toHaveBeenCalled();
expect(getCurrentFileLocationSpy).toHaveBeenCalled();
expect(buildNativeCommandSpy).toHaveBeenCalledWith(
"/storagePath",
process.platform,
);
expect(buildAnalysisCommandPortionSpy).toHaveReturnedWith(
'analysis -s "/storagePath" -cf=.',
);
expect(sendToTerminalSpy).toHaveBeenCalled();

expect(buildJavaCommandSpy).toHaveBeenCalledTimes(0);
});

test("Cobol Analysis - Undefined Type", async () => {
const testAnalysis = new RunAnalysis(
context.globalStorageUri,
context.extensionUri,
);
vscode.window.showQuickPick = jest.fn().mockReturnValue(undefined);

const runCobolAnalysisCommandSpy = jest.spyOn(
testAnalysis as any,
"runCobolAnalysisCommand",
);
const getVersionToRunSpy = jest.spyOn(
testAnalysis as any,
"getVersionToRun",
);
const buildJavaCommandSpy = jest.spyOn(
testAnalysis as any,
"buildJavaCommand",
);
const buildNativeCommandSpy = jest.spyOn(
testAnalysis as any,
"buildNativeCommand",
);

await testAnalysis.runCobolAnalysisCommand();

expect(runCobolAnalysisCommandSpy).toHaveBeenCalled();
expect(getVersionToRunSpy).toHaveBeenCalled();
expect(buildJavaCommandSpy).not.toHaveBeenCalled();
expect(buildNativeCommandSpy).not.toHaveBeenCalled();
});

test("Cobol Analysis - Save temp file", async () => {
const testAnalysis = new RunAnalysis(
context.globalStorageUri,
context.extensionUri,
);
vscode.window.showQuickPick = jest.fn().mockReturnValue("Java");
if (vscode.window.activeTextEditor) {
vscode.window.activeTextEditor.document.getText = jest
.fn()
.mockReturnValue("Test data");
jest.replaceProperty(
vscode.window.activeTextEditor.document.uri,
"scheme",
"untitled",
);
}

const saveTempFileSpy = jest.spyOn(testAnalysis as any, "saveTempFile");

await testAnalysis.runCobolAnalysisCommand();

expect(saveTempFileSpy).toHaveBeenCalled();
});

test("Cobol - Java - No file location", () => {
const testAnalysis = new RunAnalysis(
context.globalStorageUri,
context.extensionUri,
);

const result = (testAnalysis as any).buildJavaCommand("");

expect(result).toBe("");
});

test("Cobol - getServerPath", () => {
const testAnalysis = new RunAnalysis(
context.globalStorageUri,
context.extensionUri,
);

let result = (testAnalysis as any).getServerPath("initialPath", "win32");
expect(result).toBe("initialPath");

result = (testAnalysis as any).getServerPath("initialPath", "linux");
expect(result).toBe("initialPath/server-linux");

result = (testAnalysis as any).getServerPath("initialPath", "darwin");
expect(result).toBe("initialPath/server-mac");

result = (testAnalysis as any).getServerPath("initialPath", "other");
expect(result).toBe("");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe("Check plugin extension for cobol starts successfully.", () => {
"Extension activation event was triggered",
);

expect(vscode.commands.registerCommand).toBeCalledTimes(10);
expect(vscode.commands.registerCommand).toBeCalledTimes(11);

expect(fetchCopybookCommand).toHaveBeenCalled();
expect(gotoCopybookSettings).toHaveBeenCalled();
Expand Down
Loading
Loading