Skip to content
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

Included a js_of_ocaml version of superbol in the .vsix #93

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Makefile
nberth marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not _out/$(SERVER_PROJECT).bc.js as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I simply forgot :)

$(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`."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this conflicts with pending edits in #72 .

}
}
},
Expand Down
1 change: 1 addition & 0 deletions src/lsp/superbol-free/dune
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please investigate whether that can be achieved via fields of the corresponding package.toml. Same for superbol_free_lib/dune.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed the drom files. Running drom build generates a bunch of main.ml files everywhere tho, not sure what's up about that. Not included in this commit, in spite of drom "helpfully" (not at all) deciding to add its changes to the index.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might depend on drom's version. I typically use opam exec -- drom project to generated the files instead.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I, too, hate the way drom interacts with git. (Fabrice mentioned he welcomed PRs on drom, notably to disable auto-indexing).

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in this case there is a dune.drom-tpl to edit instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a change I made — drom modified this file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw something related to js_of_ocaml so I though it was edited manually. We should probably check those lines were not introduced on purpose.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should ask @ddeclerck they were introduced in a commit "fix cross-compilation" (09b9ce7)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dune.drom-tpl is based on https://github.com/OCamlPro/drom-share/blob/master/packages/js_program/dune_. I had to add it so I could add a missing !(package-dune-stanzas) (which comes from the package.toml file and disables compiling the VSCode extension when cross-compiling : js_of_ocaml is neither available nor needed in cross-compilation environments). Obviously, this is a temporary solution ; the template dune file should be modified in the aforementioned drom-share repository. If someone feels like contributing to drom.

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))

Loading