Skip to content

Commit

Permalink
Merge branch 'main' into v8.17
Browse files Browse the repository at this point in the history
  • Loading branch information
ejgallego committed Jul 5, 2023
2 parents d31d060 + ecb728e commit 4d48314
Show file tree
Hide file tree
Showing 77 changed files with 2,199 additions and 421 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,15 @@ jobs:
if: matrix.os != 'windows-latest'
run: opam exec -- make test

- name: 🐛 Test fcc
if: matrix.os != 'windows-latest'
run: opam exec -- make test-compiler

build-nix:
name: Nix
strategy:
matrix:
os: [macOS-latest, ubuntu-latest]
os: [ubuntu-latest, macOS-latest]
fail-fast: false

runs-on: ${{ matrix.os }}
Expand All @@ -82,7 +86,7 @@ jobs:
submodules: recursive

- name: ❄️ Setup Nix
uses: cachix/install-nix-action@v18
uses: cachix/install-nix-action@v22

- name: 🧱 Build coq-lsp
run: nix build .?submodules=1
Expand Down
19 changes: 16 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# coq-lsp 0.1.7: Just-in-time
-----------------------------

- New command line compiler `fcc`. `fcc` allows to access most
features of `coq-lsp` without the need for a command line client,
and it has been designed to be extensible and machine-friendly
(@ejgallego, #507, fixes #472)
- Enable web extension support. For now this will not try to start
the coq-lsp worker as it is not yet built. (@ejgallego, #430, fixes
#234)
- Improvements and clenaups on hover display, in particular we don't
print repeated `Notation` strings (@ejgallego, #422)
- Don't fail on missing serlib plugins, they are indeed an
optimization; this mostly impacts 8.16 by lowering the SerAPI
requirements (@ejgallego, #421)
- Enable web extension support. For now this will not try to start
the coq-lsp worker as it is not yet built. (@ejgallego, #430, fixes
#234)
- Fix bug that prevented "Goal after tactic" from working properly
(@ejgallego, #438, reported by David Ilcinkas)
- Message about workspace detection was printing the wrong file,
Expand All @@ -32,6 +36,15 @@
processing. Default setting is `0.1`, using more aggressive
settings like `0.01` can decrease latency of requests by ~4x
(@ejgallego, @hazardouspeach, #467, #471)
- Warnings from `_CoqProject` files are now applied (@ejgallego,
reported by @arthuraa, #500)
- Be more resilient when serializing unknowns Asts (@ejgallego, #503,
reported by Gijs Pennings)
- Coq's STM is not linked anymore to `coq-lsp` (@ejgallego, #511)
- More granular options `send_perf_data` `send_diags`, `verbosity`
will set them now (@ejgallego, #517)
- Preliminary plugin API for completion events (@ejgallego, #518,
fixes #506)

# coq-lsp 0.1.6: Peek
---------------------
Expand Down
55 changes: 31 additions & 24 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,27 +154,6 @@ Some tips:

[ocamlformat]: https://github.com/ocaml-ppx/ocamlformat

### Releasing

`coq-lsp` is released using `dune-release tag` + `dune-release`.

The checklist for the release as of today is the following:

### Client:

- update the client changelog at `editor/code/CHANGELOG.md`, commit
- for the `main` branch: `dune release tag $coq_lsp_version`
- check with `vsce ls` that the client contents are OK
- `vsce publish`

### Server:

- sync branches for previous Coq versions, using `git merge`, test and push to CI.
- `dune release tag` for each `$coq_lsp_version+$coq_version`
- `dune release` for each version that should to the main opam repos
- [optional] update pre-release packages to coq-opam-archive
- [important] bump `version.ml` and `package.json` version string

## Client guide (VS Code Extension)

The VS Code extension is setup as a standard `npm` Typescript + React package
Expand Down Expand Up @@ -277,16 +256,44 @@ that, you want to use the web extension profile in the launch setup.
The default build target will allow you to debug the extension by providing the
right sourcemaps.

## Test-suite

`coq-lsp` has a test-suite in the [test directory](./test), see the
README there for more details.

## Releasing

`coq-lsp` is released using `dune-release tag` + `dune-release`.

The checklist for the release as of today is the following:

### Client:

- update the client changelog at `editor/code/CHANGELOG.md`, commit
- for the `main` branch: `dune release tag $coq_lsp_version`
- check with `vsce ls` that the client contents are OK
- `vsce publish`

### Server:

- sync branches for previous Coq versions, using `git merge`, test and push to CI.
- `dune release tag` for each `$coq_lsp_version+$coq_version`
- `dune release` for each version that should to the main opam repos
- [optional] update pre-release packages to coq-opam-archive
- [important] bump `version.ml` and `package.json` version string

## Emacs

You should be able to use `coq-lsp` with
[eglot](https://joaotavora.github.io/eglot/).

Emacs support is a goal of `coq-lsp`, so if you find any trouble using `eglot` or `lsp-mode` with `coq-lsp`, please don't hesitate to open an issue.
Emacs support is a goal of `coq-lsp`, so if you find any trouble using
`eglot` or `lsp-mode` with `coq-lsp`, please don't hesitate to open an
issue.

## VIM

You should be able to use `coq-lsp` with VIM.
You should be able to use `coq-lsp` with VIM.

VIM support is a goal of `coq-lsp`, so if you find any trouble using `coq-lsp` with VIM, please don't hesitate to open an issue.
VIM support is a goal of `coq-lsp`, so if you find any trouble using
`coq-lsp` with VIM, please don't hesitate to open an issue.
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ build: coq_boot
check: coq_boot
dune build $(DUNEOPT) @check

test/node_modules: test/package.json
cd test && npm i
test/server/node_modules: test/server/package.json
cd test/server && npm i

.PHONY: test
test: build test/node_modules
cd test && npm test
test: build test/server/node_modules
cd test/server && npm test

.PHONY: test-compiler
test-compiler: build
OCAMLPATH=_build/install/default/lib:$$OCAMLPATH FCC_TEST=true dune runtest

.PHONY: fmt format
fmt format:
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ and web native usage, providing quite a few extra features from vanilla Coq.
- [💾 `.vo` file saving](#-vo-file-saving)
- [⏱️ Detailed Timing and Memory Statistics](#️-detailed-timing-and-memory-statistics)
- [🔧 Client-Side Configuration Options](#-client-side-configuration-options)
- [🖵 Extensible, Machine-friendly Command Line Compiler](#️-extensive-machine-friendly-command-line-compiler)
- [♻️ Reusability, Standards, Modularity](#️-reusability-standards-modularity)
- [🌐 Web Native!](#-web-native)
- [🔎 A Platform for Research!](#-a-platform-for-research)
Expand Down Expand Up @@ -161,6 +162,16 @@ See the `coq-lsp` extension configuration in VSCode for options available.

<img alt="Configuration screen" height="286px" src="etc/img/lsp-config.png"/>

### 🖵 Extensible, Machine-friendly Command Line Compiler

`coq-lsp` includes the `fcc` "Flèche Coq Compiler" which allows the access to
almost all the features of Flèche / `coq-lsp` without the need to spawn a
fully-fledged LSP client.

`fcc` has been designed to be machine-friendly and extensible, so you can easily
add your pre/post processing passes, for example to analyze or serialize parts
of Coq files.

### ♻️ Reusability, Standards, Modularity

The incremental document checking library of `coq-lsp` has been designed to be
Expand Down
14 changes: 14 additions & 0 deletions compiler/args.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Display = struct
type t =
| Verbose
| Normal
| Quiet
end

type t =
{ roots : string list (** workspace root(s) *)
; files : string list (** files to compile *)
; debug : bool (** run in debug mode *)
; display : Display.t (** display level *)
; plugins : string list (** Flèche plugins to load *)
}
6 changes: 6 additions & 0 deletions compiler/cc.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(* Compiler context *)
type t =
{ root_state : Coq.State.t
; workspaces : (string * Coq.Workspace.t) list
; io : Fleche.Io.CallBack.t
}
42 changes: 42 additions & 0 deletions compiler/compile.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
open Fleche

let is_in_dir ~dir ~file = CString.is_prefix dir file

let workspace_of_uri ~io ~uri ~workspaces =
let file = Lang.LUri.File.to_string_file uri in
match List.find_opt (fun (dir, _) -> is_in_dir ~dir ~file) workspaces with
| None ->
Io.Report.message ~io ~lvl:1 ~message:("file not in workspace: " ^ file);
snd (List.hd workspaces)
| Some (_, workspace) -> workspace

(* Improve errors *)
let save_vo_file ~doc =
match Fleche.Doc.save ~doc with
| { r = Completed (Ok ()); feedback = _ } -> ()
| { r = Completed (Error _); feedback = _ } -> ()
| { r = Interrupted; feedback = _ } -> ()

let save_diags_file ~(doc : Fleche.Doc.t) =
let file = Lang.LUri.File.to_string_file doc.uri in
let file = Filename.remove_extension file ^ ".diags" in
let diags = Fleche.Doc.diags doc in
Util.format_to_file ~file ~f:Output.pp_diags diags

let compile_file ~cc file =
let { Cc.io; root_state; workspaces } = cc in
io.message ~lvl:3 ~message:(Format.asprintf "compiling file %s@\n%!" file);
match Lang.LUri.(File.of_uri (of_string file)) with
| Error _ -> ()
| Ok uri -> (
let workspace = workspace_of_uri ~io ~workspaces ~uri in
let raw = Util.input_all file in
let () = Theory.create ~io ~root_state ~workspace ~uri ~raw ~version:1 in
match Theory.Check.maybe_check ~io with
| None -> ()
| Some (_, doc) ->
save_vo_file ~doc;
save_diags_file ~doc;
Theory.close ~uri)

let compile ~cc = List.iter (compile_file ~cc)
48 changes: 48 additions & 0 deletions compiler/driver.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
(* Duplicated with coq_lsp *)
let coq_init ~debug =
let load_module = Dynlink.loadfile in
let load_plugin = Coq.Loader.plugin_handler None in
Coq.Init.(coq_init { debug; load_module; load_plugin })

let sanitize_paths message =
match Sys.getenv_opt "FCC_TEST" with
| None -> message
| Some _ ->
let home_re = Str.regexp "coqlib is at: .*$" in
Str.global_replace home_re "coqlib is at: [TEST_PATH]" message

let log_workspace ~io (dir, w) =
let message, extra = Coq.Workspace.describe w in
Fleche.Io.Log.trace "workspace" ("initialized " ^ dir) ~extra;
let message = sanitize_paths message in
Fleche.Io.Report.message ~io ~lvl:3 ~message

let load_plugin plugin_name = Fl_dynload.load_packages [ plugin_name ]
let plugin_init = List.iter load_plugin

let go args =
let { Args.roots; display; debug; files; plugins } = args in
(* Initialize event callbacks *)
let io = Output.init display in
(* Initialize Coq *)
let debug = debug || Fleche.Debug.backtraces || !Fleche.Config.v.debug in
let root_state = coq_init ~debug in
let cmdline =
{ Coq.Workspace.CmdLine.coqcorelib =
Filename.concat Coq_config.coqlib "../coq-core/"
; coqlib = Coq_config.coqlib
; ocamlpath = None
; vo_load_path = []
; ml_include_path = []
; args = []
}
in
let roots = if List.length roots < 1 then [ Sys.getcwd () ] else roots in
let workspaces =
List.map (fun dir -> (dir, Coq.Workspace.guess ~cmdline ~debug ~dir)) roots
in
List.iter (log_workspace ~io) workspaces;
let cc = Cc.{ root_state; workspaces; io } in
(* Initialize plugins *)
plugin_init plugins;
Compile.compile ~cc files
10 changes: 10 additions & 0 deletions compiler/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(library
(name fcc_lib)
(modules :standard \ fcc)
; LSP is used to print diagnostics, etc...
(libraries fleche lsp))

(executable
(public_name fcc)
(modules fcc)
(libraries cmdliner fcc_lib))
54 changes: 54 additions & 0 deletions compiler/fcc.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
(* Flèche Coq compiler *)
open Cmdliner
open Fcc_lib

let fcc_main roots display debug plugins files =
let args = Args.{ roots; display; files; debug; plugins } in
Driver.go args

let roots : string list Term.t =
let doc = "Workspace(s) root(s)" in
Arg.(value & opt_all string [] & info [ "root" ] ~docv:"ROOTS" ~doc)

let display : Args.Display.t Term.t =
let doc = "Verbosity display settings" in
let dparse =
Args.Display.[ ("verbose", Verbose); ("normal", Normal); ("quiet", Quiet) ]
in
Arg.(
value
& opt (enum dparse) Args.Display.Normal
& info [ "display" ] ~docv:"DISPLAY" ~doc)

let debug : bool Term.t =
let doc = "Enable debug mode" in
Arg.(value & flag & info [ "debug" ] ~docv:"DISPLAY" ~doc)

let file : string list Term.t =
let doc = "File(s) to compile" in
Arg.(value & pos_all string [] & info [] ~docv:"FILES" ~doc)

let plugins : string list Term.t =
let doc = "Compiler plugins to load" in
Arg.(value & opt_all string [] & info [ "plugin" ] ~docv:"PLUGINS" ~doc)

let fcc_cmd : unit Cmd.t =
let doc = "Flèche Coq Compiler" in
let man =
[ `S "DESCRIPTION"
; `P "Flèche Coq Compiler"
; `S "USAGE"
; `P "See the documentation on the project's webpage for more information"
]
in
let version = Fleche.Version.server in
let fcc_term =
Term.(const fcc_main $ roots $ display $ debug $ plugins $ file)
in
Cmd.(v (Cmd.info "fcc" ~version ~doc ~man) fcc_term)

let main () =
let ecode = Cmd.eval fcc_cmd in
exit ecode

let () = main ()
1 change: 1 addition & 0 deletions compiler/fcc.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(* Flèche Coq compiler *)

0 comments on commit 4d48314

Please sign in to comment.