Skip to content

Commit

Permalink
Merge pull request #336 from NeoKaios/feat/show-type-completion
Browse files Browse the repository at this point in the history
Show more detail type information on completion
  • Loading branch information
nberth committed Aug 6, 2024
2 parents 423512f + 4aa9a8d commit 58e64f1
Show file tree
Hide file tree
Showing 3 changed files with 736 additions and 718 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [0.1.4] Next release

### Added
- Improved information shown on completion [#336](https://github.com/OCamlPro/superbol-studio-oss/pull/336)
- Configuration flag for caching in storage provided by Visual Studio Code [#167](https://github.com/OCamlPro/superbol-studio-oss/pull/167)
- Configuration setting for copybook filename extensions [#332](https://github.com/OCamlPro/superbol-studio-oss/pull/332), with updated JSON schema [#333](https://github.com/OCamlPro/superbol-studio-oss/pull/333)
- COBOL language configuration for highlighting matching brackets and auto-insertion of line numbers in fixed-format code [#330](https://github.com/OCamlPro/superbol-studio-oss/pull/330)
Expand Down
45 changes: 31 additions & 14 deletions src/lsp/cobol_lsp/lsp_completion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,23 @@ let procedures_proposal ~filename pos group =
match Lsp_lookup.last_cobol_unit_before_pos ~filename pos group with
| None -> []
| Some cu ->
let paragraph_name (paragraph:Cobol_unit.Types.procedure_paragraph with_loc) =
Option.map Cobol_common.Srcloc.payload ~&paragraph.paragraph_name
let to_string_with_type typ paragraph =
match ~&paragraph with
| Cobol_unit.Types.{ paragraph_name = Some { payload = qn; _ }; _ } ->
List.map (fun s -> typ, s) @@ to_string qn
| _ -> []
in
List.flatten @@ List.rev_map (function
| Cobol_unit.Types.Paragraph paragraph ->
Option.to_list @@ paragraph_name paragraph
| Section section ->
List.filter_map paragraph_name ~&section.section_paragraphs.list)
cu.unit_procedure.list
|> List.rev_map to_string
cu.unit_procedure.list
|> List.rev_map begin function
| Cobol_unit.Types.Paragraph p ->
to_string_with_type "Paragraph" p
| Section section ->
List.mapi begin fun i paragraph ->
let typ = (if i == 0 then "Section" else "Paragraph") in
to_string_with_type typ paragraph end
~&section.section_paragraphs.list
|> List.flatten
end
|> List.flatten

let all_intrinsic_function_name =
Expand Down Expand Up @@ -208,7 +215,12 @@ let range_n_case case (pos:Position.t) text =
Range.create ~start:position_start ~end_:pos,
actual_case case start_of_word

let completion_item_create ?(detail="") ?(priority_sort=0) ~range ~kind ~case text=
let p_highest = 3
let p_high = 2
let p_low = 1
let p_none = 0

let completion_item_create ?(detail="") ?(priority_sort=p_none) ~range ~kind ~case text=
let text = change ~case text in
let textEdit =`TextEdit (TextEdit.create ~newText:text ~range) in
let sortText = String.init priority_sort (Fun.const '.') ^ text in
Expand Down Expand Up @@ -242,17 +254,22 @@ let map_completion_items ~(range:Range.t) ~case ~group ~filename comp_entries =
|> List.rev_map begin fun { name; typ; is_valid } ->
let typ = approx_type_to_string typ in
completion_item_create
~priority_sort:(if is_valid then 2 else 1)
~kind:Variable ~range ~case name
~priority_sort:(if is_valid then p_high else p_low)
~detail:(if is_valid then typ else typ ^ " (unexpected here)")
~kind:Variable ~range ~case name
end
| ProcedureRef ->
procedures_proposal ~filename pos group
|> List.rev_map (completion_item_create
~priority_sort:3 ~kind:Function ~range ~case)
|> List.rev_map begin fun (typ, name) ->
completion_item_create
~detail:typ
~priority_sort:p_highest
~kind:Function ~range ~case name
end
| FunctionName ->
all_intrinsic_function_name
|> List.rev_map (completion_item_create
~detail:"Intrinsic"
~kind:Function ~range ~case)
| K tokens -> begin
try [ completion_item_create ~kind:Keyword ~range ~case @@
Expand Down
Loading

0 comments on commit 58e64f1

Please sign in to comment.