Skip to content

Commit

Permalink
Remove cobol_lsp/cobol_lsp.ml
Browse files Browse the repository at this point in the history
  • Loading branch information
lefessan committed Feb 1, 2024
1 parent 7acdf52 commit 0458349
Show file tree
Hide file tree
Showing 30 changed files with 181 additions and 204 deletions.
36 changes: 7 additions & 29 deletions src/lsp/cobol_lsp/cobol_lsp.ml → src/lsp/cobol_lsp/alltypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,10 @@
(* *)
(**************************************************************************)

include Lsp_server_loop

(* --- *)

(** {1 Modules and functions exported for testing purposes}
Signatures of modules below may change unexpectedly. *)

module INTERNAL = struct
module Types = struct
include Lsp_imports
include Lsp_diagnostics.TYPES
include Lsp_lookup.TYPES
include Lsp_document.TYPES
include Lsp_project.TYPES
include Lsp_project_cache.TYPES
include Lsp_server.TYPES
end
module Diagnostics = Lsp_diagnostics
module Lookup = Lsp_lookup
module Project = Lsp_project
module Project_cache = Lsp_project_cache
module Document = Lsp_document
module Server = Lsp_server
module Loop = Lsp_server_loop
module Request = Lsp_request.INTERNAL
module Utils = Lsp_utils
module Debug = Lsp_debug
end
include Lsp_imports
include Diagnostics.TYPES
include Lookup.TYPES
include Document.TYPES
include Project.TYPES
include Project_cache.TYPES
include Server.TYPES
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ let translate_one ~rootdir ~uri (diag: DIAG.t) =
let uri, range =
match Option.map project_srcloc (DIAG.location diag) with
| Some (Lexing.{ pos_fname = f; _ }, _ as lexloc) ->
pseudo_normalized_uri ~rootdir f, Lsp_position.range_of_lexloc lexloc
pseudo_normalized_uri ~rootdir f, Position.range_of_lexloc lexloc
| None ->
uri, Lsp_position.pointwise_range_at_start
uri, Position.pointwise_range_at_start
in
let diag =
Lsp.Types.Diagnostic.create ()
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
(* *)
(**************************************************************************)

open Lsp_project.TYPES
open Project.TYPES
open Ez_file.V1

module DIAGS = Cobol_common.Diagnostics
Expand All @@ -20,7 +20,7 @@ module TYPES = struct

type document =
{
project: Lsp_project.t;
project: Project.t;
textdoc: Lsp.Text_document.t;
copybook: bool;
artifacts: Cobol_parser.Outputs.artifacts;
Expand Down Expand Up @@ -75,7 +75,7 @@ let rewindable_parse ({ project; textdoc; _ } as doc) =
Cobol_preproc.Preprocess.preprocessor
~options:Cobol_preproc.Options.{
default with
libpath = Lsp_project.libpath_for ~uri:(uri doc) project;
libpath = Project.libpath_for ~uri:(uri doc) project;
config = project.config.cobol_config;
source_format = project.config.source_format
} @@
Expand Down Expand Up @@ -123,7 +123,7 @@ let reparse_and_analyze ?position ({ copybook; rewinder; textdoc; _ } as doc) =
let blank ~project ?copybook textdoc =
let copybook = match copybook with
| Some p -> p
| None -> Lsp_project.detect_copybook project
| None -> Project.detect_copybook project
~uri:(Lsp.Text_document.documentUri textdoc)
in
{
Expand Down Expand Up @@ -180,7 +180,7 @@ let to_cache ({ project; textdoc; checked; diags;
artifacts = { pplog; tokens;
rev_comments; rev_ignored; _ }; _ } as doc) =
{
doc_cache_filename = Lsp_project.relative_path_for ~uri:(uri doc) project;
doc_cache_filename = Project.relative_path_for ~uri:(uri doc) project;
doc_cache_checksum = Digest.string (Lsp.Text_document.text textdoc);
doc_cache_langid = Lsp.Text_document.languageId textdoc;
doc_cache_version = Lsp.Text_document.version textdoc;
Expand All @@ -206,7 +206,7 @@ let of_cache ~project
doc_cache_ignored = rev_ignored;
doc_cache_checked = checked;
doc_cache_diags = diags } =
let absolute_filename = Lsp_project.absolute_path_for ~filename project in
let absolute_filename = Project.absolute_path_for ~filename project in
if checksum <> Digest.file absolute_filename then
failwith "Bad checksum"
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ let rec qualname_at_pos ~filename (qn: Cobol_ptree.Types.qualname) pos =
| Qual (name, qn') ->
try
let lexloc = lexloc_of_qualname_in ~filename qn in
if not (Lsp_position.is_after_lexloc pos lexloc) &&
not (Lsp_position.is_in_srcloc ~filename pos ~@name)
if not (Position.is_after_lexloc pos lexloc) &&
not (Position.is_in_srcloc ~filename pos ~@name)
then qualname_at_pos ~filename qn' pos
else qn
with Invalid_argument _ -> qn (* dummy loc *)
Expand Down Expand Up @@ -151,7 +151,7 @@ let element_at_position ~uri pos group : element_at_position =

Cobol_unit.Visitor.fold_unit_group object
inherit [acc] Cobol_unit.Visitor.folder
inherit! [acc] Lsp_position.sieve ~filename ~pos
inherit! [acc] Position.sieve ~filename ~pos

method! fold_cobol_unit' cu ({ elt; _ } as acc) =
let name = ~&(~&cu.unit_name) in
Expand Down Expand Up @@ -197,7 +197,7 @@ let copy_at_pos ~filename pos ptree =
| None ->
match Cobol_common.Srcloc.as_copy loc with
| Some { loc; _ } as copy
when Lsp_position.is_in_srcloc ~filename pos loc ->
when Position.is_in_srcloc ~filename pos loc ->
Visitor.skip_children copy
| _ ->
Visitor.do_children None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ open Ez_file.V1.EzFile.OP
[project_layout] does not provide a per-project storage directory ({i i.e,}
[project_layout.relative_work_dirname = None]). *)
let config
~(project_layout: Lsp_project.layout)
~(project_layout: Project.layout)
?(enable_caching = true)
?(fallback_storage_directory: string option)
() =
let cache_storage: Lsp_project_cache.storage =
let cache_storage: Project_cache.storage =
match project_layout.relative_work_dirname, fallback_storage_directory with
| _ when not enable_caching ->
No_storage
Expand All @@ -57,7 +57,7 @@ let config
relative_filename = relative_work_dirname // "lsp-cache";
}
in
Lsp_server.{
Server.{
cache_config = {
cache_storage;
cache_verbose = true;
Expand All @@ -76,14 +76,14 @@ let run ~config =
| Jsonrpc.Packet.Notification n ->
continue @@ Lsp_notif.handle n state
| Jsonrpc.Packet.Request r ->
continue @@ reply @@ Lsp_request.handle r state
continue @@ reply @@ Request.handle r state
| Jsonrpc.Packet.Batch_call calls ->
batch calls state
| Jsonrpc.Packet.Response _ | Batch_response _ ->
Pretty.error "Response@ recieved@ unexpectedly@.";
continue state
| exception End_of_file ->
Lsp_request.shutdown state;
Request.shutdown state;
Error "Premature end of input stream" (* exit loop *)
| exception Lsp_io.Parse_error msg ->
Lsp_io.pretty_notification ~type_:Error "%s" msg;
Expand All @@ -95,12 +95,12 @@ let run ~config =
| `Notification n :: calls' ->
batch calls' @@ Lsp_notif.handle n state
| `Request n :: calls' ->
batch calls' @@ reply @@ Lsp_request.handle n state
batch calls' @@ reply @@ Request.handle n state
and reply (state, response) =
Lsp_io.send_response response;
state
and continue = function
| Lsp_server.Exit code -> code (* exit loop *)
| Server.Exit code -> code (* exit loop *)
| state -> loop state
in
loop (NotInitialized config)
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ val config
-> ?enable_caching: bool
-> ?fallback_storage_directory: string
-> unit
-> Lsp_server.config
-> Server.config

val run
: config: Lsp_server.config
-> Lsp_server.exit_status
: config: Server.config
-> Server.exit_status
19 changes: 10 additions & 9 deletions src/lsp/cobol_lsp/lsp_completion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ open Cobol_common (* Visitor *)
open Cobol_common.Srcloc.INFIX

open Lsp_completion_keywords
open Lsp.Types

module POSITION = Lsp.Types.Position

let name_proposals ast ~filename pos =
let visitor = object
inherit [StringSet.t] Cobol_ptree.Visitor.folder

method! fold_compilation_unit' cu =
if Lsp_position.is_in_srcloc ~filename pos ~@cu
if Position.is_in_srcloc ~filename pos ~@cu
then Visitor.do_children
else Visitor.skip_children

Expand Down Expand Up @@ -56,13 +57,13 @@ let keyword_proposals ast pos =
method! fold_data_division' {loc; _} _ =
Visitor.skip_children @@
if Lsp_position.is_in_srcloc pos loc
if Position.is_in_srcloc pos loc
then Some Data_div
else None
method! fold_procedure_division' {loc; _} _ =
Visitor.skip_children @@
if Lsp_position.is_in_srcloc pos loc
if Position.is_in_srcloc pos loc
then Some Proc_div
else None
Expand All @@ -75,26 +76,26 @@ let keyword_proposals ast pos =

let keyword_proposals _ast _pos = keywords_all

let completion_items text (pos:Position.t) ast =
let completion_items text (pos:POSITION.t) ast =
let filename = Lsp.Uri.to_path (Lsp.Text_document.documentUri text) in
let range =
let line = pos.line in
let character = pos.character in
let texts = String.split_on_char '\n' @@ Lsp.Text_document.text text in
let text_line = List.nth texts line in
let index = 1 + String.rindex_from text_line (character - 1) ' ' in
let position_start = Position.create ~character:index ~line in
Range.create ~start:position_start ~end_:pos
let position_start = POSITION.create ~character:index ~line in
Lsp.Types.Range.create ~start:position_start ~end_:pos
in

let names = name_proposals ast ~filename pos in
let keywords = keyword_proposals ast pos in
let words = names @ keywords in

List.map (fun x ->
let textedit = TextEdit.create ~newText:x ~range in
let textedit = Lsp.Types.TextEdit.create ~newText:x ~range in
(*we may change the ~sortText/preselect for reason of priority *)
CompletionItem.create
Lsp.Types.CompletionItem.create
~label:x
~sortText:x
~preselect:false
Expand Down
14 changes: 7 additions & 7 deletions src/lsp/cobol_lsp/lsp_notif.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
(* *)
(**************************************************************************)

open Lsp_server.TYPES
open Server.TYPES

let on_notification state notif =
match state, notif with
Expand All @@ -22,15 +22,15 @@ let on_notification state notif =
| NotInitialized _ | Exit _ as state, _ ->
state (* spec indicate notif should just be discarded *)
| Initialized config, Initialized ->
Running (Lsp_server.init ~config)
Running (Server.init ~config)
| Running registry, TextDocumentDidOpen params ->
Running (Lsp_server.did_open params registry)
Running (Server.did_open params registry)
| Running registry, TextDocumentDidChange params ->
Running (Lsp_server.did_change params registry)
Running (Server.did_change params registry)
| Running registry, TextDocumentDidClose params ->
Running (Lsp_server.did_close params registry)
Running (Server.did_close params registry)
| Running _, Exit ->
Lsp_request.shutdown state;
Request.shutdown state;
Exit (Error "Received premature 'exit' notification")
| _ ->
state
Expand All @@ -42,7 +42,7 @@ let handle notif state =
state
| Ok notif ->
try on_notification state notif with
| Lsp_server.Document_not_found { uri } ->
| Server.Document_not_found { uri } ->
Lsp_io.pretty_notification ~type_:Error
"Document@ %s@ is@ not@ opened@ yet"
(Lsp.Types.DocumentUri.to_string uri);
Expand Down
2 changes: 1 addition & 1 deletion src/lsp/cobol_lsp/lsp_notif.mli
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
(* *)
(**************************************************************************)

val handle: Jsonrpc.Notification.t -> (Lsp_server.state as 's) -> 's
val handle: Jsonrpc.Notification.t -> (Server.state as 's) -> 's
8 changes: 4 additions & 4 deletions src/lsp/cobol_lsp/lsp_semtoks.ml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ type semtok = {
}

let semtok ?(tokmods = TOKMOD.none) toktyp lexloc =
let range = Lsp_position.range_of_lexloc lexloc in
let range = Position.range_of_lexloc lexloc in
let line = range.start.line in
let start = range.start.character in
let length = range.end_.character - start in
Expand All @@ -109,7 +109,7 @@ let single_line_lexlocs_in ~filename =

let acc_semtoks ~filename ?range ?tokmods toktyp loc acc =
List.fold_left begin fun acc lexloc -> match range with
| Some r when not (Lsp_position.intersects_lexloc r lexloc) -> acc
| Some r when not (Position.intersects_lexloc r lexloc) -> acc
| _ -> semtok toktyp ?tokmods lexloc :: acc
end acc @@ single_line_lexlocs_in ~filename loc

Expand Down Expand Up @@ -548,7 +548,7 @@ let semtoks_of_comments ~filename ?range rev_comments =
| Cobol_preproc.Text.{ comment_loc = s, _ as lexloc; _ }
when s.Lexing.pos_fname = filename &&
Option.fold range
~some:(fun r -> Lsp_position.intersects_lexloc r lexloc)
~some:(fun r -> Position.intersects_lexloc r lexloc)
~none:true ->
semtok TOKTYP.comment lexloc :: acc
| _ ->
Expand All @@ -563,7 +563,7 @@ let semtoks_of_ignored ~filename ?range rev_ignored =
List.fold_left begin fun acc ((s, _ ) as lexloc) ->
if s.Lexing.pos_fname = filename &&
Option.fold range
~some:(fun r -> Lsp_position.intersects_lexloc r lexloc)
~some:(fun r -> Position.intersects_lexloc r lexloc)
~none:true
then semtok TOKTYP.comment lexloc :: acc
else acc
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ let rootdir_for ~uri ~layout =

let show_n_forget_diagnostics ?(force = false) { result = project; diags } =
if force || diags <> DIAGS.Set.none then
Lsp_diagnostics.publish @@
Lsp_diagnostics.translate diags
Diagnostics.publish @@
Diagnostics.translate diags
~rootdir:(Superbol_project.string_of_rootdir project.rootdir)
~uri:(`Main (Lsp.Uri.of_path project.config_filename));
project
Expand Down
File renamed without changes.
Loading

0 comments on commit 0458349

Please sign in to comment.