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: Cli analysis improvements #2379

Merged
Merged
Show file tree
Hide file tree
Changes from 12 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
5 changes: 4 additions & 1 deletion clients/cobol-lsp-vscode-extension/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"typescript.tsdk": "./node_modules/typescript/lib"
"typescript.tsdk": "./node_modules/typescript/lib",
"files.readonlyInclude": {
"{**/.c4z/.extsrcs/*.PROTSYM.cbl,**/.c4z/.extsrcs/*.PROTSYM.listing}": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ describe("Test Analysis CLI command functionality", () => {
context.globalStorageUri,
context.extensionUri,
);
vscode.window.showQuickPick = jest.fn().mockReturnValue("Java");
vscode.window.showQuickPick = jest
.fn()
.mockReturnValueOnce("Java")
.mockReturnValue("Show");

const runCobolAnalysisCommandSpy = jest.spyOn(
testAnalysis as any,
Expand Down Expand Up @@ -136,7 +139,7 @@ describe("Test Analysis CLI command functionality", () => {

expect(runCobolAnalysisCommandSpy).toHaveBeenCalled();
expect(getCurrentFileLocationSpy).toHaveBeenCalled();
expect(buildJavaCommandSpy).toHaveBeenCalledWith("/storagePath");
expect(buildJavaCommandSpy).toHaveBeenCalledWith("/storagePath", true);
expect(buildJavaCommandSpy).toHaveReturnedWith(
'java -jar "/test/server/jar/server.jar" analysis -s "/storagePath" -cf=.',
);
Expand All @@ -153,7 +156,10 @@ describe("Test Analysis CLI command functionality", () => {
context.globalStorageUri,
context.extensionUri,
);
vscode.window.showQuickPick = jest.fn().mockReturnValue("Native");
vscode.window.showQuickPick = jest
.fn()
.mockReturnValueOnce("Native")
.mockReturnValue("Show");

const runCobolAnalysisCommandSpy = jest.spyOn(
testAnalysis as any,
Expand Down Expand Up @@ -184,6 +190,7 @@ describe("Test Analysis CLI command functionality", () => {
expect(buildNativeCommandSpy).toHaveBeenCalledWith(
"/storagePath",
process.platform,
true,
);
expect(buildAnalysisCommandPortionSpy).toHaveReturnedWith(
'analysis -s "/storagePath" -cf=.',
Expand Down
60 changes: 49 additions & 11 deletions clients/cobol-lsp-vscode-extension/src/commands/RunAnalysisCLI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import * as vscode from "vscode";
import { Terminal } from "vscode";
import show = Mocha.reporters.Base.cursor.show;

export interface AnalysisResults {
typeToRun: string;
Expand Down Expand Up @@ -49,18 +50,21 @@ export class RunAnalysis {
const result = {} as Partial<AnalysisResults>;
await this.getVersionToRun(result);
await this.getCopybookConfigLocation(result);
const showDiagnosticsResult = await this.getShowDiagnosticsChoice();

if (
result.typeToRun === undefined ||
result.copybookLocation === undefined
result.copybookLocation === undefined ||
showDiagnosticsResult === undefined
) {
return;
}

this.runNative = result.typeToRun === "Native";
this.copybookConfigLocation = result.copybookLocation;
const showDiagnostics: boolean = showDiagnosticsResult === "Show";

const command = await this.buildCommand();
const command = await this.buildCommand(showDiagnostics);
if (command !== "") {
this.sendToTerminal(command);
}
Expand All @@ -82,38 +86,58 @@ export class RunAnalysis {
result.copybookLocation = "";
}

public async getShowDiagnosticsChoice() {
return await vscode.window.showQuickPick(["Show", "Hide"], {
placeHolder: "Show diagnostics?",
});
}

/**
* Encapsulates the handling of building the command
* @param showDiagnostics - Option to show/hide diagnostics
* @protected
*/
protected async buildCommand() {
protected async buildCommand(showDiagnostics: boolean) {
const currentFileLocation = await this.getCurrentFileLocation();
if (!currentFileLocation || currentFileLocation === "") {
return "";
}

if (this.runNative) {
return this.buildNativeCommand(currentFileLocation, process.platform);
return this.buildNativeCommand(
currentFileLocation,
process.platform,
showDiagnostics,
);
}

return this.buildJavaCommand(currentFileLocation);
return this.buildJavaCommand(currentFileLocation, showDiagnostics);
}

/**
* Creates the command to run using the native build.
* @param currentFileLocation - Location of the main cobol file being analyzed.
* @param platform - Result from Node.js' "process.platform".
* @param showDiagnostics - Option to show/hide diagnostics
* @protected
*/
protected buildNativeCommand(currentFileLocation: string, platform: string) {
protected buildNativeCommand(
currentFileLocation: string,
platform: string,
showDiagnostics: boolean,
) {
const serverPath = this.extensionUri.fsPath + "/server/native";
const result = this.getServerPath(serverPath, platform);

if (result === "") {
return "";
}

return result + " " + this.buildAnalysisCommandPortion(currentFileLocation);
return (
result +
" " +
this.buildAnalysisCommandPortion(currentFileLocation, showDiagnostics)
);
}

protected getServerPath(serverPath: string, platform: string) {
Expand All @@ -132,9 +156,13 @@ export class RunAnalysis {
/**
* Creates the command to run using the java build.
* @param currentFileLocation - Location of the main cobol file being analyzed.
* @param showDiagnostics - Option to show/hide diagnostics
* @protected
*/
protected buildJavaCommand(currentFileLocation: string) {
protected buildJavaCommand(
currentFileLocation: string,
showDiagnostics: boolean,
) {
const extensionFolder: string | undefined =
this.extensionUri.fsPath + "/server/jar/server.jar";

Expand All @@ -143,7 +171,7 @@ export class RunAnalysis {
'java -jar "' +
extensionFolder +
'" ' +
this.buildAnalysisCommandPortion(currentFileLocation)
this.buildAnalysisCommandPortion(currentFileLocation, showDiagnostics)
);
}

Expand All @@ -154,16 +182,26 @@ export class RunAnalysis {
* Provides the portion of the command from "analysis" onwards.
* Is the same for both the Java and Native builds.
* @param currentFileLocation - Location of the main cobol file being analyzed.
* @param showDiagnostics - Option to show/hide diagnostics
* @protected
*/
protected buildAnalysisCommandPortion(currentFileLocation: string) {
protected buildAnalysisCommandPortion(
currentFileLocation: string,
showDiagnostics: boolean,
) {
const copyBookCommand = `-cf=${
this.copybookConfigLocation === ""
? "."
: '"' + this.copybookConfigLocation + '"'
}`;

return 'analysis -s "' + currentFileLocation + '" ' + copyBookCommand;
return (
'analysis -s "' +
currentFileLocation +
'" ' +
copyBookCommand +
(showDiagnostics ? "" : " -nd")
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.inject.Injector;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -57,6 +58,9 @@
})
@Slf4j
public class Cli implements Callable<Integer> {
static final int SUCCESS = 0;
static final int FAILURE = 1;

ProcessorGroupsResolver processorGroupsResolver;

/**
Expand All @@ -67,7 +71,7 @@ public class Cli implements Callable<Integer> {
*/
@Override
public Integer call() throws Exception {
return 0;
return SUCCESS;
}

Result runAnalysis(File src, CobolLanguageId dialect, Injector diCtx, boolean isAnalysisRequired) throws IOException {
Expand Down Expand Up @@ -99,7 +103,7 @@ static class Result {
}
}

void initProcessorGroupsReader(Path workspace) {
void initProcessorGroupsReader(Path workspace) throws IOException {
if (workspace == null) {
return;
}
Expand All @@ -110,9 +114,11 @@ void initProcessorGroupsReader(Path workspace) {
processorGroupsResolver = new ProcessorGroupsResolver(new String(Files.readAllBytes(programConfig)), new String(Files.readAllBytes(groupsConfig)));
} catch (IOException e) {
LOG.error("Processor group configuration read error", e);
throw e;
}
} else {
LOG.warn("Processor group configuration is missing");
throw new FileNotFoundException("Processor group configuration is missing");
}
}

Expand Down
Loading
Loading