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

Move rescript/tools to OCaml #855

Merged
merged 17 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
45 changes: 29 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,25 @@ jobs:
# - run: opam pin add rescript-editor-analysis.dev . --no-action
# - run: opam install . --deps-only --with-doc --with-test

- name: Build and test
- name: Build
run: opam exec -- make

- name: Test
run: opam exec -- make test
working-directory: analysis

# Also avoids artifacts upload permission loss:
# https://github.com/actions/upload-artifact/tree/ee69f02b3dfdecd58bb31b4d133da38ba6fe3700#permission-loss
- name: Compress files
run: |
cd analysis
mkdir ${{matrix.artifact-folder}}
mv rescript-editor-analysis.exe ${{matrix.artifact-folder}}
mv rescript-tools.exe ${{matrix.artifact-folder}}
tar -cvf binary.tar ${{matrix.artifact-folder}}

- uses: actions/upload-artifact@v3
with:
name: ${{matrix.os}}
path: analysis/binary.tar
path: binary.tar

package:
needs: test
Expand All @@ -106,37 +108,51 @@ jobs:
uses: actions/download-artifact@v3
with:
name: macos-latest
path: ./server/analysis_binaries
path: binaries
- run: tar -xvf binary.tar
working-directory: ./server/analysis_binaries
working-directory: binaries

- name: Download MacOS ARM binary
uses: actions/download-artifact@v3
with:
name: macos-arm
path: ./server/analysis_binaries
path: binaries
- run: tar -xvf binary.tar
working-directory: ./server/analysis_binaries
working-directory: binaries

- name: Download Linux binary
uses: actions/download-artifact@v3
with:
name: ubuntu-20.04
path: ./server/analysis_binaries
path: binaries
- run: tar -xvf binary.tar
working-directory: ./server/analysis_binaries
working-directory: binaries

- name: Download Windows binary
uses: actions/download-artifact@v3
with:
name: windows-latest
path: ./server/analysis_binaries
path: binaries
- run: tar -xvf binary.tar
working-directory: ./server/analysis_binaries
working-directory: binaries

- name: Cleanup tar file
run: rm binary.tar
working-directory: ./server/analysis_binaries
working-directory: binaries

- name: Move binaries to folders
run: |
declare -a platforms=("darwin" "darwinarm64" "linux" "win32")

for platform in "${platforms[@]}"; do
mkdir server/analysis_binaries/"$platform"
mv binaries/"$platform"/rescript-editor-analysis.exe server/analysis_binaries/"$platform"
done

for platform in "${platforms[@]}"; do
mkdir tools/binaries/"$platform"
mv binaries/"$platform"/rescript-tools.exe tools/binaries/"$platform"
done

- name: Store short commit SHA for filename
id: vars
Expand Down Expand Up @@ -221,9 +237,6 @@ jobs:
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Copy analysis binaries to tools folder
run: cp -r server/analysis_binaries/* tools/analysis_binaries

- name: Build @rescript/tools package
working-directory: tools
run: |
Expand Down
15 changes: 11 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
out
node_modules
examples/*/lib

analysis/tests/lib
analysis/tests/.bsb.lock
analysis/_build
analysis/tests/.merlin
analysis/rescript-editor-analysis.exe
analysis/_opam

tools/node_modules
tools/lib
tools/**/*.bs.js
tools/**/*.res.js
tools/tests/node_modules
tools/tests/lib

rescript-editor-analysis.exe
rescript-tools.exe

_opam/
_build/
File renamed without changes.
2 changes: 2 additions & 0 deletions .ocamlformat-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
analysis/vendor/compiler-libs-406/*
analysis/vendor/res_outcome_printer/*
22 changes: 11 additions & 11 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"editor.insertSpaces": false,
"tslint.enable": true,
"typescript.tsc.autoDetect": "off",
"typescript.preferences.quoteStyle": "single",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"ocaml.sandbox": {
"kind": "opam",
"switch": "4.14.0"
}
"editor.insertSpaces": false,
"tslint.enable": true,
"typescript.tsc.autoDetect": "off",
"typescript.preferences.quoteStyle": "single",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"ocaml.sandbox": {
"kind": "opam",
"switch": "${workspaceFolder:rescript-vscode}"
}
}
7 changes: 7 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ contributing.md
server/node_modules/.bin
node_modules/.bin
analysis/
tools/
scripts/
dune-project
analysis.opam
tools.opam
.ocamlformat
.ocamlformat-ignore
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@

- More cases of not emitting `_` when completing in expressions. https://github.com/rescript-lang/rescript-vscode/pull/890

#### :house: Internal

- Move `rescript-tools` to OCaml code and make `analysis` an library. https://github.com/rescript-lang/rescript-vscode/pull/855

## 1.34.0

#### :rocket: New Feature
Expand Down
44 changes: 26 additions & 18 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ Thanks for your interest. Below is an informal spec of how the plugin's server c
│ └── src
│ └── extension.ts // Language Client entry point
├── analysis // Native binary powering hover, autocomplete, etc.
│ ├── src
── rescript-editor-analysis.exe // Dev-time analysis binary
│ ├── src // Analysis library
── bin // Analysis binary
├── package.json // The extension manifest
└── server // Language Server. Usable standalone
├── src
│ ├── server.ts // Language Server Module
│ ├── cli.ts // LSP CLI
└── analysis_binaries // Prod-time platform-specific analysis binaries
├── server // Language Server. Usable standalone
│ ├── src
│ │ ├── server.ts // Language Server Module
│ │ ├── cli.ts // LSP CLI
│ └── analysis_binaries // Prod-time platform-specific analysis binaries
│ ├── darwin
│ ├── linux
│ └── win32
└── tools // ReScript Tools
├── bin // OCaml Binary
├── src // ReScript Tools library
└── binaries // Prod-time platform-specific binaries
├── darwin
├── linux
└── win32
Expand All @@ -27,9 +34,11 @@ Thanks for your interest. Below is an informal spec of how the plugin's server c

- Run `npm install` at the root. This will also install the npm modules for both the `client` and `server` folders.

## Analysis Binary
## OCaml Code

This is needed for the `analysis` and `tools` folder, which is native code.

This is needed for the `analysis` folder, which is native code.
At the root:

```sh
# If you haven't created the switch, do it. OPAM(https://opam.ocaml.org)
Expand All @@ -38,14 +47,14 @@ opam switch 4.14.0 # can also create local switch with opam switch create . 4.14
# Install dev dependencies from OPAM
opam install . --deps-only

# For IDE support, install the OCaml language server
opam install ocaml-lsp-server
# For IDE support, install the OCaml language server and OCaml Formatter
opam install ocaml-lsp-server ocamlformat
```

## Build & Run

- `npm run compile`. You don't need this if you're developing this repo in VSCode. The compilation happens automatically in the background.
- `cd analysis && make`.
- `make`.

## Test

Expand All @@ -67,7 +76,7 @@ opam install ocaml-lsp-server

<img width="359" alt="image" src="https://user-images.githubusercontent.com/1909539/97448639-19db0800-18ee-11eb-875a-d17cd1b141d1.png">

- For the native analysis binary tests: `cd analysis && make test`.
- For the native analysis and tools binary tests: `make test`.

## Change the Grammar

Expand Down Expand Up @@ -96,7 +105,7 @@ We call a few binaries and it's tricky to call them properly cross-platform. Her

## General Coding Guidance

- `server/` is a standalone folder that can be vendored by e.g. Vim and Sublime Text. Keep it light, don't add deps unless absolutely necessarily, and don't accidentally use a runtime dep from the top level `package.json`.
- `server/` is a standalone LSP server. Keep it light, don't add deps unless absolutely necessarily, and don't accidentally use a runtime dep from the top level `package.json`.
- This codebase stayed alive by not trying to babysit long-living processes. Be fast, call a binary and shut down.

## Rough Description Of How The Plugin Works
Expand Down Expand Up @@ -197,9 +206,8 @@ We're happy to gather more resources over time here, including more in-depth get
_This below will automatically release the LSP package as well._

1. Bump the version to an _even minor_ version number in `package.json` and `server/package.json` and their lockfiles. It's very important that it's an even minor like `1.8.0`, and not `1.7.0`. This is because even minors are reserved for actual releases, and uneven minors for pre-releases. Commit and push the version bump.
2. Make sure @ryyppy is aware of your changes. He needs to sync them over to the vim plugin.
3. Let CI build your version bump commit.
4. Tag the commit with the version number (e.g. `git tag 1.6.0`) and push the tag (e.g. `git push origin 1.6.0`). Another build will trigger, which should automatically:
2. Let CI build your version bump commit.
3. Tag the commit with the version number (e.g. `git tag 1.6.0`) and push the tag (e.g. `git push origin 1.6.0`). Another build will trigger, which should automatically:
- create a `rescript-vscode-<version-number>.vsix` file
- publish that extension version to the VSCode marketplace
- create an automatic release on GitHub
Expand All @@ -214,4 +222,4 @@ For beta releases, ask folks to use the pre-release version installable from the

## Releasing the `@rescript/tools` package

The tools package is released by bumping the version in `tools/package.json`, running `npm i` in the `tools/` folder, and then pushing those changes with the commit message `publish tools`.
The tools package is released by bumping the version in `tools/package.json` and run `node scripts/updateVersion.js`, running `npm i` in the `tools/` folder, and then pushing those changes with the commit message `publish tools`.
17 changes: 11 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
SHELL = /bin/bash

build:
make -C analysis build

clean:
make -C analysis clean
dune build
cp _build/install/default/bin/rescript-editor-analysis rescript-editor-analysis.exe
cp _build/install/default/bin/rescript-tools rescript-tools.exe

test:
make -C analysis test
make -C tools/tests test

clean:
dune clean
make -C analysis clean
make -C tools/tests clean

format:
make -C analysis format
dune build @fmt --auto-promote

checkformat:
make -C analysis checkformat
dune build @fmt

.DEFAULT_GOAL := build

Expand Down
8 changes: 3 additions & 5 deletions analysis/rescript-vscode.opam → analysis.opam
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "ReScript vscode support"
maintainer: ["Cristiano Calcagno"]
authors: ["Cristiano Calcagno"]
synopsis: "ReScript Analysis"
maintainer: ["ReScript Team"]
authors: ["ReScript Team"]
homepage: "https://github.com/rescript-lang/rescript-vscode"
bug-reports: "https://github.com/rescript-lang/rescript-vscode/issues"
depends: [
"ocaml" {>= "4.10"}
"ocamlformat" {= "0.26.1"}
"cppo" {= "1.6.9"}
"reanalyze" {= "2.23.0"}
"dune"
]
build: [
Expand Down
2 changes: 0 additions & 2 deletions analysis/.ocamlformat-ignore

This file was deleted.

11 changes: 0 additions & 11 deletions analysis/.vscode/settings.json

This file was deleted.

5 changes: 0 additions & 5 deletions analysis/.vscode/tasks.json

This file was deleted.

23 changes: 4 additions & 19 deletions analysis/Makefile
Original file line number Diff line number Diff line change
@@ -1,41 +1,26 @@
SHELL = /bin/bash

build-analysis-binary:
rm -f rescript-editor-analysis.exe
dune build
cp _build/install/default/bin/rescript-editor-analysis rescript-editor-analysis.exe

build-tests:
make -C tests build

build-reanalyze:
make -C reanalyze build

build: build-analysis-binary build-reanalyze build-tests
build: build-reanalyze build-tests

dce: build-analysis-binary
opam exec reanalyze.exe -- -dce-cmt _build -suppress vendor

format:
dune build @fmt --auto-promote

test-analysis-binary: build-analysis-binary
test-analysis-binary:
make -C tests test

test-reanalyze: build-analysis-binary
test-reanalyze:
make -C reanalyze test

test: test-analysis-binary test-reanalyze

clean:
rm -f rescript-editor-analysis.exe
dune clean
make -C tests clean
make -C reanalyze clean

checkformat:
dune build @fmt

.DEFAULT_GOAL := build

.PHONY: build-analysis-binary build-reanalyze build-tests dce clean format test
.PHONY: build-reanalyze build-tests dce clean test
Loading