-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4fc0587
Showing
1,676 changed files
with
840,006 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains 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,7 @@ | ||
tests/lib | ||
tests/.bsb.lock | ||
_build | ||
tests/.merlin | ||
resgraph.exe | ||
_opam | ||
.DS_Store |
This file contains 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 @@ | ||
profile = default | ||
version = 0.22.4 | ||
|
||
field-space = tight-decl | ||
break-cases = toplevel | ||
module-item-spacing = preserve | ||
cases-exp-indent = 2 | ||
space-around-arrays = false | ||
space-around-lists = false | ||
space-around-records = false | ||
space-around-variants = false |
This file contains 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 @@ | ||
vendor/compiler-libs-406/* | ||
vendor/res_outcome_printer/* |
This file contains 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,6 @@ | ||
{ | ||
"ocaml.sandbox": { | ||
"kind": "opam", | ||
"switch": "4.14.0" | ||
} | ||
} |
This file contains 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,35 @@ | ||
SHELL = /bin/bash | ||
|
||
build-resgraph-binary: | ||
rm -f resgraph.exe | ||
dune build | ||
cp _build/install/default/bin/resgraph resgraph.exe | ||
|
||
build-tests: | ||
make -C tests build | ||
|
||
build: build-resgraph-binary build-tests | ||
|
||
dce: build-resgraph-binary | ||
opam exec reanalyze.exe -- -dce-cmt _build -suppress vendor | ||
|
||
format: | ||
dune build @fmt --auto-promote | ||
|
||
test-resgraph-binary: build-resgraph-binary | ||
make -C tests test | ||
|
||
test: test-resgraph-binary | ||
|
||
clean: | ||
rm -f resgraph.exe | ||
dune clean | ||
make -C tests clean | ||
make -C reanalyze clean | ||
|
||
checkformat: | ||
dune build @fmt | ||
|
||
.DEFAULT_GOAL := build | ||
|
||
.PHONY: build-resgraph-binary build-tests dce clean format test |
This file contains 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 @@ | ||
# ResGraph |
This file contains 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 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 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,25 @@ | ||
(lang dune 2.3) | ||
|
||
(generate_opam_files true) | ||
|
||
(authors "Gabriel Nordeborn") | ||
|
||
(maintainers "Gabriel Nordeborn") | ||
|
||
(homepage "https://github.com/rescript-lang/rescript-vscode") | ||
|
||
(bug_reports "https://github.com/rescript-lang/rescript-vscode/issues") | ||
|
||
(package | ||
(name resgraph) | ||
(synopsis "ResGraph") | ||
(depends | ||
(ocaml | ||
(>= 4.10)) | ||
(ocamlformat | ||
(= 0.22.4)) | ||
(cppo | ||
(= 1.6.9)) | ||
(reanalyze | ||
(= 2.23.0)) | ||
dune)) |
Binary file not shown.
This file contains 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,28 @@ | ||
# This file is generated by dune, edit dune-project instead | ||
opam-version: "2.0" | ||
synopsis: "ResGraph" | ||
maintainer: ["Gabriel Nordeborn"] | ||
authors: ["Gabriel Nordeborn"] | ||
homepage: "https://github.com/rescript-lang/rescript-vscode" | ||
bug-reports: "https://github.com/rescript-lang/rescript-vscode/issues" | ||
depends: [ | ||
"ocaml" {>= "4.10"} | ||
"ocamlformat" {= "0.22.4"} | ||
"cppo" {= "1.6.9"} | ||
"reanalyze" {= "2.23.0"} | ||
"dune" | ||
] | ||
build: [ | ||
["dune" "subst"] {pinned} | ||
[ | ||
"dune" | ||
"build" | ||
"-p" | ||
name | ||
"-j" | ||
jobs | ||
"@install" | ||
"@runtest" {with-test} | ||
"@doc" {with-doc} | ||
] | ||
] |
This file contains 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,24 @@ | ||
let namespacedName namespace name = | ||
match namespace with | ||
| None -> name | ||
| Some namespace -> name ^ "-" ^ namespace | ||
|
||
let ( /+ ) = Filename.concat | ||
|
||
let getBsPlatformDir rootPath = | ||
let result = | ||
ModuleResolution.resolveNodeModulePath ~startPath:rootPath "rescript" | ||
in | ||
match result with | ||
| Some path -> Some path | ||
| None -> | ||
let message = "rescript could not be found" in | ||
Log.log message; | ||
None | ||
|
||
let getLibBs root = Files.ifExists (root /+ "lib" /+ "bs") | ||
|
||
let getStdlib base = | ||
match getBsPlatformDir base with | ||
| None -> None | ||
| Some bsPlatformDir -> Some (bsPlatformDir /+ "lib" /+ "ocaml") |
This file contains 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,3 @@ | ||
let supportsSnippets = ref false | ||
|
||
let debugFollowCtxPath = ref false |
This file contains 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,99 @@ | ||
let help = | ||
{| | ||
**Private CLI For rescript-vscode usage only** | ||
|
||
API examples: | ||
./resgraph.exe completion src/MyFile.res 0 4 currentContent.res true | ||
./resgraph.exe definition src/MyFile.res 9 3 | ||
./resgraph.exe typeDefinition src/MyFile.res 9 3 | ||
./resgraph.exe documentSymbol src/Foo.res | ||
./resgraph.exe hover src/MyFile.res 10 2 true | ||
./resgraph.exe references src/MyFile.res 10 2 | ||
./resgraph.exe rename src/MyFile.res 10 2 foo | ||
./resgraph.exe diagnosticSyntax src/MyFile.res | ||
./resgraph.exe inlayHint src/MyFile.res 0 3 25 | ||
./resgraph.exe codeLens src/MyFile.res | ||
|
||
Dev-time examples: | ||
./resgraph.exe dump src/MyFile.res src/MyFile2.res | ||
./resgraph.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. | ||
|
||
./resgraph.exe completion src/MyFile.res 0 4 current.res | ||
|
||
definition: get definition for item in MyFile.res at line 10 column 2: | ||
|
||
./resgraph.exe definition src/MyFile.res 10 2 | ||
|
||
typeDefinition: get type definition for item in MyFile.res at line 10 column 2: | ||
|
||
./resgraph.exe typeDefinition src/MyFile.res 10 2 | ||
|
||
documentSymbol: get all symbols declared in MyFile.res | ||
|
||
./resgraph.exe documentSymbol src/MyFile.res | ||
|
||
hover: get inferred type for MyFile.res at line 10 column 2 (supporting markdown links): | ||
|
||
./resgraph.exe hover src/MyFile.res 10 2 true | ||
|
||
references: get all references to item in MyFile.res at line 10 column 2: | ||
|
||
./resgraph.exe references src/MyFile.res 10 2 | ||
|
||
rename: rename all appearances of item in MyFile.res at line 10 column 2 with foo: | ||
|
||
./resgraph.exe rename src/MyFile.res 10 2 foo | ||
|
||
semanticTokens: return token semantic highlighting info for MyFile.res | ||
|
||
./resgraph.exe semanticTokens src/MyFile.res | ||
|
||
createInterface: print to stdout the interface file for src/MyFile.res | ||
|
||
./resgraph.exe createInterface src/MyFile.res lib/bs/src/MyFile.cmi | ||
|
||
format: print to stdout the formatted version of the provided file | ||
|
||
./resgraph.exe format src/MyFile.res | ||
|
||
diagnosticSyntax: print to stdout diagnostic for syntax | ||
|
||
./resgraph.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 | ||
|
||
./resgraph.exe inlayHint src/MyFile.res 0 3 25 | ||
|
||
codeLens: get all code lens entries for file src/MyFile.res | ||
|
||
./resgraph.exe codeLens src/MyFile.res | ||
|
||
signatureHelp: get signature help if available for position at line 10 column 2 in src/MyFile.res | ||
|
||
./resgraph.exe signatureHelp src/MyFile.res 10 2 | ||
|
||
test: run tests specified by special comments in file src/MyFile.res | ||
|
||
./resgraph.exe test src/src/MyFile.res | ||
|} | ||
|
||
let main () = | ||
match Array.to_list Sys.argv with | ||
| [_; "generate-schema"; path] -> GenerateSchema.generateSchema ~path ~debug:false | ||
| [_; "test"; path] -> | ||
Cfg.supportsSnippets := true; | ||
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 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,36 @@ | ||
open SharedTypes | ||
|
||
let fullForCmt ~moduleName ~package ~uri cmt = | ||
match Shared.tryReadCmt cmt with | ||
| None -> None | ||
| Some infos -> | ||
let file = ProcessCmt.fileForCmtInfos ~moduleName ~uri infos in | ||
let extra = ProcessExtra.getExtra ~file ~infos in | ||
Some {file; extra; package} | ||
|
||
let fullFromUri ~uri = | ||
let path = Uri.toPath uri in | ||
match Packages.getPackage ~uri with | ||
| None -> None | ||
| Some package -> ( | ||
let moduleName = | ||
BuildSystem.namespacedName package.namespace (FindFiles.getName path) | ||
in | ||
match Hashtbl.find_opt package.pathsForModule moduleName with | ||
| Some paths -> | ||
let cmt = getCmtPath ~uri paths in | ||
fullForCmt ~moduleName ~package ~uri cmt | ||
| None -> | ||
prerr_endline ("can't find module " ^ moduleName); | ||
None) | ||
|
||
let fullsFromModule ~package ~moduleName = | ||
if Hashtbl.mem package.pathsForModule moduleName then | ||
let paths = Hashtbl.find package.pathsForModule moduleName in | ||
let uris = getUris paths in | ||
uris |> List.filter_map (fun uri -> fullFromUri ~uri) | ||
else [] | ||
|
||
let loadFullCmtFromPath ~path = | ||
let uri = Uri.fromPath path in | ||
fullFromUri ~uri |
This file contains 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,54 @@ | ||
let test ~path = | ||
Uri.stripPath := true; | ||
match Files.readFile path with | ||
| None -> assert false | ||
| Some text -> | ||
let lines = text |> String.split_on_char '\n' in | ||
let processLine i line = | ||
let createCurrentFile () = | ||
let currentFile, cout = Filename.open_temp_file "def" "txt" in | ||
let removeLineComment l = | ||
let len = String.length l in | ||
let rec loop i = | ||
if i + 2 <= len && l.[i] = '/' && l.[i + 1] = '/' then Some (i + 2) | ||
else if i + 2 < len && l.[i] = ' ' then loop (i + 1) | ||
else None | ||
in | ||
match loop 0 with | ||
| None -> l | ||
| Some indexAfterComment -> | ||
String.make indexAfterComment ' ' | ||
^ String.sub l indexAfterComment (len - indexAfterComment) | ||
in | ||
lines | ||
|> List.iteri (fun j l -> | ||
let lineToOutput = | ||
if j == i - 1 then removeLineComment l else l | ||
in | ||
Printf.fprintf cout "%s\n" lineToOutput); | ||
close_out cout; | ||
currentFile | ||
in | ||
if Str.string_match (Str.regexp "^ *//[ ]*\\^") line 0 then | ||
let matched = Str.matched_string line in | ||
let len = line |> String.length in | ||
let mlen = String.length matched in | ||
let rest = String.sub line mlen (len - mlen) in | ||
let line = i - 1 in | ||
let col = mlen - 1 in | ||
if mlen >= 3 then ( | ||
(match String.sub rest 0 3 with | ||
| "db+" -> Log.verbose := true | ||
| "db-" -> Log.verbose := false | ||
| "gen" -> GenerateSchema.generateSchema ~path ~debug:true | ||
| "ast" -> | ||
print_endline | ||
("Dump AST " ^ path ^ " " ^ string_of_int line ^ ":" | ||
^ string_of_int col); | ||
let currentFile = createCurrentFile () in | ||
DumpAst.dump ~pos:(line, col) ~currentFile; | ||
Sys.remove currentFile | ||
| _ -> ()); | ||
print_newline ()) | ||
in | ||
lines |> List.iteri processLine |
Oops, something went wrong.