-
Notifications
You must be signed in to change notification settings - Fork 468
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
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 6904577
Add package "analysis" from rescript-vscode repo
cknitt 3fceca8
Analysis: remove vendored libs that are already in the compiler repo
cknitt dbd577b
Add Tast_iterator module from rescript-vscode repo
cknitt e3acfb1
Remove class stuff from Tast_iterator
cknitt 0716c1f
Format Tast_iterator
cknitt 0b82fa5
Fix DeadValue.ml
cknitt 23502b5
No more Config.uncurried
cknitt 20de8dd
Analysis: use default print width instead of taking it from syntax cli
cknitt ede3dba
Make pexp_attributes mutable
cknitt 3cdce12
Add package "tools" from rescript-vscode repo
cknitt a764250
Format OCaml code
cknitt 8c76c29
Mark Res_multi_printer.default_print_width as live
cknitt df18fa1
Format
cknitt ba56a9e
Do not check in tools/analysis test artifacts
cknitt 12df921
Add rescript-editor-analysis and rescript-tools to rescript npm package
cknitt c8c627e
Fix path for analysis/tools binaries in test scripts
cknitt 7f48594
Run analysis tests in CI
cknitt 6426d79
analysis: get rid of PervasivesU
cknitt d023ea2
Nullable is now @unboxed
cknitt a8e787a
More pervasives
cknitt ec6fc9c
Analysis tests: use rescript from this repo and adapt
cknitt 85e1c76
Output changes that are ok
cknitt e242851
Tools tests: use rescript from this repo
cknitt 459d60b
commit OK changes to analysis output
zth aea019b
commit more OK changes to test output
zth 166bca7
get CodeLens to a good enough state
zth 77562e3
fix jsx prop completion broken by first class regexp literal support
zth 490e341
use predef paths so weird type lookups do not happen
zth 17e0e6c
commit OK change
zth ef14388
commit OK output
zth e3233f9
Fix gitignore
cknitt a405293
commit OK output (JSON type changes)
cknitt 1067261
Do not run analysis tests on Windows
cknitt dd779f8
Add opam exec
cknitt 01600b1
print module name instead of full file name in debug statement
zth fd90205
dont use deprecated functions
zth 751d4f9
update generic jsx transform test
zth a47085e
update incremental typechecking test
zth 2a91755
Fix uppercase exotic idents
cknitt 908b54e
Don't run analysis tests on Linux ARM
cknitt fa39d1c
Move tools and analysis tests to tests folder
cknitt ac5f8b0
CHANGELOG
cknitt f7ed5b8
Add rescript-tools cli wrapper script
cknitt 476bdaa
Remove obsolete Makefile
cknitt 702458a
Ship RescriptTools module with the rescript npm package
cknitt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
] | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/`. | ||
|
||
## 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). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
lib | ||
.merlin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.