Skip to content

Move rescript-editor-analysis and rescript-tools into compiler repo #7000

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

Merged
merged 46 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
6c40788
Dune: explicitly set package to "rescript" before adding more packages
cknitt Sep 1, 2024
6904577
Add package "analysis" from rescript-vscode repo
cknitt Sep 1, 2024
3fceca8
Analysis: remove vendored libs that are already in the compiler repo
cknitt Sep 1, 2024
dbd577b
Add Tast_iterator module from rescript-vscode repo
cknitt Sep 1, 2024
e3acfb1
Remove class stuff from Tast_iterator
cknitt Sep 1, 2024
0716c1f
Format Tast_iterator
cknitt Oct 31, 2024
0b82fa5
Fix DeadValue.ml
cknitt Sep 1, 2024
23502b5
No more Config.uncurried
cknitt Sep 1, 2024
20de8dd
Analysis: use default print width instead of taking it from syntax cli
cknitt Sep 1, 2024
ede3dba
Make pexp_attributes mutable
cknitt Nov 1, 2024
3cdce12
Add package "tools" from rescript-vscode repo
cknitt Sep 1, 2024
a764250
Format OCaml code
cknitt Sep 1, 2024
8c76c29
Mark Res_multi_printer.default_print_width as live
cknitt Sep 1, 2024
df18fa1
Format
cknitt Oct 31, 2024
ba56a9e
Do not check in tools/analysis test artifacts
cknitt Nov 1, 2024
12df921
Add rescript-editor-analysis and rescript-tools to rescript npm package
cknitt Nov 2, 2024
c8c627e
Fix path for analysis/tools binaries in test scripts
cknitt Nov 2, 2024
7f48594
Run analysis tests in CI
cknitt Nov 2, 2024
6426d79
analysis: get rid of PervasivesU
cknitt Nov 2, 2024
d023ea2
Nullable is now @unboxed
cknitt Nov 2, 2024
a8e787a
More pervasives
cknitt Nov 2, 2024
ec6fc9c
Analysis tests: use rescript from this repo and adapt
cknitt Nov 2, 2024
85e1c76
Output changes that are ok
cknitt Nov 2, 2024
e242851
Tools tests: use rescript from this repo
cknitt Nov 2, 2024
459d60b
commit OK changes to analysis output
zth Nov 10, 2024
aea019b
commit more OK changes to test output
zth Nov 10, 2024
166bca7
get CodeLens to a good enough state
zth Nov 10, 2024
77562e3
fix jsx prop completion broken by first class regexp literal support
zth Nov 10, 2024
490e341
use predef paths so weird type lookups do not happen
zth Nov 10, 2024
17e0e6c
commit OK change
zth Nov 10, 2024
ef14388
commit OK output
zth Nov 10, 2024
e3233f9
Fix gitignore
cknitt Nov 10, 2024
a405293
commit OK output (JSON type changes)
cknitt Nov 10, 2024
1067261
Do not run analysis tests on Windows
cknitt Nov 10, 2024
dd779f8
Add opam exec
cknitt Nov 10, 2024
01600b1
print module name instead of full file name in debug statement
zth Nov 10, 2024
fd90205
dont use deprecated functions
zth Nov 10, 2024
751d4f9
update generic jsx transform test
zth Nov 10, 2024
a47085e
update incremental typechecking test
zth Nov 10, 2024
2a91755
Fix uppercase exotic idents
cknitt Nov 10, 2024
908b54e
Don't run analysis tests on Linux ARM
cknitt Nov 10, 2024
fa39d1c
Move tools and analysis tests to tests folder
cknitt Nov 11, 2024
ac5f8b0
CHANGELOG
cknitt Nov 11, 2024
f7ed5b8
Add rescript-tools cli wrapper script
cknitt Nov 11, 2024
476bdaa
Remove obsolete Makefile
cknitt Nov 11, 2024
702458a
Ship RescriptTools module with the rescript npm package
cknitt Nov 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ jobs:
- name: Check for diffs in tests folder
run: git diff --ignore-cr-at-eol --exit-code tests

- name: Run analysis / tools tests
if: runner.os != 'Windows' && matrix.os != 'buildjet-2vcpu-ubuntu-2204-arm'
run: opam exec -- make -C tests/analysis_tests test && make -C tests/tools_tests test

- name: Run gentype tests
if: runner.os != 'Windows'
run: make -C tests/gentype_tests/typescript-react-example clean test
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,8 @@ playground/compiler.js

rewatch/target/
rewatch/rewatch

tests/tools_tests/**/*.res.js
tests/tools_tests/lib
tests/analysis_tests*/lib
tests/analysis_tests/**/*.bs.js
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
- Introduce "Unified operators" for arithmetic operators (`+`, `-`, `*`, `/`, `mod`). https://github.com/rescript-lang/rescript-compiler/pull/7057
- Add remainder (`%`, aka modulus) operator. https://github.com/rescript-lang/rescript-compiler/pull/7152


#### :bug: Bug fix

- Fix and clean up boolean and/or optimizations. https://github.com/rescript-lang/rescript-compiler/pull/7134 https://github.com/rescript-lang/rescript-compiler/pull/7151

#### :nail_care: Polish

- Improve code generation for pattern matching of untagged variants. https://github.com/rescript-lang/rescript-compiler/pull/7128
- Improve negation handling in combination with and/or to simplify generated code (especially coming out of pattern matching). https://github.com/rescript-lang/rescript-compiler/pull/7138
- optimize JavaScript code generation by using x == null checks and improving type-based optimizations for string/number literals. https://github.com/rescript-lang/rescript-compiler/pull/7141
Expand All @@ -30,6 +31,9 @@
- Further improve boolean optimizations. https://github.com/rescript-lang/rescript-compiler/pull/7149
- Simplify code generated for conditionals. https://github.com/rescript-lang/rescript-compiler/pull/7151

#### :house: Internal

- Move rescript-editor-analysis and rescript-tools into compiler repo. https://github.com/rescript-lang/rescript-compiler/pull/7000

# 12.0.0-alpha.4

Expand Down Expand Up @@ -61,6 +65,7 @@
- Fix genType JSX component compilation. https://github.com/rescript-lang/rescript-compiler/pull/7107

#### :nail_care: Polish

- Add some context to error message for unused variables. https://github.com/rescript-lang/rescript-compiler/pull/7050
- Improve error message when passing `children` prop to a component that doesn't accept it. https://github.com/rescript-lang/rescript-compiler/pull/7044
- Improve error messages for pattern matching on option vs non-option, and vice versa. https://github.com/rescript-lang/rescript-compiler/pull/7035
Expand All @@ -71,7 +76,6 @@
- Provide additional context in error message when `unit` is expected. https://github.com/rescript-lang/rescript-compiler/pull/7045
- Improve error message when passing an object where a record is expected. https://github.com/rescript-lang/rescript-compiler/pull/7101


#### :house: Internal

- Remove uncurried flag from bsb. https://github.com/rescript-lang/rescript-compiler/pull/7049
Expand Down
27 changes: 27 additions & 0 deletions analysis.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "ReScript Analysis"
maintainer: ["Hongbo Zhang <[email protected]>" "Cristiano Calcagno"]
authors: ["Hongbo Zhang <[email protected]>"]
license: "LGPL-3.0-or-later"
homepage: "https://github.com/rescript-lang/rescript-compiler"
bug-reports: "https://github.com/rescript-lang/rescript-compiler/issues"
depends: [
"ocaml" {>= "4.10"}
"cppo" {= "1.6.9"}
"dune"
]
build: [
["dune" "subst"] {pinned}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
26 changes: 26 additions & 0 deletions analysis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Analysis Library and Binary

This subfolder builds a private command line binary used by the plugin to power a few functionalities such as jump to definition, hover and autocomplete.

The binary reads the `.cmt` and `.cmti` files and analyses them.

For installation & build instructions, see the main CONTRIBUTING.md.

## Overview

See main CONTRIBUTING.md's repo structure. Additionally, `examples/` is a convenience debugging repo. Check out `test.sh` (invoked through `make test`) to see the snapshots testing workflow stored in `tests/`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess changes to CONTRIBUTING are coming in a separate PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, still some stuff to clean up, and also to move/add to the root Makefile.


## Usage

At root:
```sh
./rescript-editor-analysis.exe --help

# or

dune exec -- rescript-editor-analysis --help
```

## History

This project is based on a fork of [Reason Language Server](https://github.com/jaredly/reason-language-server).
11 changes: 11 additions & 0 deletions analysis/bin/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(env
(static
(flags
(:standard -ccopt -static))))

(executable
(public_name rescript-editor-analysis)
(package analysis)
(modes byte exe)
(name main)
(libraries analysis))
218 changes: 218 additions & 0 deletions analysis/bin/main.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
open Analysis

let help =
{|
**Private CLI For rescript-vscode usage only**

API examples:
./rescript-editor-analysis.exe completion src/MyFile.res 0 4 currentContent.res true
./rescript-editor-analysis.exe definition src/MyFile.res 9 3
./rescript-editor-analysis.exe typeDefinition src/MyFile.res 9 3
./rescript-editor-analysis.exe documentSymbol src/Foo.res
./rescript-editor-analysis.exe hover src/MyFile.res 10 2 true
./rescript-editor-analysis.exe references src/MyFile.res 10 2
./rescript-editor-analysis.exe rename src/MyFile.res 10 2 foo
./rescript-editor-analysis.exe diagnosticSyntax src/MyFile.res
./rescript-editor-analysis.exe inlayHint src/MyFile.res 0 3 25
./rescript-editor-analysis.exe codeLens src/MyFile.res

Dev-time examples:
./rescript-editor-analysis.exe dump src/MyFile.res src/MyFile2.res
./rescript-editor-analysis.exe test src/MyFile.res

Note: positions are zero-indexed (start at 0 0), following LSP.
https://microsoft.github.io/language-server-protocol/specification#position

Options:
completion: compute autocomplete for MyFile.res at line 0 and column 4,
where MyFile.res is being edited and the editor content is in file current.res.

./rescript-editor-analysis.exe completion src/MyFile.res 0 4 current.res

definition: get definition for item in MyFile.res at line 10 column 2:

./rescript-editor-analysis.exe definition src/MyFile.res 10 2

typeDefinition: get type definition for item in MyFile.res at line 10 column 2:

./rescript-editor-analysis.exe typeDefinition src/MyFile.res 10 2

documentSymbol: get all symbols declared in MyFile.res

./rescript-editor-analysis.exe documentSymbol src/MyFile.res

hover: get inferred type for MyFile.res at line 10 column 2 (supporting markdown links):

./rescript-editor-analysis.exe hover src/MyFile.res 10 2 true

references: get all references to item in MyFile.res at line 10 column 2:

./rescript-editor-analysis.exe references src/MyFile.res 10 2

rename: rename all appearances of item in MyFile.res at line 10 column 2 with foo:

./rescript-editor-analysis.exe rename src/MyFile.res 10 2 foo

semanticTokens: return token semantic highlighting info for MyFile.res

./rescript-editor-analysis.exe semanticTokens src/MyFile.res

createInterface: print to stdout the interface file for src/MyFile.res

./rescript-editor-analysis.exe createInterface src/MyFile.res lib/bs/src/MyFile.cmi

format: print to stdout the formatted version of the provided file

./rescript-editor-analysis.exe format src/MyFile.res

diagnosticSyntax: print to stdout diagnostic for syntax

./rescript-editor-analysis.exe diagnosticSyntax src/MyFile.res

inlayHint: get all inlay Hint between line 0 and 3 declared in MyFile.res. Last argument is maximum of character length for inlay hints

./rescript-editor-analysis.exe inlayHint src/MyFile.res 0 3 25

codeLens: get all code lens entries for file src/MyFile.res

./rescript-editor-analysis.exe codeLens src/MyFile.res

signatureHelp: get signature help if available for position at line 10 column 2 in src/MyFile.res

./rescript-editor-analysis.exe signatureHelp src/MyFile.res 10 2

test: run tests specified by special comments in file src/MyFile.res

./rescript-editor-analysis.exe test src/src/MyFile.res
|}

let main () =
let args = Array.to_list Sys.argv in
let debugLevel, args =
match args with
| _ :: "debug-dump" :: logLevel :: rest ->
( (match logLevel with
| "verbose" -> Debug.Verbose
| "regular" -> Regular
| _ -> Off),
"dummy" :: rest )
| args -> (Off, args)
in
Debug.debugLevel := debugLevel;
let debug = debugLevel <> Debug.Off in
let printHeaderInfo path line col =
if debug then
Printf.printf "Debug level: %s\n%s:%s-%s\n\n"
(match debugLevel with
| Debug.Verbose -> "verbose"
| Regular -> "regular"
| Off -> "off")
path line col
in
match args with
| [_; "cache-project"; rootPath] -> (
Cfg.readProjectConfigCache := false;
let uri = Uri.fromPath rootPath in
match Packages.getPackage ~uri with
| Some package -> Cache.cacheProject package
| None -> print_endline "\"ERR\"")
| [_; "cache-delete"; rootPath] -> (
Cfg.readProjectConfigCache := false;
let uri = Uri.fromPath rootPath in
match Packages.findRoot ~uri (Hashtbl.create 0) with
| Some (`Bs rootPath) -> (
match BuildSystem.getLibBs rootPath with
| None -> print_endline "\"ERR\""
| Some libBs ->
Cache.deleteCache (Cache.targetFileFromLibBs libBs);
print_endline "\"OK\"")
| _ -> print_endline "\"ERR: Did not find root \"")
| [_; "completion"; path; line; col; currentFile] ->
printHeaderInfo path line col;
Commands.completion ~debug ~path
~pos:(int_of_string line, int_of_string col)
~currentFile
| [_; "completionResolve"; path; modulePath] ->
Commands.completionResolve ~path ~modulePath
| [_; "definition"; path; line; col] ->
Commands.definition ~path
~pos:(int_of_string line, int_of_string col)
~debug
| [_; "typeDefinition"; path; line; col] ->
Commands.typeDefinition ~path
~pos:(int_of_string line, int_of_string col)
~debug
| [_; "documentSymbol"; path] -> DocumentSymbol.command ~path
| [_; "hover"; path; line; col; currentFile; supportsMarkdownLinks] ->
Commands.hover ~path
~pos:(int_of_string line, int_of_string col)
~currentFile ~debug
~supportsMarkdownLinks:
(match supportsMarkdownLinks with
| "true" -> true
| _ -> false)
| [
_; "signatureHelp"; path; line; col; currentFile; allowForConstructorPayloads;
] ->
Commands.signatureHelp ~path
~pos:(int_of_string line, int_of_string col)
~currentFile ~debug
~allowForConstructorPayloads:
(match allowForConstructorPayloads with
| "true" -> true
| _ -> false)
| [_; "inlayHint"; path; line_start; line_end; maxLength] ->
Commands.inlayhint ~path
~pos:(int_of_string line_start, int_of_string line_end)
~maxLength ~debug
| [_; "codeLens"; path] -> Commands.codeLens ~path ~debug
| [_; "codeAction"; path; startLine; startCol; endLine; endCol; currentFile]
->
Commands.codeAction ~path
~startPos:(int_of_string startLine, int_of_string startCol)
~endPos:(int_of_string endLine, int_of_string endCol)
~currentFile ~debug
| [_; "codemod"; path; line; col; typ; hint] ->
let typ =
match typ with
| "add-missing-cases" -> Codemod.AddMissingCases
| _ -> raise (Failure "unsupported type")
in
let res =
Codemod.transform ~path
~pos:(int_of_string line, int_of_string col)
~debug ~typ ~hint
|> Json.escape
in
Printf.printf "\"%s\"" res
| [_; "diagnosticSyntax"; path] -> Commands.diagnosticSyntax ~path
| _ :: "reanalyze" :: _ ->
let len = Array.length Sys.argv in
for i = 1 to len - 2 do
Sys.argv.(i) <- Sys.argv.(i + 1)
done;
Sys.argv.(len - 1) <- "";
Reanalyze.cli ()
| [_; "references"; path; line; col] ->
Commands.references ~path
~pos:(int_of_string line, int_of_string col)
~debug
| [_; "rename"; path; line; col; newName] ->
Commands.rename ~path
~pos:(int_of_string line, int_of_string col)
~newName ~debug
| [_; "semanticTokens"; currentFile] ->
SemanticTokens.semanticTokens ~currentFile
| [_; "createInterface"; path; cmiFile] ->
Printf.printf "\"%s\""
(Json.escape (CreateInterface.command ~path ~cmiFile))
| [_; "format"; path] ->
Printf.printf "\"%s\"" (Json.escape (Commands.format ~path))
| [_; "test"; path] -> Commands.test ~path
| args when List.mem "-h" args || List.mem "--help" args -> prerr_endline help
| _ ->
prerr_endline help;
exit 1
;;

main ()
16 changes: 16 additions & 0 deletions analysis/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(dirs bin src reanalyze vendor)

(env
(dev
(env-vars
(CPPO_FLAGS -U=RELEASE)))
(release
(env-vars
(CPPO_FLAGS -D=RELEASE))
(ocamlopt_flags
(:standard -O3 -unbox-closures)))
(static
(env-vars
(CPPO_FLAGS -D=RELEASE))
(ocamlopt_flags
(:standard -O3 -unbox-closures))))
2 changes: 2 additions & 0 deletions analysis/examples/example-project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib
.merlin
14 changes: 14 additions & 0 deletions analysis/examples/example-project/bsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "tryit",
"sources": "src",
"bsc-flags": ["-bs-super-errors", "-open Belt"],
"warnings": {
"number": "-32-26-27-33"
},
"bs-dependencies": ["reason-react"],
"reason": { "react-jsx": 3 },
"namespace": "my-namespace",
"reanalyze": {
"analysis": ["dce", "exception"]
}
}
16 changes: 16 additions & 0 deletions analysis/examples/example-project/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading