Skip to content

Commit

Permalink
Included a js_of_ocaml version of superbol in the .vsix
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bclement-ocp committed Oct 27, 2023
1 parent 9faae1b commit e737563
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 37 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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}

Expand All @@ -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 .
Expand All @@ -73,7 +73,7 @@ dev-deps:

test:
./scripts/before.sh test
opam exec -- dune build @runtest
$(DUNE) build @runtest
./scripts/after.sh test

clean:
Expand Down
57 changes: 45 additions & 12 deletions Makefile.header
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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 \
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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`."
}
}
},
Expand Down
1 change: 1 addition & 0 deletions src/lsp/superbol-free/dune
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lsp/superbol_free_lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/lsp/superbol_free_lib/project.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/vscode/superbol-vscode-platform/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 20 additions & 8 deletions src/vscode/superbol-vscode-platform/superbol_languageclient.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))

0 comments on commit e737563

Please sign in to comment.