Skip to content

Commit

Permalink
Feature support multiple lang id (#2256)
Browse files Browse the repository at this point in the history
* feat: make cobol code layout configurable

Signed-off-by: Aman Prashant <aman.prashant@broadcom.com>

* feat: adjust editor rulers as per the layout settings

Signed-off-by: Aman Prashant <aman.prashant@broadcom.com>

* feat: introduce languageId to the language server engine

Signed-off-by: Aman Prashant <aman.prashant@broadcom.com>

* chore: resolve merge conflicts

Signed-off-by: Aman Prashant <aman.prashant@broadcom.com>

* build: increase UI coverage to pass build

Signed-off-by: Aman Prashant <aman.prashant@broadcom.com>

* build: fix tests

Signed-off-by: Aman Prashant <aman.prashant@broadcom.com>

* chore: add syntax files to the vsix

Signed-off-by: Aman Prashant <aman.prashant@broadcom.com>

* Enable HP Cobol copybooks

* Prepare for code refactor

* Remove unused import

* Minor changes

* Fix tests

* Fix tests

---------

Signed-off-by: Aman Prashant <aman.prashant@broadcom.com>
Co-authored-by: Leonid Baranov <nurkambay@gmail.com>
  • Loading branch information
ap891843 and Nurkambay authored Apr 16, 2024
1 parent 2ca3052 commit 09535e3
Show file tree
Hide file tree
Showing 95 changed files with 2,656 additions and 941 deletions.
2 changes: 1 addition & 1 deletion clients/cobol-lsp-vscode-extension/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{
"[typescript]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"[javascript]": {
"editor.formatOnSave": true,
Expand Down
2 changes: 2 additions & 0 deletions clients/cobol-lsp-vscode-extension/.vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
!resources/TELEMETRY_KEY
!package.json
!syntaxes/lang-config.json
!syntaxes/lang-config-hp.json
!syntaxes/COBOL.tmLanguage.json
!syntaxes/CICS.tmLanguage.json
!syntaxes/SQL.tmLanguage.json
!syntaxes/HP.COBOL.tmLanguage.json
!schema/pgm_conf.schema.json
!schema/preprocessor_entry.schema.json
!schema/proc_grps.schema.json
Expand Down
31 changes: 31 additions & 0 deletions clients/cobol-lsp-vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@
],
"configuration": "./syntaxes/lang-config.json",
"firstLine": "^[0-9 ]{6}([*].*|[ Dd] *([Ii][Dd]([Ee][Nn][Tt][Ii][Ff][Ii][Cc][Aa][Tt][Ii][Oo][Nn])? +[Dd][Ii][Vv][Ii][Ss][Ii][Oo][Nn][. ]|[0-9][0-9] +[@#$A-Z][-A-Z0-9]*[. ]|[*](CBL|PROCESS) ).*)$|^([0-9].{5})?[ ]*(CBL|PROCESS) "
},
{
"id": "hpcobol",
"extensions": [
".hpcbl",
".hpcobol",
".hp",
"ecobol"
],
"aliases": [
"HP-COBOL"
],
"configuration": "./syntaxes/lang-config-hp.json",
"firstLine": "^[ ]( *([Ii][Dd]([Ee][Nn][Tt][Ii][Ff][Ii][Cc][Aa][Tt][Ii][Oo][Nn])? +[Dd][Ii][Vv][Ii][Ss][Ii][Oo][Nn][.].*?)$|^\\?.*"
}
],
"grammars": [
Expand Down Expand Up @@ -119,6 +133,14 @@
"injectTo": [
"source.cobol"
]
},
{
"language": "hpcobol",
"scopeName": "source.hpcobol",
"path": "./syntaxes/HP.COBOL.tmLanguage.json",
"embeddedLanguages": {
"meta.embedded.block.html": "html"
}
}
],
"configuration": {
Expand Down Expand Up @@ -427,6 +449,15 @@
80
],
"editor.wordSeparators": "!\"#$%&'()*+,./:;<=>?@[\\]^`{|}~"
},
"[hpcobol]": {
"editor.guides.indentation": false,
"editor.rulers": [
1,
5,
132
],
"editor.wordSeparators": "!\"#$%&'()*+,./:;<=>?@[\\]^`{|}~"
}
},
"keybindings": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { LanguageClientService } from "../../services/LanguageClientService";
import { NativeExecutableService } from "../../services/nativeLanguageClient/nativeExecutableService";
import { TelemetryService } from "../../services/reporter/TelemetryService";
import { Utils } from "../../services/util/Utils";
import { HP_LANGUAGE_ID } from "../../constants";

jest.mock("../../services/reporter/TelemetryService");
jest.mock("../../services/copybook/CopybookURI");
Expand Down Expand Up @@ -140,7 +141,7 @@ describe("LanguageClientService positive scenario", () => {
options: { detached: false },
},
{
documentSelector: [SERVER_ID],
documentSelector: [SERVER_ID, HP_LANGUAGE_ID],
outputChannel: expect.any(Function),
synchronize: {
fileEvents: [undefined, undefined],
Expand All @@ -163,11 +164,11 @@ describe("LanguageClientService positive scenario", () => {
SERVER_DESC,
expect.any(Function),
{
documentSelector: [SERVER_ID],
documentSelector: [SERVER_ID, HP_LANGUAGE_ID],

outputChannel: expect.any(Function),
synchronize: {
fileEvents: [undefined, undefined],
fileEvents: [undefined, undefined, undefined],
},
},
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* 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 * as vscode from "vscode";
import { Range } from "../../../__mocks__/vscode";
import { ServerRuntimeCodeActionProvider } from "../../../services/nativeLanguageClient/serverRuntimeCodeActionProvider";

jest.mock("../../../services/reporter/TelemetryService");
describe("Tests the server code actions", () => {
it("checks that no code action is provided when diagnostics is empty", async () => {
const codeActionProvider = new ServerRuntimeCodeActionProvider();
const { doc, context, token } = getCodeactionMockObjects([]);
const codeActions = await codeActionProvider.provideCodeActions(
doc,
new Range(),
context,
token,
);
expect(codeActions.length).toBe(0);
});

it("checks that no code action is provided when diagnostics is a syntax error and not a setup issue", async () => {
const codeActionProvider = new ServerRuntimeCodeActionProvider();
const { doc, context, token } = getCodeactionMockObjects([
{
range: new Range(),
message: "some syntax error",
severity: 0,
code: "syntax error",
},
]);
const codeActions = await codeActionProvider.provideCodeActions(
doc,
new Range(),
context,
token,
);
expect(codeActions.length).toBe(0);
});

it("checks that code actions are provided when the diagnostics are related to the server type configuration", async () => {
const codeActionProvider = new ServerRuntimeCodeActionProvider();
const { doc, context, token } = getCodeactionMockObjects([
{
range: new Range(),
message: "server configuration error",
severity: 0,
code: "incompatible server type",
},
]);
(vscode.CodeActionKind as any) = {
QuickFix: "quickfix",
};
(vscode.CodeAction as any) = jest.fn();
const codeActions = await codeActionProvider.provideCodeActions(
doc,
new Range(),
context,
token,
);
expect(codeActions.length).toBe(2);
});
});

function getCodeactionMockObjects(diagnostics: vscode.Diagnostic[]) {
const doc = {
uri: { fsPath: "ws-path" },
fileName: "test-file",
lineAt: jest.fn().mockReturnValue({ text: "" }),
} as any;
const context = {
triggerKind: 1,
diagnostics: diagnostics,
only: undefined,
};
const token = {
isCancellationRequested: false,
onCancellationRequested: jest.fn(),
};
return { doc, context, token };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// /*
// * 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 * as vscode from "vscode";
// import { SettingsService } from "../services/Settings";
// import { integer } from "vscode-languageclient";

// export interface LayoutStructure {
// sequence_length?: integer;
// indicator_length?: integer;
// area_a_length?: integer;
// area_b_length?: integer;
// comment_area?: integer;
// }

// // export enum Layout {
// // IBM = "IBM",
// // HP = "HP"
// // }

// // export const layoutMappingObject: Record<string, LayoutStructure> = {
// // [Layout.IBM]: { sequence_length: 6, indicator_length: 1, area_a_length: 4, area_b_length: 61, comment_area: 8 },
// // [Layout.HP]: { sequence_length: 0, indicator_length: 1, area_a_length: 4, area_b_length: 127, comment_area: 0 }
// // }

// // export function updateCobolEditorRuler() {
// // const configuration = vscode.workspace.getConfiguration();

// // const rulers = SettingsService.getCobolProgramLayout();
// // const seqLen = rulers?.sequence_length ?? 6;
// // const indcatorLen = rulers?.indicator_length ?? 1;
// // const areaA = rulers?.area_a_length ?? 4;
// // const areaB = rulers?.area_b_length ?? 61;
// // const commentLen = rulers?.comment_area ?? 8;
// // const rulerIndex = [
// // seqLen,
// // seqLen + indcatorLen,
// // seqLen + indcatorLen + areaA,
// // seqLen + indcatorLen + areaA + areaB,
// // seqLen + indcatorLen + areaA + areaB + commentLen,
// // ];
// // const updatedRules = {
// // ...(configuration.get("[cobol]") as {
// // "editor.guides.indentation": integer;
// // "editor.rulers": integer[];
// // "editor.wordSeparators": string;
// // }),
// // "editor.rulers": rulerIndex,
// // };
// // configuration.update(
// // "[cobol]",
// // updatedRules,
// // vscode.ConfigurationTarget.Workspace,
// // true,
// // );
// // }
1 change: 1 addition & 0 deletions clients/cobol-lsp-vscode-extension/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const C4Z_FOLDER: string = ".c4z";
export const COPYBOOKS_FOLDER: string = ".copybooks";
export const GITIGNORE_FILE: string = ".gitignore";
export const LANGUAGE_ID = "cobol";
export const HP_LANGUAGE_ID = "hpcobol";
export const PROFILE_NAME_PLACEHOLDER = "<profilename>";
export const DOWNLOAD_QUEUE_LOCKED_ERROR_MSG = `Invalid credentials for profile: ${PROFILE_NAME_PLACEHOLDER}. Copybook retrieval is blocked. Ensure the profile contains correct credentials.`;
export const UNLOCK_DOWNLOAD_QUEUE_MSG = "Unblock and retry";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
LanguageClientOptions,
StreamInfo,
} from "vscode-languageclient/node";
import { LANGUAGE_ID } from "../constants";
import { HP_LANGUAGE_ID, LANGUAGE_ID } from "../constants";
import { JavaCheck } from "./JavaCheck";
import { NativeExecutableService } from "./nativeLanguageClient/nativeExecutableService";
import { TelemetryService } from "./reporter/TelemetryService";
Expand Down Expand Up @@ -130,7 +130,7 @@ export class LanguageClientService {

private createClientOptions(): LanguageClientOptions {
return {
documentSelector: [LANGUAGE_ID],
documentSelector: [LANGUAGE_ID, HP_LANGUAGE_ID],
outputChannel: this.outputChannel,
synchronize: {
fileEvents: [
Expand Down
13 changes: 3 additions & 10 deletions clients/cobol-lsp-vscode-extension/src/services/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import {
loadProcessorGroupSqlBackendConfig,
} from "./ProcessorGroups";
import { getProgramNameFromUri } from "./util/FSUtils";
import { integer } from "vscode-languageclient";

/**
* New file (e.g .gitignore) will be created or edited if exits, under project folder
Expand Down Expand Up @@ -154,6 +153,8 @@ export function configHandler(request: any): Array<any> {
} else {
result.push(cfg);
}
} else if (item.section === COBOL_PRGM_LAYOUT) {
result.push(SettingsService.getCobolProgramLayout());
} else {
result.push(vscode.workspace.getConfiguration().get(item.section));
}
Expand Down Expand Up @@ -343,15 +344,7 @@ export class SettingsService {
return vscode.workspace.getConfiguration().get(SERVER_RUNTIME);
}

public static getCobolProgramLayout():
| {
sequence_length?: integer;
indicator_length?: integer;
area_a_length?: integer;
area_b_length?: integer;
comment_area?: integer;
}
| undefined {
public static getCobolProgramLayout() {
return vscode.workspace.getConfiguration().get(COBOL_PRGM_LAYOUT);
}

Expand Down
24 changes: 24 additions & 0 deletions clients/cobol-lsp-vscode-extension/src/type/codeLayout.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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
*/

/**
* Type for a cobol code layout
*/
interface LayoutStructure {
sequence_length?: integer;
indicator_length?: integer;
area_a_length?: integer;
area_b_length?: integer;
comment_area?: integer;
}
Loading

0 comments on commit 09535e3

Please sign in to comment.