Skip to content

Commit 00954df

Browse files
committed
feat: Automatic Cobol Detection
Based on the first line of the source code for: * `*` in column 7 - comments * `IDENTIFICATION DIVISION` - cobol programs * `01 label` - variable definitions in copybooks * `CBL XOTPS(COBOL2)` - CICS Translator Directives
1 parent 805fdb7 commit 00954df

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

clients/cobol-lsp-vscode-extension/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@
9090
"filenamePatterns": [
9191
"**/*copybook*/**"
9292
],
93-
"configuration": "./syntaxes/lang-config.json"
93+
"configuration": "./syntaxes/lang-config.json",
94+
"firstLine": "^[0-9 ]{6}([*].*|[ ] *([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) +XOPTS\\b.*))$"
9495
}
9596
],
9697
"grammars": [

clients/cobol-lsp-vscode-extension/src/__tests__/extensionTest.spec.ts

+26
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,29 @@ describe("Check plugin extension for cobol fails.", () => {
133133
expect(TelemetryService.registerEvent).toHaveBeenCalledWith("log", ["bootstrap", "experiment-tag"], "Extension activation event was triggered");
134134
});
135135
});
136+
137+
describe.only("Check recognition of COBOL from first line", () => {
138+
const manifest = require('../../package.json')
139+
const firstLine = manifest.contributes.languages[0].firstLine;
140+
const cobol = expect.stringMatching(firstLine)
141+
142+
test("Comment Line", () => {
143+
const pgm = `000010*REALLY ANYTHING`;
144+
expect(pgm).toEqual(cobol)
145+
})
146+
147+
test("Identification Division", () => {
148+
const pgm = `000010 IDENTIFICATION DIVISION.`
149+
expect(pgm).toEqual(cobol)
150+
})
151+
152+
test("Data Definition (copybook)", () => {
153+
const pgm = `000010 01 ABC-XYZ.`;
154+
expect(pgm).toEqual(cobol)
155+
})
156+
157+
test("CICS Translator Directive", () => {
158+
const pgm = `000010 CBL XOPTS(COBOL2)`;
159+
expect(pgm).toEqual(cobol)
160+
})
161+
});

0 commit comments

Comments
 (0)