Skip to content

Commit c862317

Browse files
committed
fix merge
2 parents 814a710 + f21af99 commit c862317

25 files changed

+351
-153
lines changed

Diff for: CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,24 @@
1313
## master
1414

1515
#### :nail_care: Polish
16+
1617
- Remove spacing between type definition in clients that do not support markdown links. https://github.com/rescript-lang/rescript-vscode/pull/619
18+
- Rename custom LSP methods names. https://github.com/rescript-lang/rescript-vscode/pull/611
1719

1820
#### :bug: Bug Fix
1921

2022
- Fix issue where `-open Some.Path` in `"bsc-flags"` would sometimes be treated differently from `open Some.Path` locally in a file https://github.com/rescript-lang/rescript-vscode/pull/616
2123

24+
- Fix issue where doc comment is not shown on hover in case of shadowed identifier (in particular for JSX V4 components which shadow `make`) https://github.com/rescript-lang/rescript-vscode/issues/621
25+
26+
- Adapt command to create interface files to latest JSX V4 (no key prop, possibly empty record) https://github.com/rescript-lang/rescript-vscode/issues/617
27+
28+
- Fix issue where pipes were not taken into account in the signature help, resulting in the highlighted argument in signature help always being off by one for unlabelled arguments in piped expressions https://github.com/rescript-lang/rescript-vscode/issues/626
29+
30+
- Fix incorrect type hint for module type. https://github.com/rescript-lang/rescript-vscode/pull/626
31+
32+
- Fix file location in Document Symbols response. https://github.com/rescript-lang/rescript-vscode/issues/629
33+
2234
## v1.8.2
2335

2436
#### :rocket: New Feature

Diff for: analysis/src/CompletionBackEnd.ml

+19-5
Original file line numberDiff line numberDiff line change
@@ -1283,10 +1283,18 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
12831283
|> completionsGetTypeEnv
12841284
with
12851285
| Some (typ, _envNotUsed) -> (
1286-
let arrayModulePath = ["Js"; "Array2"] in
1287-
let listModulePath = ["Belt"; "List"] in
1288-
let optionModulePath = ["Belt"; "Option"] in
1289-
let stringModulePath = ["Js"; "String2"] in
1286+
let {
1287+
arrayModulePath;
1288+
optionModulePath;
1289+
stringModulePath;
1290+
intModulePath;
1291+
floatModulePath;
1292+
promiseModulePath;
1293+
listModulePath;
1294+
resultModulePath;
1295+
} =
1296+
package.builtInCompletionModules
1297+
in
12901298
let getModulePath path =
12911299
let rec loop (path : Path.t) =
12921300
match path with
@@ -1296,9 +1304,15 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
12961304
in
12971305
match path with
12981306
| Path.Pident id when Ident.name id = "array" -> arrayModulePath
1299-
| Path.Pident id when Ident.name id = "list" -> listModulePath
13001307
| Path.Pident id when Ident.name id = "option" -> optionModulePath
13011308
| Path.Pident id when Ident.name id = "string" -> stringModulePath
1309+
| Path.Pident id when Ident.name id = "int" -> intModulePath
1310+
| Path.Pident id when Ident.name id = "float" -> floatModulePath
1311+
| Path.Pident id when Ident.name id = "promise" -> promiseModulePath
1312+
| Path.Pident id when Ident.name id = "list" -> listModulePath
1313+
| Path.Pident id when Ident.name id = "result" -> resultModulePath
1314+
| Path.Pident id when Ident.name id = "lazy_t" -> ["Lazy"]
1315+
| Path.Pident id when Ident.name id = "char" -> ["Char"]
13021316
| _ -> (
13031317
match loop path with
13041318
| _ :: rest -> List.rev rest

Diff for: analysis/src/CreateInterface.ml

+13-7
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,19 @@ let printSignature ~extractor ~signature =
240240
( propsId,
241241
{
242242
type_params;
243-
type_kind = Type_record (labelDecls, Record_optional_labels optLbls);
243+
type_kind = Type_record (labelDecls, recordRepresentation);
244244
},
245245
_ )
246246
:: Sig_value (makeId (* make *), makeValueDesc)
247247
:: rest
248248
when Ident.name propsId = "props"
249249
&& getComponentTypeV4 makeValueDesc.val_type <> None
250-
&& optLbls |> List.mem "key" ->
250+
&&
251+
match recordRepresentation with
252+
| Record_optional_labels _ -> true
253+
| _ -> labelDecls = [] (* empty record *) ->
251254
(* PPX V4 component declaration:
252-
type props = {..., key?: _}
255+
type props = {...}
253256
let v = ...
254257
*)
255258
let newItemStr =
@@ -268,15 +271,18 @@ let printSignature ~extractor ~signature =
268271
in
269272
let lblName = labelDecl.ld_id |> Ident.name in
270273
let lbl =
274+
let optLbls =
275+
match recordRepresentation with
276+
| Record_optional_labels optLbls -> optLbls
277+
| _ -> []
278+
in
271279
if List.mem lblName optLbls then Asttypes.Optional lblName
272280
else Labelled lblName
273281
in
274-
if lblName = "key" then mkFunType rest
275-
else
276-
{retType with desc = Tarrow (lbl, propType, mkFunType rest, Cok)}
282+
{retType with desc = Tarrow (lbl, propType, mkFunType rest, Cok)}
277283
in
278284
let funType =
279-
if List.length labelDecls = 1 (* No props: only "key "*) then
285+
if List.length labelDecls = 0 (* No props *) then
280286
let tUnit =
281287
Ctype.newconstr (Path.Pident (Ident.create "unit")) []
282288
in

Diff for: analysis/src/DocumentSymbol.ml

+2-9
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,9 @@ let command ~path =
137137
let result =
138138
!symbols
139139
|> List.rev_map (fun (name, loc, kind) ->
140+
let range = Utils.cmtLocToRange loc in
140141
Protocol.stringifyDocumentSymbolItem
141-
{
142-
name;
143-
location =
144-
{
145-
uri = Uri.toString (Uri.fromPath path);
146-
range = Utils.cmtLocToRange loc;
147-
};
148-
kind = kindNumber kind;
149-
})
142+
{name; range; selectionRange = range; kind = kindNumber kind})
150143
|> String.concat ",\n"
151144
in
152145
print_endline ("[\n" ^ result ^ "\n]")

Diff for: analysis/src/Hover.ml

+7-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ let rec showModule ~docstring ~(file : File.t) ~name
2828
(declared : Module.t Declared.t option) =
2929
match declared with
3030
| None -> showModuleTopLevel ~docstring ~name file.structure.items
31-
| Some {item = Structure {items}} -> showModuleTopLevel ~docstring ~name items
31+
| Some {item = Structure {items}; modulePath} ->
32+
let name =
33+
match modulePath with
34+
| ExportedModule {isType} when isType = true -> "type " ^ name
35+
| _ -> name
36+
in
37+
showModuleTopLevel ~docstring ~name items
3238
| Some ({item = Constraint (_moduleItem, moduleTypeItem)} as declared) ->
3339
(* show the interface *)
3440
showModule ~docstring ~file ~name

Diff for: analysis/src/Packages.ml

+30
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,36 @@ let newBsPackage ~rootPath =
9393
pathsForModule;
9494
opens;
9595
namespace;
96+
builtInCompletionModules =
97+
(if
98+
opens_from_bsc_flags
99+
|> List.find_opt (fun opn ->
100+
match opn with
101+
| ["RescriptStdlib"] -> true
102+
| _ -> false)
103+
|> Option.is_some
104+
then
105+
{
106+
arrayModulePath = ["Array"];
107+
optionModulePath = ["Option"];
108+
stringModulePath = ["String"];
109+
intModulePath = ["Int"];
110+
floatModulePath = ["Float"];
111+
promiseModulePath = ["Promise"];
112+
listModulePath = ["List"];
113+
resultModulePath = ["Result"];
114+
}
115+
else
116+
{
117+
arrayModulePath = ["Js"; "Array2"];
118+
optionModulePath = ["Belt"; "Option"];
119+
stringModulePath = ["Js"; "String2"];
120+
intModulePath = ["Belt"; "Int"];
121+
floatModulePath = ["Belt"; "Float"];
122+
promiseModulePath = ["Js"; "Promise"];
123+
listModulePath = ["Belt"; "List"];
124+
resultModulePath = ["Belt"; "Result"];
125+
});
96126
})))
97127
| None -> None)
98128

Diff for: analysis/src/ProcessCmt.ml

+38-6
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,30 @@ let addDeclared ~(name : string Location.loc) ~extent ~stamp ~(env : Env.t)
1010
addStamp env.stamps stamp declared;
1111
declared
1212

13-
let rec forTypeSignatureItem ~env ~(exported : Exported.t)
13+
let rec forTypeSignatureItem ~(env : SharedTypes.Env.t) ~(exported : Exported.t)
1414
(item : Types.signature_item) =
1515
match item with
1616
| Sig_value (ident, {val_type; val_attributes; val_loc = loc}) ->
1717
let item = val_type in
18+
let stamp = Ident.binding_time ident in
19+
let oldDeclared = Stamps.findValue env.stamps stamp in
1820
let declared =
1921
addDeclared
2022
~name:(Location.mknoloc (Ident.name ident))
21-
~extent:loc ~stamp:(Ident.binding_time ident) ~env ~item val_attributes
23+
~extent:loc ~stamp ~env ~item val_attributes
2224
(Exported.add exported Exported.Value)
2325
Stamps.addValue
2426
in
27+
let declared =
28+
(* When an id is shadowed, a module constraint without the doc comment is created.
29+
Here the existing doc comment is restored. See https://github.com/rescript-lang/rescript-vscode/issues/621 *)
30+
match oldDeclared with
31+
| Some oldDeclared when declared.docstring = [] ->
32+
let newDeclared = {declared with docstring = oldDeclared.docstring} in
33+
Stamps.addValue env.stamps stamp newDeclared;
34+
newDeclared
35+
| _ -> declared
36+
in
2537
[{Module.kind = Module.Value declared.item; name = declared.name.txt}]
2638
| Sig_type
2739
( ident,
@@ -363,7 +375,12 @@ let rec forStructureItem ~env ~(exported : Exported.t) item =
363375
mtd_loc;
364376
} ->
365377
let env =
366-
{env with modulePath = ExportedModule (name.txt, env.modulePath)}
378+
{
379+
env with
380+
modulePath =
381+
ExportedModule
382+
{name = name.txt; modulePath = env.modulePath; isType = true};
383+
}
367384
in
368385
let modTypeItem = forTypeModule env modType in
369386
let declared =
@@ -413,7 +430,12 @@ and forModule env mod_desc moduleName =
413430
| Tmod_ident (path, _lident) -> Ident path
414431
| Tmod_structure structure ->
415432
let env =
416-
{env with modulePath = ExportedModule (moduleName, env.modulePath)}
433+
{
434+
env with
435+
modulePath =
436+
ExportedModule
437+
{name = moduleName; modulePath = env.modulePath; isType = false};
438+
}
417439
in
418440
let contents = forStructure ~env structure.str_items in
419441
Structure contents
@@ -435,14 +457,24 @@ and forModule env mod_desc moduleName =
435457
forModule env functor_.mod_desc moduleName
436458
| Tmod_unpack (_expr, moduleType) ->
437459
let env =
438-
{env with modulePath = ExportedModule (moduleName, env.modulePath)}
460+
{
461+
env with
462+
modulePath =
463+
ExportedModule
464+
{name = moduleName; modulePath = env.modulePath; isType = false};
465+
}
439466
in
440467
forTypeModule env moduleType
441468
| Tmod_constraint (expr, typ, _constraint, _coercion) ->
442469
(* TODO do this better I think *)
443470
let modKind = forModule env expr.mod_desc moduleName in
444471
let env =
445-
{env with modulePath = ExportedModule (moduleName, env.modulePath)}
472+
{
473+
env with
474+
modulePath =
475+
ExportedModule
476+
{name = moduleName; modulePath = env.modulePath; isType = false};
477+
}
446478
in
447479
let modTypeKind = forTypeModule env typ in
448480
Constraint (modKind, modTypeKind)

Diff for: analysis/src/Protocol.ml

+11-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ type completionItem = {
4242
}
4343

4444
type location = {uri: string; range: range}
45-
type documentSymbolItem = {name: string; kind: int; location: location}
45+
type documentSymbolItem = {
46+
name: string;
47+
kind: int;
48+
range: range;
49+
selectionRange: range;
50+
}
4651
type renameFile = {oldUri: string; newUri: string}
4752
type textEdit = {range: range; newText: string}
4853

@@ -103,15 +108,16 @@ let stringifyLocation (h : location) =
103108
Printf.sprintf {|{"uri": "%s", "range": %s}|} (Json.escape h.uri)
104109
(stringifyRange h.range)
105110

106-
let stringifyDocumentSymbolItem i =
111+
let stringifyDocumentSymbolItem (i : documentSymbolItem) =
112+
let range = stringifyRange i.range in
107113
Printf.sprintf
108114
{|{
109115
"name": "%s",
110116
"kind": %i,
111-
"location": %s
117+
"range": %s,
118+
"selectionRange": %s
112119
}|}
113-
(Json.escape i.name) i.kind
114-
(stringifyLocation i.location)
120+
(Json.escape i.name) i.kind range range
115121

116122
let stringifyRenameFile {oldUri; newUri} =
117123
Printf.sprintf {|{

Diff for: analysis/src/References.ml

+3-2
Original file line numberDiff line numberDiff line change
@@ -430,15 +430,16 @@ let isVisible (declared : _ Declared.t) =
430430
| File _ -> true
431431
| NotVisible -> false
432432
| IncludedModule (_, inner) -> loop inner
433-
| ExportedModule (_, inner) -> loop inner
433+
| ExportedModule {modulePath = inner} -> loop inner
434434
in
435435
loop declared.modulePath
436436

437437
let rec pathFromVisibility visibilityPath current =
438438
match visibilityPath with
439439
| File _ -> Some current
440440
| IncludedModule (_, inner) -> pathFromVisibility inner current
441-
| ExportedModule (name, inner) -> pathFromVisibility inner (name :: current)
441+
| ExportedModule {name; modulePath = inner} ->
442+
pathFromVisibility inner (name :: current)
442443
| NotVisible -> None
443444

444445
let pathFromVisibility visibilityPath tipName =

Diff for: analysis/src/ResolvePath.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,4 @@ let rec getSourceUri ~(env : QueryEnv.t) ~package path =
144144
Log.log "NOT FOUND";
145145
getSourceUri ~env ~package inner
146146
| Some (env, _declared) -> env.file.uri)
147-
| ExportedModule (_, inner) -> getSourceUri ~env ~package inner
147+
| ExportedModule {modulePath = inner} -> getSourceUri ~env ~package inner

Diff for: analysis/src/SharedTypes.ml

+13-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type modulePath =
66
| File of Uri.t * string
77
| NotVisible
88
| IncludedModule of Path.t * modulePath
9-
| ExportedModule of string * modulePath
9+
| ExportedModule of {name: string; modulePath: modulePath; isType: bool}
1010

1111
type field = {stamp: int; fname: string Location.loc; typ: Types.type_expr}
1212

@@ -361,12 +361,24 @@ type file = string
361361

362362
module FileSet = Set.Make (String)
363363

364+
type builtInCompletionModules = {
365+
arrayModulePath: string list;
366+
optionModulePath: string list;
367+
stringModulePath: string list;
368+
intModulePath: string list;
369+
floatModulePath: string list;
370+
promiseModulePath: string list;
371+
listModulePath: string list;
372+
resultModulePath: string list;
373+
}
374+
364375
type package = {
365376
rootPath: filePath;
366377
projectFiles: FileSet.t;
367378
dependenciesFiles: FileSet.t;
368379
pathsForModule: (file, paths) Hashtbl.t;
369380
namespace: string option;
381+
builtInCompletionModules: builtInCompletionModules;
370382
opens: path list;
371383
}
372384

0 commit comments

Comments
 (0)