Skip to content

Commit

Permalink
feat: show only one comment removed comment marker
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoKaios committed Aug 12, 2024
1 parent a0d5797 commit dcee1c4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 46 deletions.
26 changes: 13 additions & 13 deletions src/lsp/cobol_lsp/lsp_request.ml
Original file line number Diff line number Diff line change
Expand Up @@ -458,25 +458,25 @@ let documetation_of_datadef ~rev_comments ~filename data_def =
let open Cobol_preproc.Text in
let loc = Cobol_data.Item.def_loc data_def in
let def_filename = (fst @@ Cobol_common.Srcloc.as_lexloc loc).pos_fname in
if not (String.equal filename def_filename)
if not (String.equal filename def_filename) (** def is in copybook *)
then ""
else
let def_range = Lsp_position.range_of_srcloc_in ~filename loc in
let comments =
List.rev @@
List.filter_map begin fun { comment_loc; comment_kind; comment_contents } ->
let (inline, full_line) =
List.fold_left begin fun acc { comment_loc; comment_kind; comment_contents } ->
let com_range = Lsp_position.range_of_lexloc comment_loc in
if def_range.start.line = com_range.start.line
|| def_range.start.line = com_range.start.line + 1
&& comment_kind == `Line
then Some comment_contents
else None
end rev_comments
then (Some comment_contents, snd acc)
else if def_range.start.line = com_range.start.line + 1
&& comment_kind == `Line
then (fst acc, Some comment_contents)
else acc
end (None, None) rev_comments
in
match comments with
| [] -> ""
| _ -> Pretty.to_string "\n```cobol\n%a\n```"
Fmt.(list ~sep:(any "\n") string) comments
match inline, full_line with
| Some comment, _ -> "\n---\n" ^ String.sub comment 3 (String.length comment - 3)
| None, Some comment -> "\n---\n" ^ String.sub comment 2 (String.length comment - 2)
| _ -> ""

let lookup_data_definition_for_hover cu_name element_at_pos group =
let { payload = cu; _ } = CUs.find_by_name cu_name group in
Expand Down
66 changes: 33 additions & 33 deletions test/lsp/lsp_hover.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,8 @@ let%expect_test "hover-comment" =
WORKING-STORAGE SECTION.
* full line comment
01 STRUCT. *> inline comment
02 VAL-1 PIC X. *> val1 inline comment
02 VAL-1 PIC X. *> val1 only inline comment
* val2 only line comment
02 VAL-2 PIC X.
PROCEDURE DIVISION.
DISPLAY S_|_TRUCT V_|_AL-1 V_|_AL-2.
Expand All @@ -1161,59 +1162,58 @@ let%expect_test "hover-comment" =
end_with_postproc [%expect.output];
[%expect {|
{"params":{"diagnostics":[],"uri":"file://__rootdir__/prog.cob"},"method":"textDocument/publishDiagnostics","jsonrpc":"2.0"}
(line 11, character 18):
__rootdir__/prog.cob:12.17-12.23:
9 02 VAL-1 PIC X. *> val1 inline comment
10 02 VAL-2 PIC X.
11 PROCEDURE DIVISION.
12 > DISPLAY STRUCT VAL-1 VAL-2.
(line 12, character 18):
__rootdir__/prog.cob:13.17-13.23:
10 * val2 only line comment
11 02 VAL-2 PIC X.
12 PROCEDURE DIVISION.
13 > DISPLAY STRUCT VAL-1 VAL-2.
---- ^^^^^^
13 STOP RUN.
14
14 STOP RUN.
15
```cobol
STRUCT
```
Group of 2 subfields
Size: 16 bits
```cobol
* full line comment
*> inline comment
```
(line 11, character 25):
__rootdir__/prog.cob:12.24-12.29:
9 02 VAL-1 PIC X. *> val1 inline comment
10 02 VAL-2 PIC X.
11 PROCEDURE DIVISION.
12 > DISPLAY STRUCT VAL-1 VAL-2.
---
inline comment
(line 12, character 25):
__rootdir__/prog.cob:13.24-13.29:
10 * val2 only line comment
11 02 VAL-2 PIC X.
12 PROCEDURE DIVISION.
13 > DISPLAY STRUCT VAL-1 VAL-2.
---- ^^^^^
13 STOP RUN.
14
14 STOP RUN.
15
```cobol
VAL-1 IN STRUCT
```
```cobol
PIC X USAGE DISPLAY
```
ALPHANUMERIC(1)
```cobol
*> val1 inline comment
```
(line 11, character 31):
__rootdir__/prog.cob:12.30-12.35:
9 02 VAL-1 PIC X. *> val1 inline comment
10 02 VAL-2 PIC X.
11 PROCEDURE DIVISION.
12 > DISPLAY STRUCT VAL-1 VAL-2.
---
val1 only inline comment
(line 12, character 31):
__rootdir__/prog.cob:13.30-13.35:
10 * val2 only line comment
11 02 VAL-2 PIC X.
12 PROCEDURE DIVISION.
13 > DISPLAY STRUCT VAL-1 VAL-2.
---- ^^^^^
13 STOP RUN.
14
14 STOP RUN.
15
```cobol
VAL-2 IN STRUCT
```
```cobol
PIC X USAGE DISPLAY
```
ALPHANUMERIC(1) |}];;
ALPHANUMERIC(1)
---
val2 only line comment |}];;


let%expect_test "hover-comment-copy" =
Expand Down

0 comments on commit dcee1c4

Please sign in to comment.