-
Notifications
You must be signed in to change notification settings - Fork 14
[WIP] 🐕🦺 Cooltt Server v2.0 #289
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
Open
TOTBWF
wants to merge
39
commits into
main
Choose a base branch
from
cooltt-server-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
1bab8ff
Add socket communication code for a cooltt display server
TOTBWF 856f19b
Add syntax for "Probe Holes"
TOTBWF bc5b903
Use a 'ref' to hold the cooltt server handle
TOTBWF 331d422
Add 'probe_goal' family of tactics
TOTBWF 2eb241f
Add server communication inside elaborator
TOTBWF bba9713
Server initialization + command line args
TOTBWF e42d970
Fix issue with emacs mode + extra args
TOTBWF 115b838
Update protocol to perform more heavy lifting on the cooltt side
TOTBWF f2b3c71
Update zsh completion
favonia d79782d
Merge remote-tracking branch 'origin/main' into cooltt-server
TOTBWF 5a8aeb1
Replace ProbeHole with Visualize
TOTBWF c30a940
Update syntax highlighting
TOTBWF 10e4fff
Add ability to pass in server hostname, rework options handling a bit
TOTBWF a568129
Update message format to track changes to coolttviz
TOTBWF 36717bd
Fix Test Suite
TOTBWF 3d8480a
Remove old server code
TOTBWF 2777db2
Add a message queue for emitting metadata from the refiner
TOTBWF 2beea3a
Thread through a null job queue into the refiner
TOTBWF b03d146
Start implementing LSP server
TOTBWF af99c13
Fix some issues with the core lsp impl
TOTBWF 3435bfa
Add 'Executor.ml' for running server actions
TOTBWF 0b24b1c
Add emacs config for lsp integration
TOTBWF 10e5aaf
Pull 'elaborate_typed_term' into the elaborator
TOTBWF c5f6839
Remove job queue in favor of metadata list
TOTBWF 1306aac
Update main.ml with server command
TOTBWF a72fd57
Add type hovers
TOTBWF f018ff6
Tweak printing for subtypes with trivial cofibrations
TOTBWF f2b74ff
[WIP] Start working on holes/commands
TOTBWF 26c8989
Add segment trees
favonia ea21988
Remove stupid parentheses
favonia a9e2309
Refactor and clean up code
favonia 425b0f0
Add a README
favonia 6ad5196
Add visualize code action
TOTBWF 75cb430
Wire up code actions
TOTBWF 45042be
Fix minor bug in SegmentTree
TOTBWF 16ddd81
Add some extra stuff to the segment tree API
TOTBWF 75e8550
Add pp_range
TOTBWF 34fcefa
Rework how metadata is stored
TOTBWF 0b0db06
Remove IntervalTree
TOTBWF File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
open Basis | ||
open Bwd | ||
open Frontend | ||
open Core | ||
open CodeUnit | ||
open Cubical | ||
|
||
module S = Syntax | ||
module D = Domain | ||
|
||
open Lsp.Types | ||
module Json = Lsp.Import.Json | ||
|
||
module LwtIO = Lwt_io | ||
|
||
open LspLwt.Notation | ||
|
||
(* FIXME: This should live elsewhere, we use this a lot. *) | ||
let ppenv_bind env ident = | ||
Pp.Env.bind env @@ Ident.to_string_opt ident | ||
|
||
module Visualize = struct | ||
let command_name = "cooltt.visualize" | ||
let action_kind = CodeActionKind.Other "cooltt.visualize.hole" | ||
|
||
let serialize_label (str : string) (pos : (string * float) list) : Json.t = | ||
`Assoc [ | ||
"position", `Assoc (List.map (fun (nm, d) -> (nm, `Float d)) pos); | ||
"txt", `String str | ||
] | ||
|
||
let dim_tm : S.t -> float = | ||
function | ||
| S.Dim0 -> -. 1.0 | ||
| S.Dim1 -> 1.0 | ||
| _ -> failwith "dim_tm: bad dim" | ||
|
||
let rec dim_from_cof (dims : (string option) bwd) (cof : S.t) : (string * float) list list = | ||
match cof with | ||
| S.Cof (Cof.Eq (S.Var v, r)) -> | ||
let axis = Option.get @@ Bwd.nth dims v in | ||
let d = dim_tm r in | ||
[[(axis, d)]] | ||
| S.Cof (Cof.Join cofs) -> List.concat_map (dim_from_cof dims) cofs | ||
| S.Cof (Cof.Meet cofs) -> [List.concat @@ List.concat_map (dim_from_cof dims) cofs] | ||
| _ -> failwith "dim_from_cof: bad cof" | ||
|
||
let boundary_labels dims env bdry = | ||
let rec go env dims (bdry, cons) = | ||
match cons with | ||
| S.CofSplit branches -> | ||
let (_x, envx) = ppenv_bind env `Anon in | ||
List.concat_map (go envx (Snoc (dims, None))) branches | ||
| _ -> | ||
let (_x, envx) = ppenv_bind env `Anon in | ||
let lbl = Format.asprintf "%a" (S.pp envx) cons in | ||
List.map (serialize_label lbl) @@ dim_from_cof (Snoc (dims, None)) bdry | ||
in | ||
match bdry with | ||
| S.CofSplit branches -> | ||
let (_x, envx) = ppenv_bind env `Anon in | ||
List.concat_map (go envx dims) branches | ||
| _ -> [] | ||
|
||
let serialize_boundary ctx goal : Json.t option = | ||
let rec go dims env = | ||
function | ||
| [] -> | ||
begin | ||
match goal with | ||
| S.Sub (_, _, bdry) -> | ||
let dim_names = Bwd.to_list @@ Bwd.filter_map (Option.map (fun name -> `String name)) dims in | ||
let labels = boundary_labels dims env bdry in | ||
let context = Format.asprintf "%a" (S.pp_sequent ~lbl:None ctx) goal in | ||
let msg = `Assoc [ | ||
("dims", `List dim_names); | ||
("labels", `List labels); | ||
("context", `String context) | ||
] | ||
in Some (`Assoc ["DisplayGoal", msg]) | ||
| _ -> None | ||
end | ||
| (var, var_tp) :: ctx -> | ||
let (dim_name, envx) = ppenv_bind env var in | ||
match var_tp with | ||
| S.TpDim -> go (Snoc (dims, Some dim_name)) envx ctx | ||
| _ -> go (Snoc (dims, None)) envx ctx | ||
in go Emp Pp.Env.emp ctx | ||
|
||
let create ctx goal = | ||
serialize_boundary ctx goal |> Option.map @@ fun json -> | ||
let command = Command.create | ||
~title:"visualize" | ||
~command:command_name | ||
~arguments:[json] | ||
() | ||
in CodeAction.create | ||
~title:"visualize hole" | ||
~kind:action_kind | ||
~command | ||
() | ||
|
||
let execute arguments = | ||
match arguments with | ||
| Some [arg] -> | ||
(* FIXME: Handle the visualizer socket better *) | ||
let host = Unix.gethostbyname "localhost" in | ||
let host_entry = Array.get host.h_addr_list 0 in | ||
let addr = Unix.ADDR_INET (host_entry, 3001) in | ||
let* (ic, oc) = LwtIO.open_connection addr in | ||
let* _ = LwtIO.write oc (Json.to_string arg) in | ||
let* _ = LwtIO.flush oc in | ||
let* _ = LwtIO.close ic in | ||
LwtIO.close oc | ||
| _ -> | ||
(* FIXME: Handle this better *) | ||
Lwt.return () | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
open Basis | ||
open Core | ||
open CodeUnit | ||
|
||
module Json = Lsp.Import.Json | ||
|
||
module Visualize : sig | ||
val command_name : string | ||
val create : (Ident.t * Syntax.tp) list -> Syntax.tp -> Lsp.Types.CodeAction.t option | ||
val execute : Json.t list option -> unit Lwt.t | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
open Basis | ||
open Core | ||
|
||
val elaborate_file : Bantorra.Manager.library -> string -> (Lsp.Types.Diagnostic.t list * RefineMetadata.t list) Lwt.t | ||
val elaborate_file : Bantorra.Manager.library -> string -> (Lsp.Types.Diagnostic.t list * RefineState.Metadata.t) Lwt.t |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might not be correct, because the "same" span can show up as multiple segments, and "shadowed" spans will not even be in the tree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest eventually removing
containing
completely---or we have to rethink the entire framework.