Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show more detailed type information on completion #336

Merged
merged 3 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions src/lsp/cobol_lsp/lsp_completion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,24 @@ 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:Cobol_unit.Types.procedure_paragraph with_loc) =
NeoKaios marked this conversation as resolved.
Show resolved Hide resolved
match ~&paragraph with
| { 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 paragraph ->
to_string_with_type "Paragraph" paragraph
nberth marked this conversation as resolved.
Show resolved Hide resolved
| 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 @@ -243,16 +251,21 @@ let map_completion_items ~(range:Range.t) ~case ~group ~filename comp_entries =
let typ = approx_type_to_string typ in
completion_item_create
~priority_sort:(if is_valid then 2 else 1)
nberth marked this conversation as resolved.
Show resolved Hide resolved
~kind:Variable ~range ~case name
~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:3
~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
Loading