Skip to content

Commit

Permalink
Merge pull request #841 from ejgallego/request_imm
Browse files Browse the repository at this point in the history
[fleche] New immediate request serving mode.
  • Loading branch information
ejgallego authored Sep 29, 2024
2 parents 6259a79 + b9d7777 commit 2d8642d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
@corwin-of-amber, #433)
- [hover] Fix universe and level printing in hover (#839, fixes #835
, @ejgallego , @Alizter)
- [fleche] New immediate request serving mode. In this mode, requests
are served with whatever document state we have. This is very
useful when we are not in continuous mode, and we don't have a good
reference as to what to build, for example in
`documentSymbols`. The mode actually works pretty well in practice
as often language requests will come after goals requests, so the
info that is needed is at hand. It could also be tried to set the
build target for immediate requests to the view hint, but we should
see some motivation for that (@ejgallego, #841)

# coq-lsp 0.2.0: From Green to Blue
-----------------------------------
Expand Down
11 changes: 10 additions & 1 deletion controller/lsp_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,16 @@ let do_document_request_maybe ~params ~handler =
let postpone = not !Fleche.Config.v.check_only_on_request in
do_document_request ~postpone ~params ~handler

let do_symbols = do_document_request_maybe ~handler:Rq_symbols.symbols
let do_immediate ~params ~handler =
let uri = Helpers.get_uri params in
Rq.Action.Data (Request.Data.Immediate { uri; handler })

(* new immediate mode, cc: #816 *)
let do_symbols ~params =
let handler = Rq_symbols.symbols in
if !Fleche.Config.v.check_only_on_request then do_immediate ~params ~handler
else do_document_request ~postpone:true ~params ~handler

let do_document = do_document_request_maybe ~handler:Rq_document.request
let do_save_vo = do_document_request_maybe ~handler:Rq_save.request
let do_lens = do_document_request_maybe ~handler:Rq_lens.request
Expand Down
8 changes: 8 additions & 0 deletions controller/request.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ type position =
(** Requests that require data access *)
module Data = struct
type t =
| Immediate of
{ uri : Lang.LUri.File.t
; handler : document
}
| DocRequest of
{ uri : Lang.LUri.File.t
; postpone : bool
Expand All @@ -63,6 +67,7 @@ module Data = struct

(* Debug printing *)
let data fmt = function
| Immediate { uri = _; handler = _ } -> Format.fprintf fmt "{k:imm }"
| DocRequest { uri = _; postpone; handler = _ } ->
Format.fprintf fmt "{k:doc | p: %B}" postpone
| PosRequest { uri = _; point; version; postpone; handler = _ } ->
Expand All @@ -73,13 +78,16 @@ module Data = struct

let dm_request pr =
match pr with
| Immediate { uri; handler = _ } ->
(uri, false, Fleche.Theory.Request.Immediate)
| DocRequest { uri; postpone; handler = _ } ->
(uri, postpone, Fleche.Theory.Request.FullDoc)
| PosRequest { uri; point; version; postpone; handler = _ } ->
(uri, postpone, Fleche.Theory.Request.(PosInDoc { point; version }))

let serve ~token ~doc pr =
match pr with
| Immediate { uri = _; handler } -> handler ~token ~doc
| DocRequest { uri = _; postpone = _; handler } -> handler ~token ~doc
| PosRequest { uri = _; point; version = _; postpone = _; handler } ->
handler ~token ~point ~doc
Expand Down
4 changes: 4 additions & 0 deletions controller/request.mli
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ type position =
(** Requests that require data access *)
module Data : sig
type t =
| Immediate of
{ uri : Lang.LUri.File.t
; handler : document
}
| DocRequest of
{ uri : Lang.LUri.File.t
; postpone : bool
Expand Down
3 changes: 3 additions & 0 deletions fleche/theory.ml
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ let close ~uri =

module Request = struct
type request =
| Immediate
| FullDoc
| PosInDoc of
{ point : int * int
Expand Down Expand Up @@ -379,6 +380,7 @@ module Request = struct
let default () = Cancel in
(* should be Cancelled? *)
match request with
| Immediate -> Handle.with_doc ~kind ~default ~uri ~f:(fun _ doc -> Now doc)
| FullDoc ->
Handle.with_doc ~kind ~default ~uri ~f:(fun _ doc ->
match (Doc.Completion.is_completed doc.completed, postpone) with
Expand All @@ -402,6 +404,7 @@ module Request = struct
(** Removes the request from the list of things to wake up *)
let remove { id; uri; postpone = _; request } =
match request with
| Immediate -> ()
| FullDoc -> Handle.remove_cp_request ~uri ~id
| PosInDoc { point; _ } -> Handle.remove_pt_request ~uri ~id ~point
end
1 change: 1 addition & 0 deletions fleche/theory.mli
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ val close : uri:Lang.LUri.File.t -> unit

module Request : sig
type request =
| Immediate
| FullDoc
| PosInDoc of
{ point : int * int
Expand Down

0 comments on commit 2d8642d

Please sign in to comment.