Skip to content

Commit 2b17ba8

Browse files
committed
Merge branch 'master' into move-tools-to-ocaml
2 parents 70a6aa7 + a5d252c commit 2b17ba8

37 files changed

+430
-108
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,20 @@
1212
1313
## master
1414

15+
## 1.30.0
16+
17+
#### :rocket: New Feature
18+
19+
- If interface file exists, ask if it should be overwritten. https://github.com/rescript-lang/rescript-vscode/pull/865
20+
1521
#### :bug: Bug Fix
1622

23+
- Proper default for `"uncurried"` in V11 projects. https://github.com/rescript-lang/rescript-vscode/pull/867
1724
- Treat `result` type as a proper built in type. https://github.com/rescript-lang/rescript-vscode/pull/860
25+
- Fix infinite loop when resolving inferred completions when several values in scope has the same name. https://github.com/rescript-lang/rescript-vscode/pull/869
26+
- Fix crash when trying to print recursive polymorphic variants without a concrete definition. https://github.com/rescript-lang/rescript-vscode/pull/851
27+
- Fix `rescript-language-server --version` command. https://github.com/rescript-lang/rescript-vscode/pull/873
28+
- Print exotic polyvariant constructor names with quotes when doing completion. https://github.com/rescript-lang/rescript-vscode/pull/870
1829

1930
#### :nail_care: Polish
2031

analysis/bin/main.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,13 @@ let main () =
145145
~pos:(int_of_string line_start, int_of_string line_end)
146146
~maxLength ~debug
147147
| [_; "codeLens"; path] -> Commands.codeLens ~path ~debug
148-
| [_; "extractDocs"; path] -> DocExtraction.extractDocs ~path ~debug
148+
| [_; "extractDocs"; path] ->
149+
150+
let () = match Sys.getenv_opt "FROM_COMPILER" with
151+
| Some("true") -> Cfg.isDocGenFromCompiler := true
152+
| _ -> () in
153+
154+
DocExtraction.extractDocs ~path ~debug
149155
| [_; "codeAction"; path; startLine; startCol; endLine; endCol; currentFile]
150156
->
151157
Commands.codeAction ~path

analysis/src/BuildSystem.ml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ let namespacedName namespace name =
66
let ( /+ ) = Filename.concat
77

88
let getBsPlatformDir rootPath =
9-
let result =
10-
ModuleResolution.resolveNodeModulePath ~startPath:rootPath "rescript"
11-
in
12-
match result with
13-
| Some path -> Some path
14-
| None ->
15-
let message = "rescript could not be found" in
16-
Log.log message;
17-
None
9+
match !Cfg.isDocGenFromCompiler with
10+
| false -> (
11+
let result =
12+
ModuleResolution.resolveNodeModulePath ~startPath:rootPath "rescript"
13+
in
14+
match result with
15+
| Some path -> Some path
16+
| None ->
17+
let message = "rescript could not be found" in
18+
Log.log message;
19+
None)
20+
| true -> Some rootPath
1821

1922
let getLibBs root = Files.ifExists (root /+ "lib" /+ "bs")
2023

analysis/src/Cfg.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
let supportsSnippets = ref false
22

33
let debugFollowCtxPath = ref false
4+
5+
let isDocGenFromCompiler = ref false

analysis/src/CompletionBackEnd.ml

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ let kindToDetail name (kind : Completion.kind) =
231231
^ "\n\n" ^ s
232232
else name ^ ": " ^ (typ |> Shared.typeToString) ^ "\n\n" ^ s
233233
| Constructor (c, s) -> showConstructor c ^ "\n\n" ^ s
234-
| PolyvariantConstructor ({name; args}, s) ->
235-
"#" ^ name
234+
| PolyvariantConstructor ({displayName; args}, s) ->
235+
"#" ^ displayName
236236
^ (match args with
237237
| [] -> ""
238238
| typeExprs ->
@@ -263,7 +263,7 @@ let findAllCompletions ~(env : QueryEnv.t) ~prefix ~exact ~namesUsed
263263
completionForExportedFields ~env ~prefix ~exact ~namesUsed
264264
@ completionForExportedModules ~env ~prefix ~exact ~namesUsed
265265

266-
let processLocalValue name loc contextPath ~prefix ~exact ~env
266+
let processLocalValue name loc contextPath scope ~prefix ~exact ~env
267267
~(localTables : LocalTables.t) =
268268
if Utils.checkName name ~prefix ~exact then
269269
match Hashtbl.find_opt localTables.valueTable (name, Loc.start loc) with
@@ -279,14 +279,14 @@ let processLocalValue name loc contextPath ~prefix ~exact ~env
279279
}
280280
:: localTables.resultRev)
281281
| None ->
282-
Log.log
283-
(Printf.sprintf "Completion Value Not Found %s loc:%s\n" name
284-
(Loc.toString loc));
282+
if !Cfg.debugFollowCtxPath then
283+
Printf.printf "Completion Value Not Found %s loc:%s\n" name
284+
(Loc.toString loc);
285285
localTables.resultRev <-
286286
Completion.create name ~env
287287
~kind:
288288
(match contextPath with
289-
| Some contextPath -> FollowContextPath contextPath
289+
| Some contextPath -> FollowContextPath (contextPath, scope)
290290
| None ->
291291
Value
292292
(Ctype.newconstr
@@ -622,17 +622,17 @@ let completionsGetCompletionType ~full = function
622622
| {Completion.kind = ExtractedType (typ, _); env} :: _ -> Some (typ, env)
623623
| _ -> None
624624

625-
let rec completionsGetCompletionType2 ~debug ~full ~opens ~rawOpens ~pos ~scope
626-
= function
625+
let rec completionsGetCompletionType2 ~debug ~full ~opens ~rawOpens ~pos =
626+
function
627627
| {Completion.kind = Value typ; env} :: _
628628
| {Completion.kind = ObjLabel typ; env} :: _
629629
| {Completion.kind = Field ({typ}, _); env} :: _ ->
630630
Some (TypeExpr typ, env)
631-
| {Completion.kind = FollowContextPath ctxPath; env} :: _ ->
631+
| {Completion.kind = FollowContextPath (ctxPath, scope); env} :: _ ->
632632
ctxPath
633633
|> getCompletionsForContextPath ~debug ~full ~env ~exact:true ~opens
634634
~rawOpens ~pos ~scope
635-
|> completionsGetCompletionType2 ~debug ~full ~opens ~rawOpens ~pos ~scope
635+
|> completionsGetCompletionType2 ~debug ~full ~opens ~rawOpens ~pos
636636
| {Completion.kind = Type typ; env} :: _ -> (
637637
match TypeUtils.extractTypeFromResolvedType typ ~env ~full with
638638
| None -> None
@@ -642,16 +642,16 @@ let rec completionsGetCompletionType2 ~debug ~full ~opens ~rawOpens ~pos ~scope
642642
| _ -> None
643643

644644
and completionsGetTypeEnv2 ~debug (completions : Completion.t list) ~full ~opens
645-
~rawOpens ~pos ~scope =
645+
~rawOpens ~pos =
646646
match completions with
647647
| {Completion.kind = Value typ; env} :: _ -> Some (typ, env)
648648
| {Completion.kind = ObjLabel typ; env} :: _ -> Some (typ, env)
649649
| {Completion.kind = Field ({typ}, _); env} :: _ -> Some (typ, env)
650-
| {Completion.kind = FollowContextPath ctxPath; env} :: _ ->
650+
| {Completion.kind = FollowContextPath (ctxPath, scope); env} :: _ ->
651651
ctxPath
652652
|> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env
653653
~exact:true ~scope
654-
|> completionsGetTypeEnv2 ~debug ~full ~opens ~rawOpens ~pos ~scope
654+
|> completionsGetTypeEnv2 ~debug ~full ~opens ~rawOpens ~pos
655655
| _ -> None
656656

657657
and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
@@ -754,7 +754,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
754754
cp
755755
|> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env
756756
~exact:true ~scope
757-
|> completionsGetCompletionType2 ~debug ~full ~opens ~rawOpens ~pos ~scope
757+
|> completionsGetCompletionType2 ~debug ~full ~opens ~rawOpens ~pos
758758
with
759759
| Some ((TypeExpr typ | ExtractedType (Tfunction {typ})), env) -> (
760760
let rec reconstructFunctionType args tRet =
@@ -805,7 +805,6 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
805805
match
806806
completionsForCtxPath
807807
|> completionsGetCompletionType2 ~debug ~full ~opens ~rawOpens ~pos
808-
~scope
809808
with
810809
| Some (TypeExpr typ, env) -> (
811810
match typ |> TypeUtils.extractRecordType ~env ~package with
@@ -839,7 +838,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
839838
cp
840839
|> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env
841840
~exact:true ~scope
842-
|> completionsGetTypeEnv2 ~debug ~full ~opens ~rawOpens ~pos ~scope
841+
|> completionsGetTypeEnv2 ~debug ~full ~opens ~rawOpens ~pos
843842
with
844843
| Some (typ, env) -> (
845844
match typ |> TypeUtils.extractObjectType ~env ~package with
@@ -866,7 +865,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
866865
cp
867866
|> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env
868867
~exact:true ~scope ~mode:Pipe
869-
|> completionsGetTypeEnv2 ~debug ~full ~opens ~rawOpens ~pos ~scope
868+
|> completionsGetTypeEnv2 ~debug ~full ~opens ~rawOpens ~pos
870869
with
871870
| None -> []
872871
| Some (typ, envFromCompletionItem) -> (
@@ -1031,7 +1030,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
10311030
path
10321031
|> getCompletionsForPath ~debug ~completionContext:Value ~exact:true
10331032
~package ~opens ~full ~pos ~env ~scope
1034-
|> completionsGetTypeEnv2 ~debug ~full ~opens ~rawOpens ~pos ~scope
1033+
|> completionsGetTypeEnv2 ~debug ~full ~opens ~rawOpens ~pos
10351034
in
10361035
let lowercaseComponent =
10371036
match pathToComponent with
@@ -1078,7 +1077,6 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
10781077
|> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env
10791078
~exact:true ~scope
10801079
|> completionsGetCompletionType2 ~debug ~full ~opens ~rawOpens ~pos
1081-
~scope
10821080
with
10831081
| Some ((TypeExpr typ | ExtractedType (Tfunction {typ})), env) ->
10841082
(typ |> TypeUtils.getArgs ~full ~env, env)
@@ -1115,7 +1113,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
11151113
rootCtxPath
11161114
|> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env
11171115
~exact:true ~scope
1118-
|> completionsGetCompletionType2 ~debug ~full ~opens ~rawOpens ~pos ~scope
1116+
|> completionsGetCompletionType2 ~debug ~full ~opens ~rawOpens ~pos
11191117
with
11201118
| Some (typ, env) -> (
11211119
match typ |> TypeUtils.resolveNestedPatternPath ~env ~full ~nested with
@@ -1225,13 +1223,13 @@ let rec completeTypedValue ~full ~prefix ~completionContext ~mode
12251223
|> List.map (fun (constructor : polyVariantConstructor) ->
12261224
Completion.createWithSnippet
12271225
~name:
1228-
("#" ^ constructor.name
1226+
("#" ^ constructor.displayName
12291227
^ printConstructorArgs
12301228
(List.length constructor.args)
12311229
~asSnippet:false)
12321230
~insertText:
12331231
((if Utils.startsWith prefix "#" then "" else "#")
1234-
^ constructor.name
1232+
^ constructor.displayName
12351233
^ printConstructorArgs
12361234
(List.length constructor.args)
12371235
~asSnippet:true)
@@ -1528,7 +1526,7 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable =
15281526
path
15291527
|> getCompletionsForPath ~debug ~completionContext:Value ~exact:true
15301528
~package ~opens ~full ~pos ~env ~scope
1531-
|> completionsGetTypeEnv2 ~debug ~full ~opens ~rawOpens ~pos ~scope
1529+
|> completionsGetTypeEnv2 ~debug ~full ~opens ~rawOpens ~pos
15321530
in
15331531
match completable with
15341532
| Cnone -> []
@@ -1603,7 +1601,7 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable =
16031601
cp
16041602
|> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env
16051603
~exact:true ~scope
1606-
|> completionsGetTypeEnv2 ~debug ~full ~opens ~rawOpens ~pos ~scope
1604+
|> completionsGetTypeEnv2 ~debug ~full ~opens ~rawOpens ~pos
16071605
with
16081606
| Some (typ, _env) ->
16091607
if debug then
@@ -1639,7 +1637,7 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable =
16391637
contextPath
16401638
|> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env
16411639
~exact:true ~scope
1642-
|> completionsGetTypeEnv2 ~debug ~full ~opens ~rawOpens ~pos ~scope
1640+
|> completionsGetTypeEnv2 ~debug ~full ~opens ~rawOpens ~pos
16431641
with
16441642
| Some (typ, env) -> (
16451643
match
@@ -1773,7 +1771,7 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable =
17731771
~cases:
17741772
(v.constructors
17751773
|> List.map (fun (constructor : polyVariantConstructor) ->
1776-
"#" ^ constructor.name
1774+
"#" ^ constructor.displayName
17771775
^
17781776
match constructor.args with
17791777
| [] -> ""

analysis/src/Hover.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ let getHoverViaCompletions ~debug ~path ~pos ~currentFile ~forHover
141141
let opens = CompletionBackEnd.getOpens ~debug ~rawOpens ~package ~env in
142142
match
143143
CompletionBackEnd.completionsGetTypeEnv2 ~debug ~full ~rawOpens ~opens
144-
~pos ~scope completions
144+
~pos completions
145145
with
146146
| Some (typ, _env) ->
147147
let typeString =
@@ -154,7 +154,7 @@ let getHoverViaCompletions ~debug ~path ~pos ~currentFile ~forHover
154154
let opens = CompletionBackEnd.getOpens ~debug ~rawOpens ~package ~env in
155155
match
156156
CompletionBackEnd.completionsGetTypeEnv2 ~debug ~full ~rawOpens ~opens
157-
~pos ~scope completions
157+
~pos completions
158158
with
159159
| Some (typ, _env) ->
160160
let typeString =

analysis/src/Packages.ml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,31 @@ let makePathsForModule ~projectFilesAndPaths ~dependenciesFilesAndPaths =
1111
Hashtbl.replace pathsForModule modName paths);
1212
pathsForModule
1313

14+
let getReScriptVersion () =
15+
(* TODO: Include patch stuff when needed *)
16+
let defaultVersion = (10, 1) in
17+
try
18+
let value = Sys.getenv "RESCRIPT_VERSION" in
19+
let version =
20+
match value |> String.split_on_char '.' with
21+
| major :: minor :: _rest -> (
22+
match (int_of_string_opt major, int_of_string_opt minor) with
23+
| Some major, Some minor -> (major, minor)
24+
| _ -> defaultVersion)
25+
| _ -> defaultVersion
26+
in
27+
version
28+
with Not_found -> defaultVersion
29+
1430
let newBsPackage ~rootPath =
1531
let rescriptJson = Filename.concat rootPath "rescript.json" in
1632
let bsconfigJson = Filename.concat rootPath "bsconfig.json" in
1733

1834
let parseRaw raw =
19-
let libBs = BuildSystem.getLibBs rootPath in
35+
let libBs = match !Cfg.isDocGenFromCompiler with
36+
| true -> BuildSystem.getStdlib rootPath
37+
| false -> BuildSystem.getLibBs rootPath
38+
in
2039
match Json.parse raw with
2140
| Some config -> (
2241
match FindFiles.findDependencyFiles rootPath config with
@@ -27,9 +46,12 @@ let newBsPackage ~rootPath =
2746
| Some libBs ->
2847
Some
2948
(let namespace = FindFiles.getNamespace config in
49+
let rescriptVersion = getReScriptVersion () in
3050
let uncurried =
3151
let ns = config |> Json.get "uncurried" in
32-
Option.bind ns Json.bool
52+
match (rescriptVersion, ns) with
53+
| (major, _), None when major >= 11 -> Some true
54+
| _, ns -> Option.bind ns Json.bool
3355
in
3456
let uncurried = uncurried = Some true in
3557
let sourceDirectories =
@@ -93,6 +115,7 @@ let newBsPackage ~rootPath =
93115
("Opens from ReScript config file: "
94116
^ (opens |> List.map pathToString |> String.concat " "));
95117
{
118+
rescriptVersion;
96119
rootPath;
97120
projectFiles =
98121
projectFilesAndPaths |> List.map fst |> FileSet.of_list;

analysis/src/PrintType.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
let printExpr ?(lineWidth = 60) typ =
22
Printtyp.reset_names ();
3+
Printtyp.reset_and_mark_loops typ;
34
Res_doc.toString ~width:lineWidth
45
(Res_outcome_printer.printOutTypeDoc (Printtyp.tree_of_typexp false typ))
56

analysis/src/Scope.ml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
type item =
2-
| Constructor of string * Location.t
3-
| Field of string * Location.t
4-
| Module of string * Location.t
5-
| Open of string list
6-
| Type of string * Location.t
7-
| Value of string * Location.t * SharedTypes.Completable.contextPath option
1+
type item = SharedTypes.ScopeTypes.item
82

93
type t = item list
104

5+
open SharedTypes.ScopeTypes
6+
117
let itemToString item =
128
let str s = if s = "" then "\"\"" else s in
139
let list l = "[" ^ (l |> List.map str |> String.concat ", ") ^ "]" in
@@ -16,7 +12,7 @@ let itemToString item =
1612
| Field (s, loc) -> "Field " ^ s ^ " " ^ Loc.toString loc
1713
| Open sl -> "Open " ^ list sl
1814
| Module (s, loc) -> "Module " ^ s ^ " " ^ Loc.toString loc
19-
| Value (s, loc, _) -> "Value " ^ s ^ " " ^ Loc.toString loc
15+
| Value (s, loc, _, _) -> "Value " ^ s ^ " " ^ Loc.toString loc
2016
| Type (s, loc) -> "Type " ^ s ^ " " ^ Loc.toString loc
2117
[@@live]
2218

@@ -34,14 +30,14 @@ let addValue ~name ~loc ?contextPath x =
3430
if showDebug then
3531
Printf.printf "adding value '%s' with ctxPath: %s\n" name
3632
(SharedTypes.Completable.contextPathToString contextPath));
37-
Value (name, loc, contextPath) :: x
33+
Value (name, loc, contextPath, x) :: x
3834
let addType ~name ~loc x = Type (name, loc) :: x
3935

4036
let iterValuesBeforeFirstOpen f x =
4137
let rec loop items =
4238
match items with
43-
| Value (s, loc, contextPath) :: rest ->
44-
f s loc contextPath;
39+
| Value (s, loc, contextPath, scope) :: rest ->
40+
f s loc contextPath scope;
4541
loop rest
4642
| Open _ :: _ -> ()
4743
| _ :: rest -> loop rest
@@ -52,8 +48,8 @@ let iterValuesBeforeFirstOpen f x =
5248
let iterValuesAfterFirstOpen f x =
5349
let rec loop foundOpen items =
5450
match items with
55-
| Value (s, loc, contextPath) :: rest ->
56-
if foundOpen then f s loc contextPath;
51+
| Value (s, loc, contextPath, scope) :: rest ->
52+
if foundOpen then f s loc contextPath scope;
5753
loop foundOpen rest
5854
| Open _ :: rest -> loop true rest
5955
| _ :: rest -> loop foundOpen rest

0 commit comments

Comments
 (0)