Skip to content

Commit e850743

Browse files
authored
Merge pull request #377 from codefori/worksofliam/issue202
Repackage description storage and enhance hover display
2 parents a91e607 + e4c7529 commit e850743

File tree

6 files changed

+82
-49
lines changed

6 files changed

+82
-49
lines changed

extension/server/src/providers/hover.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,16 @@ export default async function hoverProvider(params: HoverParams): Promise<Hover|
4545

4646
markdown += `): ${returnValue}\n\`\`\` \n`;
4747

48-
// Description
49-
if (procedure.description)
50-
markdown += `${procedure.description}\n\n`;
48+
const titleTag = procedure.tags.find(tag => tag.tag === `title`);
49+
const descriptionTag = procedure.tags.find(tag => tag.tag === `description`);
50+
51+
const header = [titleTag ? titleTag.content : undefined, descriptionTag ? descriptionTag.content : undefined].filter(x => x).join(` — `);
52+
53+
// Header
54+
markdown += `${header}\n\n`;
5155

5256
// Params
53-
const paramTags = procedure.tags.filter(tag => tag.tag === `param`);
54-
markdown += procedure.subItems.map((parm, i) => `*@param* \`${parm.name.replace(new RegExp(`\\*`, `g`), `\\*`)}\` ${paramTags[i] ? paramTags[i].content : parm.description}`).join(`\n\n`);
57+
markdown += procedure.subItems.map((parm) => `*@param* \`${parm.name.replace(new RegExp(`\\*`, `g`), `\\*`)}\` ${parm.tags.find(t => t.tag === `description`)?.content || ``}`).join(`\n\n`);
5558

5659
// Return value
5760
if (returnTag) {

language/linter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ export default class Linter {
404404
if (rules.RequiresProcedureDescription) {
405405
const procDef = globalProcs.find(def => def.name.toUpperCase() === value.toUpperCase());
406406
if (procDef) {
407-
if (!procDef.description) {
407+
if (!procDef.tags.some(tag => tag.tag === `description`)) {
408408
errors.push({
409409
type: `RequiresProcedureDescription`,
410410
offset: { start: statement[0].range.start, end: statement[statement.length - 1].range.end }

language/models/declaration.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ type DeclarationType = "procedure"|"subroutine"|"file"|"struct"|"subitem"|"varia
88
export default class Declaration {
99
name: string = ``;
1010
keyword: Keywords = {};
11-
description: string = ``;
1211
tags: {tag: string, content: string}[] = [];
1312
position: {path: string, range: IRangeWithLine};
1413
references: Reference[] = [];
@@ -22,7 +21,6 @@ export default class Declaration {
2221
const clone = new Declaration(this.type);
2322
clone.name = this.name;
2423
clone.keyword = this.keyword;
25-
clone.description = this.description;
2624
clone.tags = this.tags;
2725

2826
if (this.position) {

language/parser.ts

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,6 @@ export default class Parser {
741741
currentItem = new Declaration(`file`);
742742
currentItem.name = partsLower[1];
743743
currentItem.keyword = Parser.expandKeywords(tokens.slice(2));
744-
currentItem.description = currentDescription.join(`\n`);
745744

746745
currentItem.position = {
747746
path: fileUri,
@@ -792,7 +791,6 @@ export default class Parser {
792791
currentItem = new Declaration(`constant`);
793792
currentItem.name = partsLower[1];
794793
currentItem.keyword = Parser.expandKeywords(tokens.slice(2), true);
795-
currentItem.description = currentDescription.join(`\n`);
796794

797795
currentItem.position = {
798796
path: fileUri,
@@ -811,7 +809,6 @@ export default class Parser {
811809
currentItem = new Declaration(`variable`);
812810
currentItem.name = partsLower[1];
813811
currentItem.keyword = Parser.expandKeywords(tokens.slice(2));
814-
currentItem.description = currentDescription.join(`\n`);
815812
currentItem.tags = currentTags;
816813

817814
currentItem.position = {
@@ -831,7 +828,6 @@ export default class Parser {
831828
currentItem = new Declaration(`constant`);
832829
currentItem.name = partsLower[1];
833830
currentItem.keyword = Parser.expandKeywords(tokens.slice(2));
834-
currentItem.description = currentDescription.join(`\n`);
835831

836832
currentItem.position = {
837833
path: fileUri,
@@ -868,7 +864,6 @@ export default class Parser {
868864
currentItem = new Declaration(`struct`);
869865
currentItem.name = partsLower[1];
870866
currentItem.keyword = Parser.expandKeywords(tokens.slice(2));
871-
currentItem.description = currentDescription.join(`\n`);
872867
currentItem.tags = currentTags;
873868

874869
currentItem.position = {
@@ -933,7 +928,6 @@ export default class Parser {
933928
currentItem = new Declaration(`procedure`);
934929
currentItem.name = partsLower[1];
935930
currentItem.keyword = Parser.expandKeywords(tokens.slice(2));
936-
currentItem.description = currentDescription.join(`\n`);
937931
currentItem.tags = currentTags;
938932

939933
currentItem.position = {
@@ -990,7 +984,6 @@ export default class Parser {
990984
currentProcName = partsLower[1];
991985
currentItem.name = currentProcName;
992986
currentItem.keyword = Parser.expandKeywords(tokens.slice(2));
993-
currentItem.description = currentDescription.join(`\n`);
994987
currentItem.tags = currentTags;
995988

996989
currentItem.position = {
@@ -1080,7 +1073,6 @@ export default class Parser {
10801073
if (!scope.subroutines.find(sub => sub.name && sub.name.toUpperCase() === parts[1])) {
10811074
currentItem = new Declaration(`subroutine`);
10821075
currentItem.name = partsLower[1];
1083-
currentItem.description = currentDescription.join(`\n`);
10841076
currentItem.keyword = {'Subroutine': true};
10851077

10861078
currentItem.position = {
@@ -1179,9 +1171,14 @@ export default class Parser {
11791171

11801172
if (currentSqlItem.name)
11811173
currentSqlItem.keyword = {};
1174+
1175+
if (qualifiedObjectPath.schema) {
1176+
currentSqlItem.tags.push({
1177+
tag: `description`,
1178+
content: qualifiedObjectPath.schema
1179+
})
1180+
}
11821181

1183-
currentSqlItem.description = qualifiedObjectPath.schema || ``;
1184-
11851182
currentSqlItem.position = {
11861183
path: fileUri,
11871184
range: qualifiedObjectPath.nameToken.range
@@ -1219,14 +1216,20 @@ export default class Parser {
12191216
});
12201217
} else {
12211218
if (currentTags.length > 0) {
1222-
currentTags[currentTags.length - 1].content += ` ${content}`;
1219+
const lastTag = currentTags[currentTags.length - 1];
1220+
lastTag.content += (lastTag.content.length === 0 ? `` : ` `) + content;
1221+
1222+
} else if (!currentTags.some(tag => tag.tag === `title`)) {
1223+
currentTags.push({
1224+
tag: `title`,
1225+
content
1226+
});
1227+
1228+
currentTags.push({
1229+
tag: `description`,
1230+
content: ``
1231+
});
12231232

1224-
} else {
1225-
if (currentTitle === undefined) {
1226-
currentTitle = content;
1227-
} else {
1228-
currentDescription.push(content);
1229-
}
12301233
}
12311234
}
12321235
}
@@ -1265,7 +1268,10 @@ export default class Parser {
12651268
const paramTags = currentItem.tags.filter(tag => tag.tag === `param`);
12661269
const paramTag = paramTags.length > currentItem.subItems.length ? paramTags[currentItem.subItems.length] : undefined;
12671270
if (paramTag) {
1268-
currentSub.description = paramTag.content;
1271+
currentSub.tags = [{
1272+
tag: `description`,
1273+
content: paramTag.content
1274+
}];
12691275
}
12701276
}
12711277

@@ -1439,7 +1445,6 @@ export default class Parser {
14391445
const f2Value = cSpec.factor2.value;
14401446
callItem.name = (f2Value.startsWith(`'`) && f2Value.endsWith(`'`) ? f2Value.substring(1, f2Value.length-1) : f2Value);
14411447
callItem.keyword = {'EXTPGM': true}
1442-
callItem.description = currentDescription.join(`\n`);
14431448
callItem.tags = currentTags;
14441449

14451450
callItem.position = {

tests/suite/basics.test.ts

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,10 @@ test('exec_1', async () => {
884884

885885
expect(cache.sqlReferences.length).toBe(1);
886886
expect(cache.sqlReferences[0].name).toBe(`sysdummy1`);
887-
expect(cache.sqlReferences[0].description).toBe(`sysibm`);
887+
expect(cache.sqlReferences[0].tags[0]).toEqual({
888+
tag: `description`,
889+
content: `sysibm`
890+
});
888891
});
889892

890893
test('exec_2', async () => {
@@ -912,10 +915,13 @@ test('exec_2', async () => {
912915

913916
expect(cache.sqlReferences.length).toBe(2);
914917
expect(cache.sqlReferences[0].name).toBe(`Employee`);
915-
expect(cache.sqlReferences[0].description).toBe(``);
918+
expect(cache.sqlReferences[0].tags.length).toBe(0);
916919

917920
expect(cache.sqlReferences[1].name).toBe(`Employee`);
918-
expect(cache.sqlReferences[1].description).toBe(`sample`);
921+
expect(cache.sqlReferences[1].tags[0]).toEqual({
922+
tag: `description`,
923+
content: `sample`
924+
});
919925
});
920926

921927
test('exec_3', async () => {
@@ -969,7 +975,10 @@ test('exec_4', async () => {
969975

970976
expect(cache.sqlReferences.length).toBe(1);
971977
expect(cache.sqlReferences[0].name).toBe(`employee`);
972-
expect(cache.sqlReferences[0].description).toBe(`sample`);
978+
expect(cache.sqlReferences[0].tags[0]).toEqual({
979+
tag: `description`,
980+
content: `sample`
981+
});
973982
});
974983

975984
test('exec_5', async () => {
@@ -992,10 +1001,13 @@ test('exec_5', async () => {
9921001
expect(cache.sqlReferences.length).toBe(2);
9931002

9941003
expect(cache.sqlReferences[0].name).toBe(`mytable`);
995-
expect(cache.sqlReferences[0].description).toBe(`sample`);
1004+
expect(cache.sqlReferences[0].tags[0]).toEqual({
1005+
tag: `description`,
1006+
content: `sample`
1007+
});
9961008

9971009
expect(cache.sqlReferences[1].name).toBe(`othertable`);
998-
expect(cache.sqlReferences[1].description).toBe(``);
1010+
expect(cache.sqlReferences[1].tags.length).toBe(0);
9991011
});
10001012

10011013
test('exec_6', async () => {
@@ -1020,10 +1032,13 @@ test('exec_6', async () => {
10201032
expect(cache.sqlReferences.length).toBe(2);
10211033

10221034
expect(cache.sqlReferences[0].name).toBe(`mytable`);
1023-
expect(cache.sqlReferences[0].description).toBe(`sample`);
1035+
expect(cache.sqlReferences[0].tags[0]).toEqual({
1036+
tag: `description`,
1037+
content: `sample`
1038+
});
10241039

10251040
expect(cache.sqlReferences[1].name).toBe(`othertable`);
1026-
expect(cache.sqlReferences[1].description).toBe(``);
1041+
expect(cache.sqlReferences[1].tags.length).toBe(0);
10271042
});
10281043

10291044
test('exec_7', async () => {
@@ -1048,10 +1063,13 @@ test('exec_7', async () => {
10481063
expect(cache.sqlReferences.length).toBe(2);
10491064

10501065
expect(cache.sqlReferences[0].name).toBe(`thetable`);
1051-
expect(cache.sqlReferences[0].description).toBe(`sample`);
1066+
expect(cache.sqlReferences[0].tags[0]).toEqual({
1067+
tag: `description`,
1068+
content: `sample`
1069+
});
10521070

10531071
expect(cache.sqlReferences[1].name).toBe(`cooltable`);
1054-
expect(cache.sqlReferences[1].description).toBe(``);
1072+
expect(cache.sqlReferences[1].tags.length).toBe(0);
10551073
});
10561074

10571075
test('exec_8', async () => {
@@ -1076,10 +1094,13 @@ test('exec_8', async () => {
10761094
expect(cache.sqlReferences.length).toBe(2);
10771095

10781096
expect(cache.sqlReferences[0].name).toBe(`thetable`);
1079-
expect(cache.sqlReferences[0].description).toBe(`sample`);
1097+
expect(cache.sqlReferences[0].tags[0]).toEqual({
1098+
tag: `description`,
1099+
content: `sample`
1100+
});
10801101

10811102
expect(cache.sqlReferences[1].name).toBe(`wooptable`);
1082-
expect(cache.sqlReferences[1].description).toBe(``);
1103+
expect(cache.sqlReferences[1].tags.length).toBe(0);
10831104
});
10841105

10851106
test('exec_9', async () => {
@@ -1102,10 +1123,13 @@ test('exec_9', async () => {
11021123
expect(cache.sqlReferences.length).toBe(2);
11031124

11041125
expect(cache.sqlReferences[0].name).toBe(`MyRandomProc`);
1105-
expect(cache.sqlReferences[0].description).toBe(`sample`);
1126+
expect(cache.sqlReferences[0].tags[0]).toEqual({
1127+
tag: `description`,
1128+
content: `sample`
1129+
});
11061130

11071131
expect(cache.sqlReferences[1].name).toBe(`OtherCoolProc`);
1108-
expect(cache.sqlReferences[1].description).toBe(``);
1132+
expect(cache.sqlReferences[1].tags.length).toBe(0);
11091133
});
11101134

11111135
test('exec_10', async () => {
@@ -1125,10 +1149,10 @@ test('exec_10', async () => {
11251149
expect(cache.sqlReferences.length).toBe(2);
11261150

11271151
expect(cache.sqlReferences[0].name).toBe(`PSBORDS`);
1128-
expect(cache.sqlReferences[0].description).toBe(``);
1152+
expect(cache.sqlReferences[0].tags.length).toBe(0);
11291153

11301154
expect(cache.sqlReferences[1].name).toBe(`PMESSGS`);
1131-
expect(cache.sqlReferences[1].description).toBe(``);
1155+
expect(cache.sqlReferences[1].tags.length).toBe(0);
11321156
});
11331157

11341158
test('exec_11', async () => {
@@ -1353,7 +1377,6 @@ test('issue_353_comments', async () => {
13531377

13541378
const hedinf = cache.find(`HEDINF`);
13551379
expect(hedinf).toBeDefined();
1356-
console.log(hedinf.subItems.map(s => s.name));
13571380
expect(hedinf.subItems.length).toBe(5);
13581381
const p2at = cache.find(`p2@`);
13591382
expect(p2at).toBeDefined();
@@ -1525,7 +1548,6 @@ test('fixed-format c spec', async () => {
15251548
expect(cache.procedures[0].name).toBe(`UpdArt`);
15261549
expect(cache.procedures[0].subItems.length).toBe(2);
15271550

1528-
console.log(cache.variables);
15291551
expect(cache.structs.length).toBe(3);
15301552
expect(cache.variables.length).toBe(1);
15311553

tests/suite/docs.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,26 @@ test("issue_202", async () => {
2929

3030
const toLower = cache.find(`ToLower`);
3131

32-
expect(toLower.description).toBe(`This procedure will take a string and transform it to lowercase`);
32+
const titleTag = toLower.tags.find(tag => tag.tag === `title`);
33+
expect(titleTag.content).toBe(`Transform to lowercase`);
34+
35+
const descTag = toLower.tags.find(tag => tag.tag === `description`);
36+
expect(descTag.content).toBe(`This procedure will take a string and transform it to lowercase`);
3337

3438
const tags = toLower.tags;
35-
expect(tags[0]).toEqual({
39+
expect(tags[2]).toEqual({
3640
tag: `param`,
3741
content: `The string`
3842
});
3943

40-
expect(tags[1]).toEqual({
44+
expect(tags[3]).toEqual({
4145
tag: `return`,
4246
content: `The lowercase value`
4347
});
4448

4549
const stringInParam = toLower.subItems[0];
46-
expect(stringInParam.description).toBe(`The string`);
50+
const parmTag = stringInParam.tags.find(tag => tag.tag === `description`);
51+
expect(parmTag.content).toBe(`The string`);
4752
});
4853

4954
test("issue_231", async () => {

0 commit comments

Comments
 (0)