Skip to content

Commit e6f143a

Browse files
authored
WI #2772 In InsertVariableDisplay consider inactive debug lines as comments (#2773)
1 parent 10371ca commit e6f143a

File tree

3 files changed

+162
-2
lines changed

3 files changed

+162
-2
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
IDENTIFICATION DIVISION.
2+
PROGRAM-ID. TCOMFL06.
3+
ENVIRONMENT DIVISION.
4+
CONFIGURATION SECTION.
5+
SOURCE-COMPUTER.
6+
IBM-370 WITH DEBUGGING MODE.
7+
DATA DIVISION.
8+
WORKING-STORAGE SECTION.
9+
01 group1.
10+
05 var1 PIC X.
11+
05 var2 PIC X.
12+
01 var3 PIC X.
13+
PROCEDURE DIVISION.
14+
MAIN.
15+
PERFORM DEBUG-INFOS
16+
GOBACK
17+
.
18+
DEBUG-INFOS.
19+
*<DBG>Some previous generation by InsertVariableDisplay
20+
D DISPLAY 'group1'
21+
D DISPLAY ' var1 <' var1 '>'
22+
D DISPLAY ' var2 <' var2 '>'
23+
*</DBG>
24+
25+
.
26+
END PROGRAM TCOMFL06.
27+
-------------------------------------------------------------------------------------------------
28+
TypeCobol.LanguageServer.Commands.InsertVariableDisplay.InsertVariableDisplayRefactoringProcessor
29+
-------------------------------------------------------------------------------------------------
30+
[
31+
{
32+
"textDocument": { "uri": "file:/test.expected.cbl" },
33+
"position": { "line": 23, "character": 7 }
34+
},
35+
false,
36+
{
37+
"vm": 1, "idx": 0, "ch": [
38+
{
39+
"vm": 0, "name": "var3"
40+
}
41+
]
42+
}
43+
]
44+
-------------------------------------------------------------------------------------------------
45+
refactoring.label=Debug instructions successfully generated.
46+
refactoring.source=
47+
IDENTIFICATION DIVISION.
48+
PROGRAM-ID. TCOMFL06.
49+
ENVIRONMENT DIVISION.
50+
CONFIGURATION SECTION.
51+
SOURCE-COMPUTER.
52+
IBM-370 WITH DEBUGGING MODE.
53+
DATA DIVISION.
54+
WORKING-STORAGE SECTION.
55+
01 group1.
56+
05 var1 PIC X.
57+
05 var2 PIC X.
58+
01 var3 PIC X.
59+
PROCEDURE DIVISION.
60+
MAIN.
61+
PERFORM DEBUG-INFOS
62+
GOBACK
63+
.
64+
DEBUG-INFOS.
65+
*<DBG>Some previous generation by InsertVariableDisplay
66+
D DISPLAY 'group1'
67+
D DISPLAY ' var1 <' var1 '>'
68+
D DISPLAY ' var2 <' var2 '>'
69+
*</DBG>
70+
*<DBG>InsertVariableDisplay 1959/09/18 11:09 TESTUSER
71+
D DISPLAY 'var3 <' var3 '>'
72+
*</DBG>
73+
74+
75+
.
76+
END PROGRAM TCOMFL06.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
IDENTIFICATION DIVISION.
2+
PROGRAM-ID. TCOMFL06.
3+
ENVIRONMENT DIVISION.
4+
CONFIGURATION SECTION.
5+
SOURCE-COMPUTER.
6+
* IBM-370 WITH DEBUGGING MODE.
7+
DATA DIVISION.
8+
WORKING-STORAGE SECTION.
9+
01 group1.
10+
05 var1 PIC X.
11+
05 var2 PIC X.
12+
01 var3 PIC X.
13+
PROCEDURE DIVISION.
14+
MAIN.
15+
PERFORM DEBUG-INFOS
16+
GOBACK
17+
.
18+
DEBUG-INFOS.
19+
*<DBG>Some previous generation by InsertVariableDisplay
20+
D DISPLAY 'group1'
21+
D DISPLAY ' var1 <' var1 '>'
22+
D DISPLAY ' var2 <' var2 '>'
23+
*</DBG>
24+
25+
.
26+
END PROGRAM TCOMFL06.
27+
-------------------------------------------------------------------------------------------------
28+
TypeCobol.LanguageServer.Commands.InsertVariableDisplay.InsertVariableDisplayRefactoringProcessor
29+
-------------------------------------------------------------------------------------------------
30+
[
31+
{
32+
"textDocument": { "uri": "file:/test.expected.cbl" },
33+
"position": { "line": 23, "character": 7 }
34+
},
35+
false,
36+
{
37+
"vm": 1, "idx": 0, "ch": [
38+
{
39+
"vm": 0, "name": "var3"
40+
}
41+
]
42+
}
43+
]
44+
-------------------------------------------------------------------------------------------------
45+
refactoring.label=Debug instructions successfully generated.
46+
refactoring.source=
47+
IDENTIFICATION DIVISION.
48+
PROGRAM-ID. TCOMFL06.
49+
ENVIRONMENT DIVISION.
50+
CONFIGURATION SECTION.
51+
SOURCE-COMPUTER.
52+
* IBM-370 WITH DEBUGGING MODE.
53+
DATA DIVISION.
54+
WORKING-STORAGE SECTION.
55+
01 group1.
56+
05 var1 PIC X.
57+
05 var2 PIC X.
58+
01 var3 PIC X.
59+
PROCEDURE DIVISION.
60+
MAIN.
61+
PERFORM DEBUG-INFOS
62+
GOBACK
63+
.
64+
DEBUG-INFOS.
65+
*<DBG>Some previous generation by InsertVariableDisplay
66+
D DISPLAY 'group1'
67+
D DISPLAY ' var1 <' var1 '>'
68+
D DISPLAY ' var2 <' var2 '>'
69+
*</DBG>
70+
*<DBG>InsertVariableDisplay 1959/09/18 11:09 TESTUSER
71+
D DISPLAY 'var3 <' var3 '>'
72+
*</DBG>
73+
74+
75+
.
76+
END PROGRAM TCOMFL06.

TypeCobol.LanguageServer/Commands/InsertVariableDisplay/InsertVariableDisplayRefactoringProcessor.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using TypeCobol.Compiler.Concurrency;
44
using TypeCobol.Compiler.Nodes;
55
using TypeCobol.Compiler.Parser;
6+
using TypeCobol.Compiler.Scanner;
67
using TypeCobol.Compiler.Text;
78
using TypeCobol.LanguageServer.Utilities;
89
using TypeCobol.LanguageServer.VsCodeProtocol;
@@ -174,7 +175,7 @@ private static TextEdit InsertBefore(ISearchableReadOnlyList<ICodeElementsLine>
174175
while (lineIndex >= 0)
175176
{
176177
var codeLine = codeLines[lineIndex];
177-
if (codeLine.Type is CobolTextLineType.Comment or CobolTextLineType.MultiFormalizedComment)
178+
if (IsComment(codeLine) || codeLine.Type == CobolTextLineType.MultiFormalizedComment)
178179
{
179180
// Insert before this comment/debug line
180181
line = lineIndex + 1;
@@ -222,7 +223,7 @@ private static TextEdit InsertAfter(ISearchableReadOnlyList<ICodeElementsLine> c
222223
while (lineIndex < codeLines.Count)
223224
{
224225
var codeLine = codeLines[lineIndex];
225-
if (codeLine.Type is CobolTextLineType.Comment) // Do not consider MultiFormalizedComment as they are attached to the code following them
226+
if (IsComment(codeLine)) // Do not consider MultiFormalizedComment as they are attached to the code following them
226227
{
227228
// Insert after this comment/debug line
228229
line = ++lineIndex;
@@ -245,5 +246,12 @@ private static string BeginLine(char indicator, int column)
245246

246247
private static TextEdit InsertAtEnd(ISearchableReadOnlyList<ICodeElementsLine> codeLines, Node node, string code)
247248
=> InsertAfter(codeLines, node.GetLastNode(), code);
249+
250+
private static bool IsComment(ITokensLine line)
251+
{
252+
return line.Type == CobolTextLineType.Comment // Regular comment line
253+
||
254+
(line.Type == CobolTextLineType.Debug && line.ScanState is { WithDebuggingMode: false }); // Inactive Debug line -> treat as Comment
255+
}
248256
}
249257
}

0 commit comments

Comments
 (0)