From 1be21d542c4bcc26bb7e657a30a0b2e9848dee5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Basile=20Cl=C3=A9ment?= Date: Wed, 25 Oct 2023 17:06:01 +0200 Subject: [PATCH 1/9] Indent text from buffer, not disk When indenting a file from the LSP, use the text from the current buffer, not the last version saved to disk (otherwise changes could disappear). --- src/lsp/cobol_indent/cobol_indent.ml | 9 +++++++-- src/lsp/cobol_indent/indenter.ml | 20 ++++++-------------- src/lsp/cobol_indent/indenter.mli | 3 ++- src/lsp/cobol_lsp/lsp_request.ml | 11 +++++++---- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/lsp/cobol_indent/cobol_indent.ml b/src/lsp/cobol_indent/cobol_indent.ml index ad15b12d0..21e32576d 100644 --- a/src/lsp/cobol_indent/cobol_indent.ml +++ b/src/lsp/cobol_indent/cobol_indent.ml @@ -18,10 +18,15 @@ let indent_range' = Indenter.indent_range' (*indent the whole file and print*) let indent_file ~dialect ~source_format ~file ~indent_config = - indent_range' ~dialect ~source_format ~range:None ~indent_config ~file + let contents = Ez_file.V1.EzFile.read_file file in + indent_range' + ~dialect ~source_format ~range:None ~indent_config + ~filename:file ~contents |> Fmt.pr "%s" (*indent a range of file and print*) let indent_range ~dialect ~source_format ~file ~range ~indent_config = - indent_range' ~dialect ~source_format ~range ~indent_config ~file + let contents = Ez_file.V1.EzFile.read_file file in + indent_range' ~dialect ~source_format ~range ~indent_config + ~filename:file ~contents |> Fmt.pr "%s" diff --git a/src/lsp/cobol_indent/indenter.ml b/src/lsp/cobol_indent/indenter.ml index 135129811..766628fe0 100644 --- a/src/lsp/cobol_indent/indenter.ml +++ b/src/lsp/cobol_indent/indenter.ml @@ -62,30 +62,22 @@ let indenter ~source_format (str:string) (rdl:indent_record list) range = String.concat "\n" strl (*indent a range of file, with the default indent_config*) -let indent_range' ~dialect ~source_format ~range ~file = - let file_content = Ez_file.V1.EzFile.read_file file in - (* - Not satisfied with the `Cobol_preproc.fold_text_lines`, - this function has an argument which is the name of file, - so when using lsp, every time using the formatting, - we must save the file before, it is not convenient. - (* NB: not anymore. *) - *) +let indent_range' ~dialect ~source_format ~range ~filename ~contents = let state = Cobol_preproc.fold_source_lines ~dialect ~source_format - ~skip_compiler_directives_text:false + ~skip_compiler_directives_text:true ~f:(fun _lnum line acc -> Indent_check.check_indentation line acc) - (String { contents = file_content; filename = file; }) + (String { filename; contents }) { scope = BEGIN; context = []; acc = []; range } in (* NB: note here we ignore diagnostics *) let ind_recds = state.result.acc in - indenter ~source_format file_content ind_recds state.result.range + indenter ~source_format contents ind_recds state.result.range (*indent a range of file, with the user-defined indent_config*) -let indent_range' ~dialect ~source_format ~indent_config ~range ~file = +let indent_range' ~dialect ~source_format ~indent_config ~range ~filename ~contents = begin match indent_config with | Some indent_config -> Indent_config.set_config ~indent_config | None -> () end; - indent_range' ~dialect ~source_format ~range ~file + indent_range' ~dialect ~source_format ~range ~filename ~contents diff --git a/src/lsp/cobol_indent/indenter.mli b/src/lsp/cobol_indent/indenter.mli index c6f62793e..a2d1d10c0 100644 --- a/src/lsp/cobol_indent/indenter.mli +++ b/src/lsp/cobol_indent/indenter.mli @@ -17,5 +17,6 @@ val indent_range' -> source_format:Cobol_config.source_format_spec -> indent_config:string option -> range:Indent_type.range option - -> file:string + -> filename:string + -> contents:string -> string diff --git a/src/lsp/cobol_lsp/lsp_request.ml b/src/lsp/cobol_lsp/lsp_request.ml index b80534384..52de0eb57 100644 --- a/src/lsp/cobol_lsp/lsp_request.ml +++ b/src/lsp/cobol_lsp/lsp_request.ml @@ -159,7 +159,9 @@ let handle_references state (params: ReferenceParams.t) = let handle_range_formatting registry params = let open DocumentRangeFormattingParams in let { textDocument = doc; range = {start; end_}; _ } = params in - let Lsp_document.{ project; _ } = Lsp_server.find_document doc registry in + let Lsp_document.{ project; textdoc; _ } = + Lsp_server.find_document doc registry + in let range_to_indent = Cobol_indent.Type.{ start_line = start.line + 1; @@ -180,7 +182,8 @@ let handle_range_formatting registry params = ~dialect:(Cobol_config.dialect project.cobol_config) ~source_format:project.source_format ~indent_config:None - ~file:(Lsp.Uri.to_path doc.uri) + ~filename:(Lsp.Uri.to_path doc.uri) + ~contents:(Lsp.Text_document.text textdoc) ~range:(Some range_to_indent) in Some [TextEdit.create ~newText ~range] @@ -198,14 +201,14 @@ let handle_formatting registry params = ~start:(Position.create ~character:0 ~line:0) ~end_:(Position.create ~character:width ~line:length) in - let path = Lsp.Uri.to_path doc.uri in try let newText = Cobol_indent.indent_range' ~dialect:(Cobol_config.dialect project.cobol_config) ~source_format:project.source_format ~indent_config:None - ~file:path + ~filename:(Lsp.Uri.to_path doc.uri) + ~contents:(Lsp.Text_document.text textdoc) ~range:None in Some [TextEdit.create ~newText ~range:edit_range] From b6951e7aaa77006553829a40ede307a0eba509ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Basile=20Cl=C3=A9ment?= Date: Thu, 26 Oct 2023 12:57:17 +0200 Subject: [PATCH 2/9] Rename indent_range' to indent_range --- src/lsp/cobol_indent/cobol_indent.ml | 13 +++---------- src/lsp/cobol_indent/indenter.ml | 6 +++--- src/lsp/cobol_indent/indenter.mli | 2 +- src/lsp/cobol_lsp/lsp_request.ml | 4 ++-- src/lsp/superbol_free_lib/command_indent_file.ml | 10 +++++++--- src/lsp/superbol_free_lib/command_indent_range.ml | 5 +++-- 6 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/lsp/cobol_indent/cobol_indent.ml b/src/lsp/cobol_indent/cobol_indent.ml index 21e32576d..716186b31 100644 --- a/src/lsp/cobol_indent/cobol_indent.ml +++ b/src/lsp/cobol_indent/cobol_indent.ml @@ -14,19 +14,12 @@ module Type = Indent_type (*return the result of indentation. use user-defined indent_config*) -let indent_range' = Indenter.indent_range' +let indent_range = Indenter.indent_range (*indent the whole file and print*) let indent_file ~dialect ~source_format ~file ~indent_config = let contents = Ez_file.V1.EzFile.read_file file in - indent_range' + indent_range ~dialect ~source_format ~range:None ~indent_config ~filename:file ~contents - |> Fmt.pr "%s" - -(*indent a range of file and print*) -let indent_range ~dialect ~source_format ~file ~range ~indent_config = - let contents = Ez_file.V1.EzFile.read_file file in - indent_range' ~dialect ~source_format ~range ~indent_config - ~filename:file ~contents - |> Fmt.pr "%s" + |> Fmt.pr "%s" \ No newline at end of file diff --git a/src/lsp/cobol_indent/indenter.ml b/src/lsp/cobol_indent/indenter.ml index 766628fe0..b5311de88 100644 --- a/src/lsp/cobol_indent/indenter.ml +++ b/src/lsp/cobol_indent/indenter.ml @@ -62,7 +62,7 @@ let indenter ~source_format (str:string) (rdl:indent_record list) range = String.concat "\n" strl (*indent a range of file, with the default indent_config*) -let indent_range' ~dialect ~source_format ~range ~filename ~contents = +let indent_range ~dialect ~source_format ~range ~filename ~contents = let state = Cobol_preproc.fold_source_lines ~dialect ~source_format ~skip_compiler_directives_text:true @@ -75,9 +75,9 @@ let indent_range' ~dialect ~source_format ~range ~filename ~contents = indenter ~source_format contents ind_recds state.result.range (*indent a range of file, with the user-defined indent_config*) -let indent_range' ~dialect ~source_format ~indent_config ~range ~filename ~contents = +let indent_range ~dialect ~source_format ~indent_config ~range ~filename ~contents = begin match indent_config with | Some indent_config -> Indent_config.set_config ~indent_config | None -> () end; - indent_range' ~dialect ~source_format ~range ~filename ~contents + indent_range ~dialect ~source_format ~range ~filename ~contents \ No newline at end of file diff --git a/src/lsp/cobol_indent/indenter.mli b/src/lsp/cobol_indent/indenter.mli index a2d1d10c0..05a0fbe70 100644 --- a/src/lsp/cobol_indent/indenter.mli +++ b/src/lsp/cobol_indent/indenter.mli @@ -12,7 +12,7 @@ (**************************************************************************) (*indent a range of file, with the user-defined or default indent_config*) -val indent_range' +val indent_range : dialect: Cobol_config.dialect -> source_format:Cobol_config.source_format_spec -> indent_config:string option diff --git a/src/lsp/cobol_lsp/lsp_request.ml b/src/lsp/cobol_lsp/lsp_request.ml index 52de0eb57..350f06519 100644 --- a/src/lsp/cobol_lsp/lsp_request.ml +++ b/src/lsp/cobol_lsp/lsp_request.ml @@ -178,7 +178,7 @@ let handle_range_formatting registry params = } in let newText = - Cobol_indent.indent_range' + Cobol_indent.indent_range ~dialect:(Cobol_config.dialect project.cobol_config) ~source_format:project.source_format ~indent_config:None @@ -203,7 +203,7 @@ let handle_formatting registry params = in try let newText = - Cobol_indent.indent_range' + Cobol_indent.indent_range ~dialect:(Cobol_config.dialect project.cobol_config) ~source_format:project.source_format ~indent_config:None diff --git a/src/lsp/superbol_free_lib/command_indent_file.ml b/src/lsp/superbol_free_lib/command_indent_file.ml index e1b144835..0ee37040b 100644 --- a/src/lsp/superbol_free_lib/command_indent_file.ml +++ b/src/lsp/superbol_free_lib/command_indent_file.ml @@ -17,11 +17,15 @@ open Cobol_indent open Common_args -let action { preproc_options = { source_format; _ } ; _ } ~indent_config - files = +let action { preproc_options = { source_format; config; _ } ; _ } + ~indent_config files = + let module Config = (val config) in List.to_seq files |> Seq.map (fun file -> - indent_file ~source_format ~file ~indent_config) + let contents = Ez_file.V1.EzFile.read_file file in + indent_range + ~source_format ~filename:file ~contents ~indent_config ~range:None + ~dialect:Config.dialect |> Fmt.pr "%s") let cmd = let files = ref [] in diff --git a/src/lsp/superbol_free_lib/command_indent_range.ml b/src/lsp/superbol_free_lib/command_indent_range.ml index 7d3d86871..d41bed4ff 100644 --- a/src/lsp/superbol_free_lib/command_indent_range.ml +++ b/src/lsp/superbol_free_lib/command_indent_range.ml @@ -20,8 +20,9 @@ open Common_args let action { preproc_options = { source_format; config; _ }; _ } ~file ~range ~indent_config = let module Config = (val config) in - indent_range ~source_format ~file ~range ~indent_config - ~dialect:Config.dialect + let contents = Ez_file.V1.EzFile.read_file file in + indent_range ~source_format ~filename:file ~contents ~range ~indent_config + ~dialect:Config.dialect |> Fmt.pr "%s" let cmd = let file = ref "" in From 754d377910ddd48cf016d789fc0681a8d98ee48d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Basile=20Cl=C3=A9ment?= Date: Thu, 26 Oct 2023 13:33:11 +0200 Subject: [PATCH 3/9] Only enable indenter on fixed format The indenter also now uses inferred formats properly. Fixes #52 --- src/lsp/cobol_indent/indent_type.ml | 1 + src/lsp/cobol_indent/indenter.ml | 39 +++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/lsp/cobol_indent/indent_type.ml b/src/lsp/cobol_indent/indent_type.ml index 897c42eb3..87d22439b 100644 --- a/src/lsp/cobol_indent/indent_type.ml +++ b/src/lsp/cobol_indent/indent_type.ml @@ -154,6 +154,7 @@ type context = (context_kind * int) list type indent_state = { + src_format: Cobol_preproc.Src_format.any; scope: context_kind; (*indicate where the current code is*) context: context; (*the stack of (context_kind, offset)*) acc: indent_record list; diff --git a/src/lsp/cobol_indent/indenter.ml b/src/lsp/cobol_indent/indenter.ml index b5311de88..25121ecba 100644 --- a/src/lsp/cobol_indent/indenter.ml +++ b/src/lsp/cobol_indent/indenter.ml @@ -27,14 +27,21 @@ let indenter ~source_format (str:string) (rdl:indent_record list) range = let str = List.nth strl (lnum - 1) in let newstr = match source_format with - | Cobol_config.SF SFFree -> + | Cobol_preproc.Src_format.SF (NoIndic, FreePaging) -> if offset > 0 then let space = String.make offset ' ' in space^str else String.sub str (-offset) (String.length str + offset) - (*TODO: must change if Auto <> SF SFFixed once*) - | SF SFFixed | Auto -> + | SF (FixedIndic, FixedWidth _) -> + (* Indenting temporarily disabled in fixed format + https://github.com/OCamlPro/superbol-studio-oss/issues/52 + + Support must be improved before enabling again, in particular to + avoid pushing content into the margin. + https://github.com/OCamlPro/superbol-studio-oss/issues/45 + *) + if true then str else let len = String.length str in let str1 = String.sub str 0 7 in let str = String.sub str 7 (len-7) in @@ -46,8 +53,11 @@ let indenter ~source_format (str:string) (rdl:indent_record list) range = String.sub str (-offset) (String.length str + offset) in str1^str - (*TODO*) - | _ -> str + (* TODO *) + | SF (XOpenIndic, FixedWidth _) -> str + | SF (CRTIndic, FixedWidth _) -> str + | SF (TrmIndic, FixedWidth _) -> str + | SF (CBLXIndic, FixedWidth _) -> str in List.mapi (fun i str -> if i = lnum - 1 then newstr else str) (strl) in @@ -63,16 +73,31 @@ let indenter ~source_format (str:string) (rdl:indent_record list) range = (*indent a range of file, with the default indent_config*) let indent_range ~dialect ~source_format ~range ~filename ~contents = + let src_format = + (* Note: this value doesn't actually matter, it will be overriden + immediately by [fold_source_lines] calling [on_initial_source_format] + below. *) + match source_format with + | Cobol_config.Auto -> Cobol_preproc.Src_format.from_config SFFixed + | SF source_format -> Cobol_preproc.Src_format.from_config source_format + in let state = Cobol_preproc.fold_source_lines ~dialect ~source_format + ~on_initial_source_format:(fun src_format st -> { st with src_format }) + ~on_compiler_directive:(fun _ { payload = cd; _} st -> + match cd with + | CDirSource { payload = src_format; _ } -> { st with src_format } + | _ -> st + ) ~skip_compiler_directives_text:true ~f:(fun _lnum line acc -> Indent_check.check_indentation line acc) (String { filename; contents }) - { scope = BEGIN; context = []; acc = []; range } + { src_format; scope = BEGIN; context = []; acc = []; range } in (* NB: note here we ignore diagnostics *) let ind_recds = state.result.acc in - indenter ~source_format contents ind_recds state.result.range + indenter + ~source_format:state.result.src_format contents ind_recds state.result.range (*indent a range of file, with the user-defined indent_config*) let indent_range ~dialect ~source_format ~indent_config ~range ~filename ~contents = From 80f447bf825d7e6202aab837f0493153effd42f0 Mon Sep 17 00:00:00 2001 From: Steven de Oliveira Date: Thu, 26 Oct 2023 14:48:58 +0200 Subject: [PATCH 4/9] Default option --- package.json | 2 +- src/lsp/superbol_free_lib/project.ml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index fc5736b2d..108a21736 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "description": "If something is selected, only format the selection" }, "superbol.path": { - "default": "", + "default": "superbol-free", "description": "Path to the `superbol` command" } } diff --git a/src/lsp/superbol_free_lib/project.ml b/src/lsp/superbol_free_lib/project.ml index e83a084ee..86c3b4de8 100644 --- a/src/lsp/superbol_free_lib/project.ml +++ b/src/lsp/superbol_free_lib/project.ml @@ -144,7 +144,7 @@ let contributes = "If something is selected, only format the selection" ; Manifest.PROPERTY.string "superbol.path" - ~default: "" + ~default:"superbol-free" ~description: "Path to the `superbol` command" ] ) ~taskDefinitions: [ From 42aba2df200a09bf03af1986f7d4a92046c4f85c Mon Sep 17 00:00:00 2001 From: Steven de Oliveira Date: Thu, 26 Oct 2023 17:15:42 +0200 Subject: [PATCH 5/9] sourceFormat as an enum --- package.json | 19 ++++++++++++++++++- src/lsp/superbol_free_lib/project.ml | 6 ++++-- src/vscode/vscode-json/manifest.ml | 7 +++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 108a21736..5c3b0a277 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,24 @@ "description": "The list of copybooks paths" }, "sourceFormat": { - "description": "The source format of the code" + "description": "The source format of the code", + "items": "string", + "enum": [ + "default", + "gnucobol", + "cobol85", + "cobol2002", + "cobol2014", + "acu", + "bs2000", + "gcos", + "ibm", + "mf", + "mvs", + "realia", + "rm", + "xopen" + ] }, "dialect": { "description": "The COBOL dialect used" diff --git a/src/lsp/superbol_free_lib/project.ml b/src/lsp/superbol_free_lib/project.ml index 86c3b4de8..f74a62a38 100644 --- a/src/lsp/superbol_free_lib/project.ml +++ b/src/lsp/superbol_free_lib/project.ml @@ -154,8 +154,10 @@ let contributes = Manifest.PROPERTY.array "copybooks" ~description:"The list of copybooks paths" ; - Manifest.PROPERTY.string "sourceFormat" - ~description: "The source format of the code" ; + Manifest.PROPERTY.enum "sourceFormat" + ~cases:Cobol_config.DIALECT.all_canonical_names + ~description: "The source format of the code" + ; Manifest.PROPERTY.string "dialect" ~description: "The COBOL dialect used" ; diff --git a/src/vscode/vscode-json/manifest.ml b/src/vscode/vscode-json/manifest.ml index 142d1dce3..1c88d601b 100644 --- a/src/vscode/vscode-json/manifest.ml +++ b/src/vscode/vscode-json/manifest.ml @@ -357,6 +357,13 @@ module PROPERTY = struct Some (`A (List.map (fun s -> `String s) strings))) ~items: (`String "string") + let enum ?default ~cases = + property + ~type_:(`String "string") + ~enum:cases + ?default + ~items:(`String "string") + end type configuration = { From 274f2859e3208d6c78f63ee7ce30db47ca082e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Basile=20Cl=C3=A9ment?= Date: Fri, 27 Oct 2023 09:29:58 +0200 Subject: [PATCH 6/9] Address review comments --- src/lsp/cobol_indent/indenter.ml | 12 ++++------ test/lsp/lsp_formatting.ml | 39 ++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/lsp/cobol_indent/indenter.ml b/src/lsp/cobol_indent/indenter.ml index 25121ecba..2d00f8005 100644 --- a/src/lsp/cobol_indent/indenter.ml +++ b/src/lsp/cobol_indent/indenter.ml @@ -73,14 +73,10 @@ let indenter ~source_format (str:string) (rdl:indent_record list) range = (*indent a range of file, with the default indent_config*) let indent_range ~dialect ~source_format ~range ~filename ~contents = - let src_format = - (* Note: this value doesn't actually matter, it will be overriden - immediately by [fold_source_lines] calling [on_initial_source_format] - below. *) - match source_format with - | Cobol_config.Auto -> Cobol_preproc.Src_format.from_config SFFixed - | SF source_format -> Cobol_preproc.Src_format.from_config source_format - in + (* Note: this value doesn't actually matter, it will be overriden + immediately by [fold_source_lines] calling [on_initial_source_format] + below. *) + let src_format = Cobol_preproc.Src_format.from_config SFFixed in let state = Cobol_preproc.fold_source_lines ~dialect ~source_format ~on_initial_source_format:(fun src_format st -> { st with src_format }) diff --git a/test/lsp/lsp_formatting.ml b/test/lsp/lsp_formatting.ml index 5d71676b2..878f56637 100644 --- a/test/lsp/lsp_formatting.ml +++ b/test/lsp/lsp_formatting.ml @@ -23,7 +23,9 @@ let doc = {cobol| |cobol};; let%expect_test "simple-formatting-request" = - let { projdir; end_with_postproc }, server = make_lsp_project () in + let { projdir; end_with_postproc }, server = + make_lsp_project ~toml:"source-format = \"free\"\n" () + in let server, prog = add_cobol_doc server ~projdir "prog.cob" doc in let params = let options = FormattingOptions.create ~insertSpaces:true ~tabSize:2 () in @@ -58,7 +60,9 @@ let doc = {cobol| move 1 to x. |cobol};; let%expect_test "formatting-request-nested-if" = - let { projdir; end_with_postproc }, server = make_lsp_project () in + let { projdir; end_with_postproc }, server = + make_lsp_project ~toml:"source-format = \"free\"\n" () + in let server, prog = add_cobol_doc server ~projdir "prog.cob" doc in let params = let options = FormattingOptions.create ~insertSpaces:true ~tabSize:2 () in @@ -100,7 +104,9 @@ let doc = {cobol| value 999. |cobol};; let%expect_test "formatting-request-data" = - let { projdir; end_with_postproc }, server = make_lsp_project () in + let { projdir; end_with_postproc }, server = + make_lsp_project ~toml:"source-format = \"free\"\n" () + in let server, prog = add_cobol_doc server ~projdir "prog.cob" doc in let params = let options = FormattingOptions.create ~insertSpaces:true ~tabSize:2 () in @@ -173,7 +179,9 @@ let doc = {cobol| |cobol};; let%expect_test "formatting-request-nested-program" = - let { projdir; end_with_postproc }, server = make_lsp_project () in + let { projdir; end_with_postproc }, server = + make_lsp_project ~toml:"source-format = \"free\"\n" () + in let server, prog = add_cobol_doc server ~projdir "prog.cob" doc in let params = let options = FormattingOptions.create ~insertSpaces:true ~tabSize:2 () in @@ -231,7 +239,9 @@ let doc = {cobol| |cobol};; let%expect_test "formatting-request-alignment-argument" = - let { projdir; end_with_postproc }, server = make_lsp_project () in + let { projdir; end_with_postproc }, server = + make_lsp_project ~toml:"source-format = \"free\"\n" () + in let server, prog = add_cobol_doc server ~projdir "prog.cob" doc in let params = let options = FormattingOptions.create ~insertSpaces:true ~tabSize:2 () in @@ -263,7 +273,9 @@ let doc = {cobol| |cobol};; let%expect_test "formatting-request-else-if" = - let { projdir; end_with_postproc }, server = make_lsp_project () in + let { projdir; end_with_postproc }, server = + make_lsp_project ~toml:"source-format = \"free\"\n" () + in let server, prog = add_cobol_doc server ~projdir "prog.cob" doc in let params = let options = FormattingOptions.create ~insertSpaces:true ~tabSize:2 () in @@ -381,7 +393,9 @@ let doc = {cobol| |cobol};; let%expect_test "formatting-request-whole-program" = - let { projdir; end_with_postproc }, server = make_lsp_project () in + let { projdir; end_with_postproc }, server = + make_lsp_project ~toml:"source-format = \"free\"\n" () + in let server, prog = add_cobol_doc server ~projdir "prog.cob" doc in let params = let options = FormattingOptions.create ~insertSpaces:true ~tabSize:2 () in @@ -401,9 +415,6 @@ let%expect_test "formatting-request-whole-program" = data_sections_visitor.ml:0: (Cobol_ptree__Data_sections_visitor.fold_file_section): missing visitor implementation - data_sections_visitor.ml:0: - (Cobol_ptree__Data_sections_visitor.fold_data_clause): partial visitor - implementation {"params":{"diagnostics":[],"uri":"file://__rootdir__/prog.cob"},"method":"textDocument/publishDiagnostics","jsonrpc":"2.0"} IDENTIFICATION DIVISION. PROGRAM-ID. MACESDS. @@ -507,7 +518,9 @@ let doc = {cobol| |cobol};; let%expect_test "formatting-request-on-exception" = - let { projdir; end_with_postproc }, server = make_lsp_project () in + let { projdir; end_with_postproc }, server = + make_lsp_project ~toml:"source-format = \"free\"\n" () + in let server, prog = add_cobol_doc server ~projdir "prog.cob" doc in let params = let options = FormattingOptions.create ~insertSpaces:true ~tabSize:2 () in @@ -542,7 +555,9 @@ let doc = {cobol| |cobol};; let%expect_test "formatting-request-perform" = - let { projdir; end_with_postproc }, server = make_lsp_project () in + let { projdir; end_with_postproc }, server = + make_lsp_project ~toml:"source-format = \"free\"\n" () + in let server, prog = add_cobol_doc server ~projdir "prog.cob" doc in let params = let options = FormattingOptions.create ~insertSpaces:true ~tabSize:2 () in From c119853486b71fd73db88a150cf7654a14ce5996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Basile=20Cl=C3=A9ment?= Date: Fri, 27 Oct 2023 11:13:59 +0200 Subject: [PATCH 7/9] Revert --- test/lsp/lsp_formatting.ml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/lsp/lsp_formatting.ml b/test/lsp/lsp_formatting.ml index 878f56637..e3aebe91b 100644 --- a/test/lsp/lsp_formatting.ml +++ b/test/lsp/lsp_formatting.ml @@ -415,6 +415,9 @@ let%expect_test "formatting-request-whole-program" = data_sections_visitor.ml:0: (Cobol_ptree__Data_sections_visitor.fold_file_section): missing visitor implementation + data_sections_visitor.ml:0: + (Cobol_ptree__Data_sections_visitor.fold_data_clause): partial visitor + implementation {"params":{"diagnostics":[],"uri":"file://__rootdir__/prog.cob"},"method":"textDocument/publishDiagnostics","jsonrpc":"2.0"} IDENTIFICATION DIVISION. PROGRAM-ID. MACESDS. From dca5862f5bb5b1eef63e3d7044c041e149a699df Mon Sep 17 00:00:00 2001 From: Steven de Oliveira Date: Fri, 27 Oct 2023 10:38:15 +0200 Subject: [PATCH 8/9] Problem patterns and matchers --- package.json | 68 ++++++++++++++++++++++++++++ src/lsp/superbol_free_lib/project.ml | 60 ++++++++++++++++++++++++ 2 files changed, 128 insertions(+) diff --git a/package.json b/package.json index 5c3b0a277..c90d1825d 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,74 @@ ] } ], + "problemMatchers": [ + { + "name": "gnucobol", + "owner": "cobol", + "fileLocation": "absolute", + "pattern": "$gnucobol", + "source": "GnuCOBOL" + }, + { + "name": "gnucobol-warning", + "owner": "cobol", + "fileLocation": "absolute", + "pattern": "$gnucobol-warning", + "source": "GnuCOBOL", + "severity": "warning" + }, + { + "name": "gnucobol-error", + "owner": "cobol", + "fileLocation": "absolute", + "pattern": "$gnucobol-error", + "source": "GnuCOBOL", + "severity": "error" + }, + { + "name": "gnucobol-note", + "owner": "cobol", + "fileLocation": "absolute", + "pattern": "$gnucobol-note", + "source": "GnuCOBOL", + "severity": "info" + } + ], + "problemPatterns": [ + { + "name": "gnucobol", + "regexp": "^(.*): ?(\\d+): (error|warning): ([^[]*)(\\[(.*)\\])?$", + "file": 1, + "line": 2, + "severity": 3, + "code": 6, + "message": 4 + }, + { + "name": "gnucobol-warning", + "regexp": "^(.*):(\\d+):\\s?(warning|Warnung|[wW]aarschuwing|[aA]lerta|avertissement|упозорење)\\s?:([^[]*)(\\[(.*)\\])?$", + "file": 1, + "line": 2, + "code": 6, + "message": 4 + }, + { + "name": "gnucobol-error", + "regexp": "^(.*): ?(\\d+):\\s?(error|Fehler|[fF]out|[eE]rrores|[eE]rrores|erreur|грешка)\\s?:\\s?([^[]*)(\\[(.*)\\])?$", + "file": 1, + "line": 2, + "code": 6, + "message": 4 + }, + { + "name": "gnucobol-note", + "regexp": "^(.*): ?(\\d+): (note|Anmerkung|[nN]ota): ([^[]*)(\\[(.*)\\])?$", + "file": 1, + "line": 2, + "code": 6, + "message": 4 + } + ], "taskDefinitions": [ { "type": "superbol", diff --git a/src/lsp/superbol_free_lib/project.ml b/src/lsp/superbol_free_lib/project.ml index f74a62a38..c28f79244 100644 --- a/src/lsp/superbol_free_lib/project.ml +++ b/src/lsp/superbol_free_lib/project.ml @@ -169,6 +169,66 @@ let contributes = ~description: "Add cobol file extensions" ] ] + ~problemPatterns:[ + Manifest.problemPattern + (Some "^(.*): ?(\\d+): (error|warning): ([^[]*)(\\[(.*)\\])?$") + ~name:"gnucobol" + ~file:1 + ~line:2 + ~severity:3 + ~message:4 + ~code:6; + Manifest.problemPattern + (Some "^(.*):(\\d+):\\s?(warning|Warnung|[wW]aarschuwing|[aA]lerta|avertissement|упозорење)\\s?:([^[]*)(\\[(.*)\\])?$") + ~name:"gnucobol-warning" + ~file:1 + ~line:2 + ~message:4 + ~code:6; + Manifest.problemPattern + (Some "^(.*): ?(\\d+):\\s?(error|Fehler|[fF]out|[eE]rrores|[eE]rrores|erreur|грешка)\\s?:\\s?([^[]*)(\\[(.*)\\])?$") + ~name:"gnucobol-error" + ~file:1 + ~line:2 + ~message:4 + ~code:6; + Manifest.problemPattern + (Some "^(.*): ?(\\d+): (note|Anmerkung|[nN]ota): ([^[]*)(\\[(.*)\\])?$") + ~name:"gnucobol-note" + ~file:1 + ~line:2 + ~message:4 + ~code:6; + ] + ~problemMatchers:[ + Manifest.problemMatcher () + ~name:"gnucobol" + ~owner:"cobol" + ~fileLocation:["absolute"] + ~pattern:[Manifest.ProblemName "$gnucobol"] + ~source:"GnuCOBOL"; + Manifest.problemMatcher () + ~name:"gnucobol-warning" + ~owner:"cobol" + ~fileLocation:["absolute"] + ~pattern:[Manifest.ProblemName "$gnucobol-warning"] + ~severity:"warning" + ~source:"GnuCOBOL"; + Manifest.problemMatcher () + ~name:"gnucobol-error" + ~owner:"cobol" + ~fileLocation:["absolute"] + ~pattern:[Manifest.ProblemName "$gnucobol-error"] + ~severity:"error" + ~source:"GnuCOBOL"; + Manifest.problemMatcher () + ~name:"gnucobol-note" + ~owner:"cobol" + ~fileLocation:["absolute"] + ~pattern:[Manifest.ProblemName "$gnucobol-note"] + ~severity:"info" + ~source:"GnuCOBOL"; + ] let manifest = Manifest.vscode From f5fb619fa6efb97790d74a1e0e7f104372fec9ab Mon Sep 17 00:00:00 2001 From: Steven de Oliveira Date: Fri, 27 Oct 2023 10:44:48 +0200 Subject: [PATCH 9/9] Task definitions --- .../superbol-vscode-platform/superbol_tasks.ml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/vscode/superbol-vscode-platform/superbol_tasks.ml b/src/vscode/superbol-vscode-platform/superbol_tasks.ml index 3ebd6dce4..58b9470e8 100644 --- a/src/vscode/superbol-vscode-platform/superbol_tasks.ml +++ b/src/vscode/superbol-vscode-platform/superbol_tasks.ml @@ -69,6 +69,12 @@ let provide_tasks ~token:_ = ~name:"Build file" ~source:"superbol" ~execution:(execution "cobc") + ~problemMatchers:[ + "$gnucobol"; + "$gnucobol-warning"; + "$gnucobol-error"; + "$gnucobol-note"; + ] in let build_debug_task = Task.make () ~definition:definition_debug @@ -76,6 +82,12 @@ let provide_tasks ~token:_ = ~name:"Build file for debug" ~source:"superbol" ~execution:(execution "cobcd") + ~problemMatchers:[ + "$gnucobol"; + "$gnucobol-warning"; + "$gnucobol-error"; + "$gnucobol-note"; + ] in `Value (Some [build_task; build_debug_task])