From 5160068c00c2ea3471945e5ad1ccbadfb7f1d815 Mon Sep 17 00:00:00 2001 From: Fabrice Le Fessant Date: Thu, 1 Feb 2024 15:34:29 +0100 Subject: [PATCH] Remove cobol_indent/cobol_indent.ml --- src/lsp/cobol_indent/cobol_indent.ml | 26 ------------------- src/lsp/cobol_indent/indent_check.ml | 2 +- src/lsp/cobol_indent/indent_check.mli | 4 +-- src/lsp/cobol_indent/indent_config.ml | 2 +- src/lsp/cobol_indent/indent_config.mli | 4 +-- src/lsp/cobol_indent/indent_keywords.ml | 2 +- src/lsp/cobol_indent/indent_keywords.mli | 10 +++---- .../{indenter.ml => indent_main.ml} | 11 +++++++- .../{indenter.mli => indent_main.mli} | 14 ++++++++-- src/lsp/cobol_indent/indent_util.ml | 2 +- src/lsp/cobol_indent/indent_util.mli | 2 +- .../cobol_indent/{indent_type.ml => types.ml} | 0 src/lsp/cobol_lsp/lsp_request.ml | 12 ++++----- .../superbol_free_lib/command_indent_file.ml | 5 ++-- .../superbol_free_lib/command_indent_range.ml | 7 +++-- 15 files changed, 47 insertions(+), 56 deletions(-) delete mode 100644 src/lsp/cobol_indent/cobol_indent.ml rename src/lsp/cobol_indent/{indenter.ml => indent_main.ml} (88%) rename src/lsp/cobol_indent/{indenter.mli => indent_main.mli} (76%) rename src/lsp/cobol_indent/{indent_type.ml => types.ml} (100%) diff --git a/src/lsp/cobol_indent/cobol_indent.ml b/src/lsp/cobol_indent/cobol_indent.ml deleted file mode 100644 index ac10c228b..000000000 --- a/src/lsp/cobol_indent/cobol_indent.ml +++ /dev/null @@ -1,26 +0,0 @@ -(**************************************************************************) -(* *) -(* SuperBOL OSS Studio *) -(* *) -(* Copyright (c) 2022-2023 OCamlPro SAS *) -(* *) -(* All rights reserved. *) -(* This source code is licensed under the GNU Affero General Public *) -(* License version 3 found in the LICENSE.md file in the root directory *) -(* of this source tree. *) -(* *) -(**************************************************************************) - -module Type = Indent_type - -(*return the result of indentation. use user-defined indent_config*) -let indent_range = Indenter.indent_range - -let indent_range_str - ~dialect ~source_format ~indent_config ~range ~filename ~contents -= - indent_range - ~dialect ~source_format ~indent_config ~range ~filename ~contents - |> Indent_util.apply contents - -let config l = Indent_config.(merge default (of_list l)) diff --git a/src/lsp/cobol_indent/indent_check.ml b/src/lsp/cobol_indent/indent_check.ml index dfb2e6369..fde7dc73d 100644 --- a/src/lsp/cobol_indent/indent_check.ml +++ b/src/lsp/cobol_indent/indent_check.ml @@ -15,7 +15,7 @@ open EzCompat open Cobol_common.Srcloc -open Indent_type +open Types open Indent_keywords open Indent_util diff --git a/src/lsp/cobol_indent/indent_check.mli b/src/lsp/cobol_indent/indent_check.mli index e5f3b9508..5040f6d2c 100644 --- a/src/lsp/cobol_indent/indent_check.mli +++ b/src/lsp/cobol_indent/indent_check.mli @@ -13,5 +13,5 @@ val check_indentation :Cobol_preproc.Text.t - -> Indent_type.indent_state - -> Indent_type.indent_state + -> Types.indent_state + -> Types.indent_state diff --git a/src/lsp/cobol_indent/indent_config.ml b/src/lsp/cobol_indent/indent_config.ml index 6dee117ab..3124f5f63 100644 --- a/src/lsp/cobol_indent/indent_config.ml +++ b/src/lsp/cobol_indent/indent_config.ml @@ -11,7 +11,7 @@ (* *) (**************************************************************************) -open Indent_type +open Types open Indent_keywords type t = indent_config diff --git a/src/lsp/cobol_indent/indent_config.mli b/src/lsp/cobol_indent/indent_config.mli index cbb20b7e3..02890c775 100644 --- a/src/lsp/cobol_indent/indent_config.mli +++ b/src/lsp/cobol_indent/indent_config.mli @@ -11,7 +11,7 @@ (* *) (**************************************************************************) -type t = Indent_type.indent_config +type t = Types.indent_config val default : t @@ -20,4 +20,4 @@ val merge : t -> t -> t val of_list : (string * int) list -> t -val offset_of_keyword: t -> Indent_type.context_kind -> int +val offset_of_keyword: t -> Types.context_kind -> int diff --git a/src/lsp/cobol_indent/indent_keywords.ml b/src/lsp/cobol_indent/indent_keywords.ml index b8ff03ea7..f078a0a9e 100644 --- a/src/lsp/cobol_indent/indent_keywords.ml +++ b/src/lsp/cobol_indent/indent_keywords.ml @@ -18,7 +18,7 @@ TODO: use the aforementioned associations instead of redefining them below. *) -open Indent_type +open Types (*data division *) let data_context_of_str : string -> data_context = function diff --git a/src/lsp/cobol_indent/indent_keywords.mli b/src/lsp/cobol_indent/indent_keywords.mli index 17bdfb8fd..54c0d17c5 100644 --- a/src/lsp/cobol_indent/indent_keywords.mli +++ b/src/lsp/cobol_indent/indent_keywords.mli @@ -11,17 +11,17 @@ (* *) (**************************************************************************) -val string_of_keyword: Indent_type.context_kind -> string +val string_of_keyword: Types.context_kind -> string -val data_context_of_str: string -> Indent_type.data_context +val data_context_of_str: string -> Types.data_context -val proc_context_of_str: string -> Indent_type.proc_context +val proc_context_of_str: string -> Types.proc_context (* To check whether the string is a keyword of statement *) val is_statement: string -> bool (* To check whether the keyword is implicitly terminable *) -val is_not_imp_terminable: Indent_type.context_kind -> bool +val is_not_imp_terminable: Types.context_kind -> bool (* To check whether the keyword is a keyword of phrase *) -val is_phrase: Indent_type.context_kind -> bool +val is_phrase: Types.context_kind -> bool diff --git a/src/lsp/cobol_indent/indenter.ml b/src/lsp/cobol_indent/indent_main.ml similarity index 88% rename from src/lsp/cobol_indent/indenter.ml rename to src/lsp/cobol_indent/indent_main.ml index 8ff9ac072..1d9ec39ed 100644 --- a/src/lsp/cobol_indent/indenter.ml +++ b/src/lsp/cobol_indent/indent_main.ml @@ -11,7 +11,7 @@ (* *) (**************************************************************************) -open Indent_type +open Types (*indent a range of file, with the default indent_config*) let indent_range ~dialect ~source_format ~indent_config ~range ~filename ~contents = @@ -42,3 +42,12 @@ let indent_range ~dialect ~source_format ~indent_config ~range ~filename ~conten in (* NB: note here we ignore diagnostics *) state.result.acc + +let indent_range_str + ~dialect ~source_format ~indent_config ~range ~filename ~contents += + indent_range + ~dialect ~source_format ~indent_config ~range ~filename ~contents + |> Indent_util.apply contents + +let config l = Indent_config.(merge default (of_list l)) diff --git a/src/lsp/cobol_indent/indenter.mli b/src/lsp/cobol_indent/indent_main.mli similarity index 76% rename from src/lsp/cobol_indent/indenter.mli rename to src/lsp/cobol_indent/indent_main.mli index 784e4dfa9..29068b070 100644 --- a/src/lsp/cobol_indent/indenter.mli +++ b/src/lsp/cobol_indent/indent_main.mli @@ -16,7 +16,17 @@ val indent_range : dialect: Cobol_config.Types.dialect -> source_format:Cobol_config.Types.source_format_spec -> indent_config:Indent_config.t option - -> range:Indent_type.range option + -> range:Types.range option -> filename:string -> contents:string - -> Indent_type.indent_record list + -> Types.indent_record list + + +val indent_range_str : + dialect:Cobol_config.Types.dialect -> + source_format:Cobol_config.Types.source_format_spec -> + indent_config:Types.indent_config option -> + range:Types.range option -> + filename:string -> contents:string -> string + +val config : (string * int) list -> Types.indent_config diff --git a/src/lsp/cobol_indent/indent_util.ml b/src/lsp/cobol_indent/indent_util.ml index a458b4cf7..44620be05 100644 --- a/src/lsp/cobol_indent/indent_util.ml +++ b/src/lsp/cobol_indent/indent_util.ml @@ -13,7 +13,7 @@ open Cobol_common.Srcloc -open Indent_type +open Types open Indent_keywords let check_pos diff --git a/src/lsp/cobol_indent/indent_util.mli b/src/lsp/cobol_indent/indent_util.mli index bc5552092..27f780a18 100644 --- a/src/lsp/cobol_indent/indent_util.mli +++ b/src/lsp/cobol_indent/indent_util.mli @@ -11,7 +11,7 @@ (* *) (**************************************************************************) -open Indent_type +open Types val check_pos: Cobol_preproc.Src_format.any -> diff --git a/src/lsp/cobol_indent/indent_type.ml b/src/lsp/cobol_indent/types.ml similarity index 100% rename from src/lsp/cobol_indent/indent_type.ml rename to src/lsp/cobol_indent/types.ml diff --git a/src/lsp/cobol_lsp/lsp_request.ml b/src/lsp/cobol_lsp/lsp_request.ml index fd30c99a1..b4750f9de 100644 --- a/src/lsp/cobol_lsp/lsp_request.ml +++ b/src/lsp/cobol_lsp/lsp_request.ml @@ -224,7 +224,7 @@ let handle_references state (params: ReferenceParams.t) = (** {3 Formatting} *) -let lsp_text_edit Cobol_indent.Type.{ lnum; offset_orig; offset_modif } = +let lsp_text_edit Cobol_indent.Types.{ lnum; offset_orig; offset_modif } = let delta = offset_modif - offset_orig in let position = Position.create ~line:(lnum - 1) ~character:offset_orig in let range = Range.create ~start:position ~end_:position in @@ -250,16 +250,16 @@ let handle_range_formatting registry params = Lsp_server.find_document doc registry in let range_to_indent = - Cobol_indent.Type.{ + Cobol_indent.Types.{ start_line = start.line + 1; end_line = end_.line + 1 } in let edit_list = - Cobol_indent.indent_range + Cobol_indent.Indent_main.indent_range ~dialect:(Cobol_config.Config.dialect project.config.cobol_config) ~source_format:project.config.source_format - ~indent_config:(Some (Cobol_indent.config project.config.indent_config)) + ~indent_config:(Some (Cobol_indent.Indent_main.config project.config.indent_config)) ~filename:(Lsp.Uri.to_path doc.uri) ~contents:(Lsp.Text_document.text textdoc) ~range:(Some range_to_indent) @@ -272,10 +272,10 @@ let handle_formatting registry params = Lsp_server.find_document doc registry in try let editList = - Cobol_indent.indent_range + Cobol_indent.Indent_main.indent_range ~dialect:(Cobol_config.Config.dialect project.config.cobol_config) ~source_format:project.config.source_format - ~indent_config:(Some (Cobol_indent.config project.config.indent_config)) + ~indent_config:(Some (Cobol_indent.Indent_main.config project.config.indent_config)) ~filename:(Lsp.Uri.to_path doc.uri) ~contents:(Lsp.Text_document.text textdoc) ~range:None diff --git a/src/lsp/superbol_free_lib/command_indent_file.ml b/src/lsp/superbol_free_lib/command_indent_file.ml index c6785027e..20ccdb176 100644 --- a/src/lsp/superbol_free_lib/command_indent_file.ml +++ b/src/lsp/superbol_free_lib/command_indent_file.ml @@ -13,7 +13,6 @@ open Ezcmd.V2 open EZCMD.TYPES -open Cobol_indent open Common_args @@ -23,9 +22,9 @@ let action { preproc_options = { source_format; config; _ } ; _ } files = |> Seq.map (fun filename -> let project = Project.for_ ~filename in let contents = Ez_file.V1.EzFile.read_file filename in - indent_range_str + Cobol_indent.Indent_main.indent_range_str ~source_format ~filename ~contents ~range:None - ~indent_config:(Some (Cobol_indent.config project.config.indent_config)) + ~indent_config:(Some (Cobol_indent.Indent_main.config project.config.indent_config)) ~dialect:Config.dialect |> Fmt.pr "%s") let cmd = diff --git a/src/lsp/superbol_free_lib/command_indent_range.ml b/src/lsp/superbol_free_lib/command_indent_range.ml index caeb2b076..78e2bea5f 100644 --- a/src/lsp/superbol_free_lib/command_indent_range.ml +++ b/src/lsp/superbol_free_lib/command_indent_range.ml @@ -13,7 +13,6 @@ open Ezcmd.V2 open EZCMD.TYPES -open Cobol_indent open Common_args @@ -22,9 +21,9 @@ let action = let module Config = (val config) in let project = Project.for_ ~filename in - let indent_config = Some (Cobol_indent.config project.config.indent_config) in + let indent_config = Some (Cobol_indent.Indent_main.config project.config.indent_config) in let contents = Ez_file.V1.EzFile.read_file filename in - indent_range_str ~source_format ~filename ~contents ~range ~indent_config + Cobol_indent.Indent_main.indent_range_str ~source_format ~filename ~contents ~range ~indent_config ~dialect:Config.dialect |> Fmt.pr "%s" let cmd = @@ -39,7 +38,7 @@ let cmd = let common, common_args = Common_args.get () in let args = direct_args @ common_args in let range start_line end_line = - let open Cobol_indent.Type in + let open Cobol_indent.Types in let start_line = !start_line |> Int32.of_string |> Int32.to_int in let end_line = !end_line |> Int32.of_string |> Int32.to_int in Some {start_line; end_line}