Skip to content

Commit

Permalink
Merge pull request #13 from nberth/lsp-improvements
Browse files Browse the repository at this point in the history
LSP improvements
  • Loading branch information
nberth authored Oct 2, 2023
2 parents 4bafb38 + 72ad995 commit fd3b888
Show file tree
Hide file tree
Showing 62 changed files with 3,155 additions and 2,360 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

## Features

* LSP (`superbol-free`) with following capabilities:
* LSP (`superbol-free`) with the following capabilities:
* Syntax diagnostics
* Go to definitions
* Find references
* Peek on copybook and source text replacements
* Folding of whole divisions, sections, and paragraphs
* Semantic highlighting
* File and range indentation

Expand Down
106 changes: 53 additions & 53 deletions src/lsp/cobol_ast/branching_statements.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,17 @@ and evaluate_branch =


(* PERFORM *)
and perform_stmt =
and perform_target_stmt =
{
perform_target: perform_target;
perform_target: qualname procedure_range;
perform_mode: perform_mode option;
}

and perform_target =
| PerformOutOfLine of qualname procedure_range
| PerformInline of statements
and perform_inline_stmt =
{
perform_inline_mode: perform_mode option;
perform_statements: statements;
}

and perform_mode =
| PerformNTimes of ident_or_intlit
Expand Down Expand Up @@ -97,28 +99,26 @@ and varying_phrase =
and search_stmt =
{
search_item: qualname;
search_varying: ident option;
search_at_end: handler;
search_spec: search_spec;
search_when_clauses: search_when_clause with_loc list;
}

and search_spec =
| SearchSerial of
{
varying: ident option;
when_clauses: search_when_clause with_loc list;
}
| SearchAll of
{
conditions: search_condition list;
action: branch;
}

and search_when_clause =
{
search_when_cond: condition;
search_when_stmts: branch;
}

(* SEARCH ALL *)
and search_all_stmt =
{
search_all_item: qualname;
search_all_at_end: handler;
search_all_conditions: search_condition list;
search_all_action: branch;
}


(* IF *)
and if_stmt =
Expand Down Expand Up @@ -396,7 +396,8 @@ and statement =
| Move of move_stmt
| Multiply of multiply_stmt
| Open of open_stmt
| Perform of perform_stmt
| PerformTarget of perform_target_stmt
| PerformInline of perform_inline_stmt
| Purge of name with_loc
| Raise of raise_operand
| Read of read_stmt
Expand All @@ -407,6 +408,7 @@ and statement =
| Return of return_stmt
| Rewrite of rewrite_stmt
| Search of search_stmt
| SearchAll of search_all_stmt
| Send of send_stmt
| Set of set_stmt
| Sort of sort_stmt
Expand Down Expand Up @@ -525,21 +527,15 @@ and pp_evaluate_branch ppf { eval_selection; eval_actions } =

(* PERFORM *)

and pp_perform_stmt ppf { perform_target; perform_mode } =
match perform_target with
| PerformInline _ ->
Fmt.pf ppf "@[<v>@[PERFORM%a@]@;<1 2>%a@]"
Fmt.(option (sp ++ pp_perform_mode)) perform_mode
pp_perform_target perform_target
| PerformOutOfLine _ ->
Fmt.pf ppf "@[<hv>PERFORM@;<1 2>%a%a@]"
pp_perform_target perform_target
Fmt.(option (sp ++ pp_perform_mode)) perform_mode

and pp_perform_target ppf = function
| PerformOutOfLine qnpr -> pp_procedure_range pp_qualname ppf qnpr
| PerformInline isl ->
Fmt.pf ppf "%a@ END-PERFORM" pp_statements isl
and pp_perform_target_stmt ppf { perform_target; perform_mode } =
Fmt.pf ppf "@[<hv>PERFORM@;<1 2>%a%a@]"
(pp_procedure_range pp_qualname) perform_target
Fmt.(option (sp ++ pp_perform_mode)) perform_mode

and pp_perform_inline_stmt ppf { perform_inline_mode; perform_statements } =
Fmt.pf ppf "@[<v>@[PERFORM%a@]@;<1 2>%a@ END-PERFORM@]"
Fmt.(option (sp ++ pp_perform_mode)) perform_inline_mode
pp_statements perform_statements

and pp_perform_mode ppf = function
| PerformNTimes i -> Fmt.pf ppf "%a TIMES" pp_ident_or_intlit i
Expand All @@ -563,23 +559,25 @@ and pp_varying_phrase ppf

(* SEARCH *)

and pp_search_stmt ppf { search_item = si; search_at_end = h; search_spec = ss } =
match ss with
| SearchSerial { varying; when_clauses } ->
Fmt.pf ppf "SEARCH %a" pp_qualname si;
Fmt.(option (any "@ VARYING " ++ pp_ident)) ppf varying;
List.iter (fun pf -> pf ppf ()) @@
list_clause Fmt.(any "@ AT END " ++ box pp_handler) h;
Fmt.(sp ++ list ~sep:sp (pp_with_loc pp_search_when_clause)) ppf when_clauses;
Fmt.pf ppf "@ END-SEARCH"
| SearchAll { conditions; action } ->
Fmt.pf ppf "SEARCH ALL %a" pp_qualname si;
List.iter (fun pf -> pf ppf ()) @@
list_clause Fmt.(any "@ AT END " ++ box pp_handler) h;
Fmt.(any "@ WHEN " ++ list ~sep:(any " AND@ ") pp_search_condition)
ppf conditions;
Fmt.(sp ++ pp_branch) ppf action;
Fmt.pf ppf "@ END-SEARCH"
and pp_search_stmt ppf { search_item = si; search_varying = sv;
search_at_end = h; search_when_clauses = swc } =
Fmt.pf ppf "SEARCH %a" pp_qualname si;
Fmt.(option (any "@ VARYING " ++ pp_ident)) ppf sv;
List.iter (fun pf -> pf ppf ()) @@
list_clause Fmt.(any "@ AT END " ++ box pp_handler) h;
Fmt.(sp ++ list ~sep:sp (pp_with_loc pp_search_when_clause)) ppf swc;
Fmt.pf ppf "@ END-SEARCH"

and pp_search_all_stmt ppf { search_all_item = si;
search_all_at_end = h;
search_all_conditions = c;
search_all_action = a } =
Fmt.pf ppf "SEARCH ALL %a" pp_qualname si;
List.iter (fun pf -> pf ppf ()) @@
list_clause Fmt.(any "@ AT END " ++ box pp_handler) h;
Fmt.(any "@ WHEN " ++ list ~sep:(any " AND@ ") pp_search_condition) ppf c;
Fmt.(sp ++ pp_branch) ppf a;
Fmt.pf ppf "@ END-SEARCH"

and pp_search_when_clause ppf { search_when_cond = c; search_when_stmts = w } =
Fmt.pf ppf "WHEN %a@ %a" pp_condition c pp_branch w
Expand Down Expand Up @@ -877,7 +875,8 @@ and pp_statement ppf = function
| Move s -> pp_move_stmt ppf s
| Multiply s -> pp_multiply_stmt ppf s
| Open s -> pp_open_stmt ppf s
| Perform s -> pp_perform_stmt ppf s
| PerformInline s -> pp_perform_inline_stmt ppf s
| PerformTarget s -> pp_perform_target_stmt ppf s
| Purge n -> Fmt.pf ppf "PURGE %a" (pp_with_loc pp_name) n
| Raise ro -> pp_raise_operand ppf ro
| Read s -> pp_read_stmt ppf s
Expand All @@ -888,6 +887,7 @@ and pp_statement ppf = function
| Return s -> pp_return_stmt ppf s
| Rewrite s -> pp_rewrite_stmt ppf s
| Search s -> pp_search_stmt ppf s
| SearchAll s -> pp_search_all_stmt ppf s
| Send s -> pp_send_stmt ppf s
| Set s -> pp_set_stmt ppf s
| Sort s -> pp_sort_stmt ppf s
Expand All @@ -908,4 +908,4 @@ and pp_statements ppf =

and pp_branch ppf = function
| Statements ss -> pp_statements ppf ss
| NextSentence -> Fmt.pf ppf "@[NEXT@ SENTENCE@]"
| NextSentence -> Fmt.pf ppf "@[NEXT@ SENTENCE@]"
34 changes: 17 additions & 17 deletions src/lsp/cobol_ast/misc_descr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ type informational_paragraphs =
(* ------------------------- ENVIRONMENT DIVISION -------------------------- *)
type environment_division =
{
env_configuration: configuration_section option;
env_input_output: input_output_section option;
env_configuration: configuration_section with_loc option;
env_input_output: input_output_section with_loc option;
}
[@@deriving ord]

(* ------------- ENVIRONMENT DIVISION / CONFIGURATION SECTION -------------- *)
and configuration_section =
{
source_computer_paragraph: source_computer_paragraph option;
object_computer_paragraph: object_computer_paragraph option;
special_names_paragraph: special_names_paragraph option;
repository_paragraph: repository_paragraph option; (* +COB2002 *)
source_computer_paragraph: source_computer_paragraph with_loc option;
object_computer_paragraph: object_computer_paragraph with_loc option;
special_names_paragraph: special_names_paragraph with_loc option;
repository_paragraph: repository_paragraph with_loc option; (* +COB2002 *)
}

(* ENVIRONMENT DIVISION / CONFIGURATION SECTION / SOURCE-COMPUTER PARAGRAPH *)
Expand Down Expand Up @@ -237,8 +237,8 @@ and expands =
(* -------------- ENVIRONMENT DIVISION / INPUT-OUTPUT SECTION -------------- *)
and input_output_section =
{
file_control_paragraph: file_control_paragraph option; (* COB85: mandatory *)
io_control_paragraph: io_control_paragraph option;
file_control_paragraph: file_control_paragraph with_loc option; (* COB85: mandatory *)
io_control_paragraph: io_control_paragraph with_loc option;
}

(* - ENVIRONMENT DIVISION / INPUT-OUTPUT SECTION / FILE-CONTROL PARAGRAPH -- *)
Expand Down Expand Up @@ -592,10 +592,10 @@ let pp_configuration_section ppf
special_names_paragraph = snp; repository_paragraph = rp }
=
Fmt.pf ppf "CONFIGURATION SECTION.%a%a%a%a"
Fmt.(option (sp ++ pp_source_computer_paragraph)) scp
Fmt.(option (sp ++ pp_object_computer_paragraph)) ocp
Fmt.(option (sp ++ pp_special_names_paragraph)) snp
Fmt.(option (sp ++ pp_repository_paragraph)) rp
Fmt.(option (sp ++ pp_with_loc pp_source_computer_paragraph)) scp
Fmt.(option (sp ++ pp_with_loc pp_object_computer_paragraph)) ocp
Fmt.(option (sp ++ pp_with_loc pp_special_names_paragraph)) snp
Fmt.(option (sp ++ pp_with_loc pp_repository_paragraph)) rp

let pp_record_delimiter ppf = function
| Standard_1 -> Fmt.pf ppf "STANDARD-1"
Expand Down Expand Up @@ -678,15 +678,15 @@ let pp_input_output_section ppf
{ file_control_paragraph = fcp ; io_control_paragraph = icp }
=
Fmt.pf ppf "INPUT-OUTPUT SECTION.";
Fmt.(option (sp ++ pp_file_control_paragraph)) ppf fcp;
Fmt.(option (sp ++ pp_io_control_paragraph)) ppf icp
Fmt.(option (sp ++ pp_with_loc pp_file_control_paragraph)) ppf fcp;
Fmt.(option (sp ++ pp_with_loc pp_io_control_paragraph)) ppf icp

let pp_environment_division ppf
{ env_configuration = ec; env_input_output = eio }
=
Fmt.pf ppf "ENVIRONMENT DIVISION.%a%a"
Fmt.(option (sp ++ pp_configuration_section)) ec
Fmt.(option (sp ++ pp_input_output_section)) eio
Fmt.(option (sp ++ pp_with_loc pp_configuration_section)) ec
Fmt.(option (sp ++ pp_with_loc pp_input_output_section)) eio

type options_paragraph =
options_clause with_loc list
Expand Down Expand Up @@ -738,4 +738,4 @@ let pp_options_paragraph : options_paragraph Fmt.t =
any "OPTIONS.@ " ++
box (list ~sep:sp (pp_with_loc pp_options_clause))
++ any "."
)
)
Loading

0 comments on commit fd3b888

Please sign in to comment.