From e737563991a5f4554101eb8ab23f9f065de9f24f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Basile=20Cl=C3=A9ment?= Date: Fri, 27 Oct 2023 13:56:17 +0200 Subject: [PATCH 1/2] Included a js_of_ocaml version of superbol in the .vsix This is a first step towards fixing #76 (but does not entirely fixes it). It avoids the need to install an external superbol executable, and should work on all platforms. The bundled superbol-free.bc.js is used if the option `superbol.path` is set to `null`, which is the new default. Some performance investigation is needed -- if we find out that the js_of_ocaml version is too slow for practical use, we can make this not be the default. --- Makefile | 10 ++-- Makefile.header | 57 +++++++++++++++---- package.json | 8 ++- src/lsp/superbol-free/dune | 1 + src/lsp/superbol_free_lib/dune | 2 +- src/lsp/superbol_free_lib/project.ml | 8 ++- src/vscode/superbol-vscode-platform/dune | 3 - .../superbol_languageclient.ml | 28 ++++++--- .../superbol_languageclient.mli | 4 +- .../superbol_vscode_platform.ml | 5 +- 10 files changed, 89 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index 149e48336..4e79cb6c5 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ all: build build: ./scripts/before.sh build - opam exec -- dune build @install + $(DUNE) build @install ./scripts/copy-bin.sh superbol-vscode-platform polka-js-stubs interop-js-stubs node-js-stubs vscode-js-stubs vscode-languageclient-js-stubs vscode-json vscode-debugadapter vscode-debugprotocol superbol-free superbol_free_lib cobol_common cobol_parser cobol_ptree ebcdic_lib cobol_lsp ppx_cobcflags pretty cobol_config cobol_indent cobol_preproc cobol_data cobol_typeck superbol_testutils ez_toml ./scripts/after.sh build @@ -43,7 +43,7 @@ sphinx: doc-common odoc: doc-common mkdir -p ${ODOC_TARGET} ./scripts/before.sh odoc ${ODOC_TARGET} - opam exec -- dune build @doc + $(DUNE) build @doc rsync -auv --delete _build/default/_doc/_html/. ${ODOC_TARGET} ./scripts/after.sh odoc ${ODOC_TARGET} @@ -53,10 +53,10 @@ view: xdg-open file://$$(pwd)/_drom/docs/index.html fmt: - opam exec -- dune build @fmt --auto-promote + $(DUNE) build @fmt --auto-promote fmt-check: - opam exec -- dune build @fmt + $(DUNE) build @fmt install: opam pin -y --no-action -k path . @@ -73,7 +73,7 @@ dev-deps: test: ./scripts/before.sh test - opam exec -- dune build @runtest + $(DUNE) build @runtest ./scripts/after.sh test clean: diff --git a/Makefile.header b/Makefile.header index 77aefb19e..1e43f56cb 100644 --- a/Makefile.header +++ b/Makefile.header @@ -1,6 +1,15 @@ # -*- Makefile -*- -PROJECT=superbol_vscode_platform -SRCDIR=src/vscode/superbol-vscode-platform +# Source directory for the LanguageClient +CLIENT_PROJECT=superbol_vscode_platform +CLIENT_SRCDIR=src/vscode/superbol-vscode-platform + +# Source directory for the LanguageServer +SERVER_SRCDIR ?= src/lsp/superbol-free +SERVER_PROJECT ?= superbol-free + +# Dune, through opam +DUNE ?= opam exec -- dune + CP ?= cp -f # Emacs lsp-mode source directory (https://github.com/emacs-lsp/lsp-mode): @@ -15,35 +24,59 @@ superbol-free: build diff -u package.json.prev package.json && rm -f package.json.prev .PHONY: build-debug yarn-debug +.PHONY: phony + +phony: + +_out/$(SERVER_PROJECT).bc.js: phony + $(DUNE) build $(SERVER_SRCDIR)/main.bc.js --profile=release + mkdir -p _out + $(CP) _build/default/$(SERVER_SRCDIR)/main.bc.js _out/$(SERVER_PROJECT).bc.js -build-debug: - opam exec -- dune build $(SRCDIR)/$(PROJECT).bc.js --profile=release +_out/$(CLIENT_PROJECT).bc.js: phony + $(DUNE) build $(CLIENT_SRCDIR)/$(CLIENT_PROJECT).bc.js --profile=release mkdir -p _out - $(CP) _build/default/$(SRCDIR)/$(PROJECT).bc.js _out/ + $(CP) _build/default/$(CLIENT_SRCDIR)/$(CLIENT_PROJECT).bc.js _out/ + +build-debug: _out/$(CLIENT_PROJECT).bc.js _out/$(SERVER_PROJECT).bc.js $(MAKE) yarn-debug # Use 'make build-debug' before to copy the JS file in _out/ yarn-debug: - yarn esbuild _out/$(PROJECT).bc.js \ + yarn esbuild _out/$(CLIENT_PROJECT).bc.js \ --bundle \ --external:vscode \ --outdir=_dist \ --platform=node \ --target=es6 \ --sourcemap -# the last command generated _dist/$(PROJECT).bs.js + yarn esbuild _out/$(SERVER_PROJECT).bc.js \ + --bundle \ + --external:vscode \ + --outdir=_dist \ + --platform=node \ + --target=es6 \ + --sourcemap +# the last command generated _dist/$(CLIENT_PROJECT).bs.js .PHONY: build-release yarn-release -build-release: - opam exec -- dune build $(SRCDIR)/$(PROJECT).bc.js --profile=release - mkdir -p _out - $(CP) _build/default/$(SRCDIR)/$(PROJECT).bc.js _out/ +build-release: _out/$(CLIENT_PROJECT).bc.js $(MAKE) yarn-release # Use 'make build-release' before to copy the JS file in _out/ yarn-release: - yarn esbuild _out/$(PROJECT).bc.js \ + yarn esbuild _out/$(CLIENT_PROJECT).bc.js \ + --bundle \ + --external:vscode \ + --outdir=_dist \ + --platform=node \ + --target=es6 \ + --minify-whitespace \ + --minify-syntax \ + --sourcemap \ + --sources-content=false + yarn esbuild _out/$(SERVER_PROJECT).bc.js \ --bundle \ --external:vscode \ --outdir=_dist \ diff --git a/package.json b/package.json index c90d1825d..f30c06c07 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,12 @@ "description": "If something is selected, only format the selection" }, "superbol.path": { - "default": "superbol-free", - "description": "Path to the `superbol` command" + "type": [ + "string", + "null" + ], + "default": null, + "description": "Path to the external `superbol` command. If `null`, use the bundled `superbol-free`." } } }, diff --git a/src/lsp/superbol-free/dune b/src/lsp/superbol-free/dune index 1e0b7391a..e85ded79b 100644 --- a/src/lsp/superbol-free/dune +++ b/src/lsp/superbol-free/dune @@ -1,6 +1,7 @@ ; generated by drom from package skeleton 'driver' (executable (name main) + (modes exe js) (public_name superbol-free) (package superbol-free) ; use field 'dune-libraries' to add libraries without opam deps diff --git a/src/lsp/superbol_free_lib/dune b/src/lsp/superbol_free_lib/dune index 6a90de0af..832ddddfd 100644 --- a/src/lsp/superbol_free_lib/dune +++ b/src/lsp/superbol_free_lib/dune @@ -5,7 +5,7 @@ (public_name superbol_free_lib) (wrapped true) ; use field 'dune-libraries' to add libraries without opam deps - (libraries vscode-json ez_toml ez_file ez_cmdliner ez_api cobol_typeck cobol_parser cobol_lsp cobol_indent cobol_common ) + (libraries vscode-json ez_toml ez_file ez_cmdliner ez_api.encoding cobol_typeck cobol_parser cobol_lsp cobol_indent cobol_common ) ; use field 'dune-flags' to set this value (flags (:standard)) ; use field 'dune-stanzas' to add more stanzas here diff --git a/src/lsp/superbol_free_lib/project.ml b/src/lsp/superbol_free_lib/project.ml index c28f79244..2e5eb5bb4 100644 --- a/src/lsp/superbol_free_lib/project.ml +++ b/src/lsp/superbol_free_lib/project.ml @@ -143,9 +143,11 @@ let contributes = ~description: "If something is selected, only format the selection" ; - Manifest.PROPERTY.string "superbol.path" - ~default:"superbol-free" - ~description: "Path to the `superbol` command" + Manifest.PROPERTY.null_string "superbol.path" + ~default:None + ~description: + "Path to the external `superbol` command. \ + If `null`, use the bundled `superbol-free`." ] ) ~taskDefinitions: [ Manifest.taskDefinition diff --git a/src/vscode/superbol-vscode-platform/dune b/src/vscode/superbol-vscode-platform/dune index 169b623f9..69eb5f980 100644 --- a/src/vscode/superbol-vscode-platform/dune +++ b/src/vscode/superbol-vscode-platform/dune @@ -5,9 +5,6 @@ (libraries vscode-languageclient-js-stubs vscode-js-stubs promise_jsoo polka-js-stubs ocplib_stuff node-js-stubs jsonoo js_of_ocaml gen_js_api ) (modes js) (preprocess (pps gen_js_api.ppx)) - (js_of_ocaml (flags --source-map --pretty)) - (enabled_if (= %{context_name} "default")) - ) (install diff --git a/src/vscode/superbol-vscode-platform/superbol_languageclient.ml b/src/vscode/superbol-vscode-platform/superbol_languageclient.ml index 563d3a92e..5823febf1 100644 --- a/src/vscode/superbol-vscode-platform/superbol_languageclient.ml +++ b/src/vscode/superbol-vscode-platform/superbol_languageclient.ml @@ -14,15 +14,27 @@ let config = Vscode.Workspace.getConfiguration () -let serverOptions = - let command = - match Vscode.WorkspaceConfiguration.get ~section:"superbol.path" config with - | Some o -> Ojs.string_of_js o - | None -> "superbol-free" +let serverOptions extension = + let args = [ "lsp" ] in + let ojs = Vscode.WorkspaceConfiguration.get config ~section:"superbol.path" in + let cmd_opt = + match ojs with + | None -> None + | Some o when Ojs.is_null o -> None + | Some o -> Some (Ojs.string_of_js o) in - Vscode_languageclient.ServerOptions.create () - ~command - ~args:["lsp"] + match cmd_opt with + | Some command -> + Vscode_languageclient.ServerOptions.create () + ~command ~args + | None -> + let superbol_path = + Vscode.ExtensionContext.asAbsolutePath extension + ~relativePath:"_dist/superbol-free.bc.js" + in + Vscode_languageclient.ServerOptions.create () + ~command:"node" + ~args:(superbol_path :: args) let clientOptions = Vscode_languageclient.ClientOptions.create () diff --git a/src/vscode/superbol-vscode-platform/superbol_languageclient.mli b/src/vscode/superbol-vscode-platform/superbol_languageclient.mli index 7f49058f8..32aa00859 100644 --- a/src/vscode/superbol-vscode-platform/superbol_languageclient.mli +++ b/src/vscode/superbol-vscode-platform/superbol_languageclient.mli @@ -12,5 +12,7 @@ (* *) (**************************************************************************) -val serverOptions: Vscode_languageclient.Executable.t +val serverOptions: + Vscode.ExtensionContext.t -> + Vscode_languageclient.Executable.t val clientOptions: Vscode_languageclient.ClientOptions.t diff --git a/src/vscode/superbol-vscode-platform/superbol_vscode_platform.ml b/src/vscode/superbol-vscode-platform/superbol_vscode_platform.ml index 6ad104543..5e9320258 100644 --- a/src/vscode/superbol-vscode-platform/superbol_vscode_platform.ml +++ b/src/vscode/superbol-vscode-platform/superbol_vscode_platform.ml @@ -188,11 +188,13 @@ let activate (extension : Vscode.ExtensionContext.t) = Vscode.ExtensionContext.subscribe extension ~disposable:task; + let serverOptions = Superbol_languageclient.serverOptions extension in + client := Some (Vscode_languageclient.LanguageClient.make ~id:"cobolServer" ~name:"Cobol Server" - ~serverOptions:Superbol_languageclient.serverOptions + ~serverOptions ~clientOptions:Superbol_languageclient.clientOptions ()); match !client with @@ -209,4 +211,3 @@ let deactivate () = let () = Js_of_ocaml.Js.(export "activate" (wrap_callback activate)); Js_of_ocaml.Js.(export "deactivate" (wrap_callback deactivate)) - From 4f4a4a146f3854fb3204922fc1e9bdb8c0493ac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Basile=20Cl=C3=A9ment?= Date: Fri, 27 Oct 2023 15:15:00 +0200 Subject: [PATCH 2/2] Give drom its blood tribute --- Makefile.drom-tpl | 10 +++++----- src/lsp/superbol-free/package.toml | 1 + src/lsp/superbol_free_lib/package.toml | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Makefile.drom-tpl b/Makefile.drom-tpl index cda36d312..a79e9f093 100644 --- a/Makefile.drom-tpl +++ b/Makefile.drom-tpl @@ -19,7 +19,7 @@ all: build build: ./scripts/before.sh build - opam exec -- dune build!{build-profile} @install + $(DUNE) build!{build-profile} @install ./scripts/copy-bin.sh !{packages} ./scripts/after.sh build @@ -43,7 +43,7 @@ sphinx: doc-common odoc: doc-common mkdir -p ${ODOC_TARGET} ./scripts/before.sh odoc ${ODOC_TARGET} - opam exec -- dune build @doc + $(DUNE) build @doc rsync -auv --delete _build/default/_doc/_html/. ${ODOC_TARGET} ./scripts/after.sh odoc ${ODOC_TARGET} @@ -53,10 +53,10 @@ view: xdg-open file://$$(pwd)/_drom/docs/index.html ![fi] fmt: - opam exec -- dune build @fmt --auto-promote + $(DUNE) build @fmt --auto-promote fmt-check: - opam exec -- dune build @fmt + $(DUNE) build @fmt install: opam pin -y --no-action -k path . @@ -73,7 +73,7 @@ dev-deps: test: ./scripts/before.sh test - opam exec -- dune build @runtest + $(DUNE) build @runtest ./scripts/after.sh test clean: diff --git a/src/lsp/superbol-free/package.toml b/src/lsp/superbol-free/package.toml index 278348c54..ddf00e9c7 100644 --- a/src/lsp/superbol-free/package.toml +++ b/src/lsp/superbol-free/package.toml @@ -72,6 +72,7 @@ superbol_free_lib = "version" # static-clibs = "unix" [fields] dune-flags = "(:standard (:include linking.sexp))" +dune-stanzas = "(modes exe js)" # static-alpine-clibs = "zarith gmp" # static-macos-clibs = "zarith ${MACPORTS:-/usr/local/osxcross/macports/pkgs/opt/local}/lib/libgmp.a camlstr" static-macos-clibs = "camlstr bigstringaf_stubs cstruct_stubs" diff --git a/src/lsp/superbol_free_lib/package.toml b/src/lsp/superbol_free_lib/package.toml index 0717ae86e..5f6e7943a 100644 --- a/src/lsp/superbol_free_lib/package.toml +++ b/src/lsp/superbol_free_lib/package.toml @@ -61,7 +61,7 @@ cobol_typeck = "version" ez_file = ">=0.3" ez_cmdliner = "0.3.0" vscode-json = "version" -ez_api = "2.0" +ez_api = { version = "2.0", libname = "ez_api.encoding" } ez_toml = "version" # package tools dependencies