Skip to content

Support autocomplete for objects from another module M.x[.... #363

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 9 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## master
- Fix issue where using paths of the form `./something` would show multiple copies of the same file in vscode.
- When hovering on a field access, show the instantiated type of the field.
- Support autocomplete for objects from another module `M.x[...`.

## 1.2.1

Expand Down
4 changes: 2 additions & 2 deletions analysis/src/Cmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let fromUri ~uri =
in
match Hashtbl.find_opt package.pathsForModule moduleName with
| Some paths ->
let cmt = SharedTypes.getCmtPath ~uri paths in
let cmt = getCmtPath ~uri paths in
ProcessCmt.fullForCmt ~moduleName ~package ~uri cmt
| None ->
prerr_endline ("can't find module " ^ moduleName);
Expand All @@ -19,7 +19,7 @@ let fromUri ~uri =
let fromModule ~package modname =
if Hashtbl.mem package.pathsForModule modname then
let paths = Hashtbl.find package.pathsForModule modname in
let uri = SharedTypes.getUri paths in
let uri = getUri paths in
fromUri ~uri
else None

Expand Down
20 changes: 11 additions & 9 deletions analysis/src/Commands.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
open SharedTypes

let dumpLocations ~full =
full.SharedTypes.extra.locItems
full.extra.locItems
|> List.map (fun locItem ->
let locItemTxt = SharedTypes.locItemToString locItem in
let locItemTxt = locItemToString locItem in
let hoverText = Hover.newHover ~full locItem in
let hover =
match hoverText with None -> "" | Some s -> String.escaped s
Expand Down Expand Up @@ -60,7 +62,7 @@ let hover ~path ~line ~col =
| Some locItem -> (
let isModule =
match locItem.locType with
| SharedTypes.LModule _ | TopLevelModule _ -> true
| LModule _ | TopLevelModule _ -> true
| TypeDefinition _ | Typed _ | Constant _ -> false
in
let uriLocOpt = References.definitionForLocItem ~full locItem in
Expand Down Expand Up @@ -102,7 +104,7 @@ let definition ~path ~line ~col =
in
let isModule =
match locItem.locType with
| SharedTypes.LModule _ | TopLevelModule _ -> true
| LModule _ | TopLevelModule _ -> true
| TypeDefinition _ | Typed _ | Constant _ -> false
in
let skipLoc =
Expand Down Expand Up @@ -174,15 +176,15 @@ let documentSymbol ~path =
| None -> Protocol.null
| Some {file} ->
let open SharedTypes in
let rec getItems {topLevel} =
let rec getItems {ModuleKind.topLevel} =
let rec getItem = function
| MValue v -> (v |> SharedTypes.variableKind, [])
| MType (t, _) -> (t.decl |> SharedTypes.declarationKind, [])
| ModuleKind.Value v -> (v |> variableKind, [])
| Type (t, _) -> (t.decl |> declarationKind, [])
| Module (Structure contents) -> (Module, getItems contents)
| Module (Constraint (_, modTypeItem)) -> getItem (Module modTypeItem)
| Module (Ident _) -> (Module, [])
in
let fn {name = {txt}; extentLoc; item} =
let fn {Declared.name = {txt}; extentLoc; item} =
let item, siblings = getItem item in
if extentLoc.loc_ghost then siblings
else (txt, extentLoc, item) :: siblings
Expand All @@ -201,7 +203,7 @@ let documentSymbol ~path =
uri = Uri2.toString (Uri2.fromPath path);
range = Utils.cmtLocToRange loc;
};
kind = SharedTypes.symbolKind kind;
kind = symbolKind kind;
})
in
"[\n" ^ (allSymbols |> String.concat ",\n") ^ "\n]"
Expand Down
24 changes: 13 additions & 11 deletions analysis/src/Hover.ml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
open SharedTypes

let codeBlock code = Printf.sprintf "```rescript\n%s\n```" code

let showModuleTopLevel ~docstring ~name
(topLevel : SharedTypes.moduleItem SharedTypes.declared list) =
(topLevel : ModuleKind.moduleItem Declared.t list) =
let contents =
topLevel
|> List.map (fun item ->
match item.SharedTypes.item with
match item.Declared.item with
(* TODO pretty print module contents *)
| SharedTypes.MType ({decl}, recStatus) ->
| ModuleKind.Type ({decl}, recStatus) ->
" " ^ (decl |> Shared.declToString ~recStatus item.name.txt)
| Module _ -> " module " ^ item.name.txt
| MValue typ ->
| Value typ ->
" let " ^ item.name.txt ^ ": " ^ (typ |> Shared.typeToString))
(* TODO indent *)
|> String.concat "\n"
Expand All @@ -23,8 +25,8 @@ let showModuleTopLevel ~docstring ~name
in
Some (doc ^ full)

let rec showModule ~docstring ~(file : SharedTypes.File.t) ~name
(declared : SharedTypes.moduleKind SharedTypes.declared option) =
let rec showModule ~docstring ~(file : File.t) ~name
(declared : ModuleKind.t Declared.t option) =
match declared with
| None -> showModuleTopLevel ~docstring ~name file.contents.topLevel
| Some {item = Structure {topLevel}} ->
Expand All @@ -36,9 +38,9 @@ let rec showModule ~docstring ~(file : SharedTypes.File.t) ~name
| Some {item = Ident path} ->
Some ("Unable to resolve module reference " ^ Path.name path)

let newHover ~full:{SharedTypes.file; package} locItem =
match locItem.SharedTypes.locType with
| SharedTypes.TypeDefinition (name, decl, _stamp) ->
let newHover ~full:{file; package} locItem =
match locItem.locType with
| TypeDefinition (name, decl, _stamp) ->
let typeDef = Shared.declToString name decl in
Some (codeBlock typeDef)
| LModule (Definition (stamp, _tip)) | LModule (LocalReference (stamp, _tip))
Expand All @@ -59,7 +61,7 @@ let newHover ~full:{SharedTypes.file; package} locItem =
match ProcessCmt.fileForModule ~package moduleName with
| None -> None
| Some file -> (
let env = SharedTypes.QueryEnv.fromFile file in
let env = QueryEnv.fromFile file in
match ProcessCmt.resolvePath ~env ~path ~package with
| None -> None
| Some (env, name) -> (
Expand Down Expand Up @@ -101,7 +103,7 @@ let newHover ~full:{SharedTypes.file; package} locItem =
let fromType ~docstring typ =
let typeString = codeBlock (typ |> Shared.typeToString) in
let extraTypeInfo =
let env = SharedTypes.QueryEnv.fromFile file in
let env = QueryEnv.fromFile file in
match typ |> Shared.digConstructor with
| None -> None
| Some path -> (
Expand Down
Loading