Skip to content

Commit 3f86b18

Browse files
authored
Move rescript/tools to OCaml (#855)
* move tools to ocaml code * update .vscodeignore * add script update version * more updates * remove ocamlformat dep * add tests * fix tests * some refactor * delete .bs.js files * update npm install and contributing.md * update tests * [skip ci]: update CONTRIBUTING.md
1 parent 0ec83cc commit 3f86b18

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+843
-339
lines changed

.github/workflows/ci.yml

+29-16
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,25 @@ jobs:
6868
# - run: opam pin add rescript-editor-analysis.dev . --no-action
6969
# - run: opam install . --deps-only --with-doc --with-test
7070

71-
- name: Build and test
71+
- name: Build
72+
run: opam exec -- make
73+
74+
- name: Test
7275
run: opam exec -- make test
73-
working-directory: analysis
7476

7577
# Also avoids artifacts upload permission loss:
7678
# https://github.com/actions/upload-artifact/tree/ee69f02b3dfdecd58bb31b4d133da38ba6fe3700#permission-loss
7779
- name: Compress files
7880
run: |
79-
cd analysis
8081
mkdir ${{matrix.artifact-folder}}
8182
mv rescript-editor-analysis.exe ${{matrix.artifact-folder}}
83+
mv rescript-tools.exe ${{matrix.artifact-folder}}
8284
tar -cvf binary.tar ${{matrix.artifact-folder}}
8385
8486
- uses: actions/upload-artifact@v3
8587
with:
8688
name: ${{matrix.os}}
87-
path: analysis/binary.tar
89+
path: binary.tar
8890

8991
package:
9092
needs: test
@@ -106,37 +108,51 @@ jobs:
106108
uses: actions/download-artifact@v3
107109
with:
108110
name: macos-latest
109-
path: ./server/analysis_binaries
111+
path: binaries
110112
- run: tar -xvf binary.tar
111-
working-directory: ./server/analysis_binaries
113+
working-directory: binaries
112114

113115
- name: Download MacOS ARM binary
114116
uses: actions/download-artifact@v3
115117
with:
116118
name: macos-arm
117-
path: ./server/analysis_binaries
119+
path: binaries
118120
- run: tar -xvf binary.tar
119-
working-directory: ./server/analysis_binaries
121+
working-directory: binaries
120122

121123
- name: Download Linux binary
122124
uses: actions/download-artifact@v3
123125
with:
124126
name: ubuntu-20.04
125-
path: ./server/analysis_binaries
127+
path: binaries
126128
- run: tar -xvf binary.tar
127-
working-directory: ./server/analysis_binaries
129+
working-directory: binaries
128130

129131
- name: Download Windows binary
130132
uses: actions/download-artifact@v3
131133
with:
132134
name: windows-latest
133-
path: ./server/analysis_binaries
135+
path: binaries
134136
- run: tar -xvf binary.tar
135-
working-directory: ./server/analysis_binaries
137+
working-directory: binaries
136138

137139
- name: Cleanup tar file
138140
run: rm binary.tar
139-
working-directory: ./server/analysis_binaries
141+
working-directory: binaries
142+
143+
- name: Move binaries to folders
144+
run: |
145+
declare -a platforms=("darwin" "darwinarm64" "linux" "win32")
146+
147+
for platform in "${platforms[@]}"; do
148+
mkdir server/analysis_binaries/"$platform"
149+
mv binaries/"$platform"/rescript-editor-analysis.exe server/analysis_binaries/"$platform"
150+
done
151+
152+
for platform in "${platforms[@]}"; do
153+
mkdir tools/binaries/"$platform"
154+
mv binaries/"$platform"/rescript-tools.exe tools/binaries/"$platform"
155+
done
140156
141157
- name: Store short commit SHA for filename
142158
id: vars
@@ -221,9 +237,6 @@ jobs:
221237
env:
222238
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
223239

224-
- name: Copy analysis binaries to tools folder
225-
run: cp -r server/analysis_binaries/* tools/analysis_binaries
226-
227240
- name: Build @rescript/tools package
228241
working-directory: tools
229242
run: |

.gitignore

+11-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22
out
33
node_modules
44
examples/*/lib
5+
56
analysis/tests/lib
67
analysis/tests/.bsb.lock
7-
analysis/_build
88
analysis/tests/.merlin
9-
analysis/rescript-editor-analysis.exe
10-
analysis/_opam
9+
1110
tools/node_modules
1211
tools/lib
13-
tools/**/*.bs.js
12+
tools/**/*.res.js
13+
tools/tests/node_modules
14+
tools/tests/lib
15+
16+
rescript-editor-analysis.exe
17+
rescript-tools.exe
18+
19+
_opam/
20+
_build/

analysis/.ocamlformat .ocamlformat

File renamed without changes.

.ocamlformat-ignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
analysis/vendor/compiler-libs-406/*
2+
analysis/vendor/res_outcome_printer/*

.vscode/settings.json

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"editor.insertSpaces": false,
3-
"tslint.enable": true,
4-
"typescript.tsc.autoDetect": "off",
5-
"typescript.preferences.quoteStyle": "single",
6-
"editor.codeActionsOnSave": {
7-
"source.fixAll.eslint": "explicit"
8-
},
9-
"ocaml.sandbox": {
10-
"kind": "opam",
11-
"switch": "4.14.0"
12-
}
2+
"editor.insertSpaces": false,
3+
"tslint.enable": true,
4+
"typescript.tsc.autoDetect": "off",
5+
"typescript.preferences.quoteStyle": "single",
6+
"editor.codeActionsOnSave": {
7+
"source.fixAll.eslint": true
8+
},
9+
"ocaml.sandbox": {
10+
"kind": "opam",
11+
"switch": "${workspaceFolder:rescript-vscode}"
12+
}
1313
}

.vscodeignore

+7
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,10 @@ contributing.md
88
server/node_modules/.bin
99
node_modules/.bin
1010
analysis/
11+
tools/
12+
scripts/
13+
dune-project
14+
analysis.opam
15+
tools.opam
16+
.ocamlformat
17+
.ocamlformat-ignore

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121

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

24+
#### :house: Internal
25+
26+
- Move `rescript-tools` to OCaml code and make `analysis` an library. https://github.com/rescript-lang/rescript-vscode/pull/855
27+
2428
## 1.34.0
2529

2630
#### :rocket: New Feature

CONTRIBUTING.md

+26-18
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,21 @@ Thanks for your interest. Below is an informal spec of how the plugin's server c
1010
│ └── src
1111
│ └── extension.ts // Language Client entry point
1212
├── analysis // Native binary powering hover, autocomplete, etc.
13-
│ ├── src
14-
── rescript-editor-analysis.exe // Dev-time analysis binary
13+
│ ├── src // Analysis library
14+
── bin // Analysis binary
1515
├── package.json // The extension manifest
16-
└── server // Language Server. Usable standalone
17-
├── src
18-
│ ├── server.ts // Language Server Module
19-
│ ├── cli.ts // LSP CLI
20-
└── analysis_binaries // Prod-time platform-specific analysis binaries
16+
├── server // Language Server. Usable standalone
17+
│ ├── src
18+
│ │ ├── server.ts // Language Server Module
19+
│ │ ├── cli.ts // LSP CLI
20+
│ └── analysis_binaries // Prod-time platform-specific analysis binaries
21+
│ ├── darwin
22+
│ ├── linux
23+
│ └── win32
24+
└── tools // ReScript Tools
25+
├── bin // OCaml Binary
26+
├── src // ReScript Tools library
27+
└── binaries // Prod-time platform-specific binaries
2128
├── darwin
2229
├── linux
2330
└── win32
@@ -27,9 +34,11 @@ Thanks for your interest. Below is an informal spec of how the plugin's server c
2734

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

30-
## Analysis Binary
37+
## OCaml Code
38+
39+
This is needed for the `analysis` and `tools` folder, which is native code.
3140

32-
This is needed for the `analysis` folder, which is native code.
41+
At the root:
3342

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

41-
# For IDE support, install the OCaml language server
42-
opam install ocaml-lsp-server
50+
# For IDE support, install the OCaml language server and OCaml Formatter
51+
opam install ocaml-lsp-server ocamlformat
4352
```
4453

4554
## Build & Run
4655

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

5059
## Test
5160

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

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

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

7281
## Change the Grammar
7382

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

97106
## General Coding Guidance
98107

99-
- `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`.
108+
- `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`.
100109
- This codebase stayed alive by not trying to babysit long-living processes. Be fast, call a binary and shut down.
101110

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

199208
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.
200-
2. Make sure @ryyppy is aware of your changes. He needs to sync them over to the vim plugin.
201-
3. Let CI build your version bump commit.
202-
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:
209+
2. Let CI build your version bump commit.
210+
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:
203211
- create a `rescript-vscode-<version-number>.vsix` file
204212
- publish that extension version to the VSCode marketplace
205213
- create an automatic release on GitHub
@@ -214,4 +222,4 @@ For beta releases, ask folks to use the pre-release version installable from the
214222

215223
## Releasing the `@rescript/tools` package
216224

217-
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`.
225+
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`.

Makefile

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
SHELL = /bin/bash
22

33
build:
4-
make -C analysis build
5-
6-
clean:
7-
make -C analysis clean
4+
dune build
5+
cp _build/install/default/bin/rescript-editor-analysis rescript-editor-analysis.exe
6+
cp _build/install/default/bin/rescript-tools rescript-tools.exe
87

98
test:
109
make -C analysis test
10+
make -C tools/tests test
11+
12+
clean:
13+
dune clean
14+
make -C analysis clean
15+
make -C tools/tests clean
1116

1217
format:
13-
make -C analysis format
18+
dune build @fmt --auto-promote
1419

1520
checkformat:
16-
make -C analysis checkformat
21+
dune build @fmt
1722

1823
.DEFAULT_GOAL := build
1924

analysis/rescript-vscode.opam analysis.opam

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
# This file is generated by dune, edit dune-project instead
22
opam-version: "2.0"
3-
synopsis: "ReScript vscode support"
4-
maintainer: ["Cristiano Calcagno"]
5-
authors: ["Cristiano Calcagno"]
3+
synopsis: "ReScript Analysis"
4+
maintainer: ["ReScript Team"]
5+
authors: ["ReScript Team"]
66
homepage: "https://github.com/rescript-lang/rescript-vscode"
77
bug-reports: "https://github.com/rescript-lang/rescript-vscode/issues"
88
depends: [
99
"ocaml" {>= "4.10"}
10-
"ocamlformat" {= "0.26.1"}
1110
"cppo" {= "1.6.9"}
12-
"reanalyze" {= "2.23.0"}
1311
"dune"
1412
]
1513
build: [

analysis/.ocamlformat-ignore

-2
This file was deleted.

analysis/.vscode/settings.json

-11
This file was deleted.

analysis/.vscode/tasks.json

-5
This file was deleted.

analysis/Makefile

+4-19
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,26 @@
11
SHELL = /bin/bash
22

3-
build-analysis-binary:
4-
rm -f rescript-editor-analysis.exe
5-
dune build
6-
cp _build/install/default/bin/rescript-editor-analysis rescript-editor-analysis.exe
7-
83
build-tests:
94
make -C tests build
105

116
build-reanalyze:
127
make -C reanalyze build
138

14-
build: build-analysis-binary build-reanalyze build-tests
9+
build: build-reanalyze build-tests
1510

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

19-
format:
20-
dune build @fmt --auto-promote
21-
22-
test-analysis-binary: build-analysis-binary
14+
test-analysis-binary:
2315
make -C tests test
2416

25-
test-reanalyze: build-analysis-binary
17+
test-reanalyze:
2618
make -C reanalyze test
2719

2820
test: test-analysis-binary test-reanalyze
2921

3022
clean:
31-
rm -f rescript-editor-analysis.exe
32-
dune clean
3323
make -C tests clean
3424
make -C reanalyze clean
3525

36-
checkformat:
37-
dune build @fmt
38-
39-
.DEFAULT_GOAL := build
40-
41-
.PHONY: build-analysis-binary build-reanalyze build-tests dce clean format test
26+
.PHONY: build-reanalyze build-tests dce clean test

0 commit comments

Comments
 (0)