Skip to content
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

[WIP] Editor mode #7369

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions analysis/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ let main () =
~pos:(int_of_string line, int_of_string col)
~debug
| [_; "documentSymbol"; path] -> DocumentSymbol.command ~path
| [_; "hover"; path; line; col; currentFile; supportsMarkdownLinks] ->
| [_; "hover"; path; line; col; _currentFile; supportsMarkdownLinks] ->
Commands.hover ~path
~pos:(int_of_string line, int_of_string col)
~currentFile ~debug
~debug
~supportsMarkdownLinks:
(match supportsMarkdownLinks with
| "true" -> true
Expand Down
16 changes: 8 additions & 8 deletions analysis/reanalyze/src/Arnold.ml
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,9 @@ module ExtendFunctionTable = struct
Texp_apply {funct = {exp_desc = Texp_ident (path, {loc}, _)}; args};
}
when kindOpt <> None ->
let checkArg ((argLabel : Asttypes.Noloc.arg_label), _argOpt) =
let checkArg ((argLabel : Asttypes.arg_label), _argOpt) =
match (argLabel, kindOpt) with
| (Labelled l | Optional l), Some kind ->
| (Labelled {txt = l} | Optional {txt = l}), Some kind ->
kind |> List.for_all (fun {Kind.label} -> label <> l)
| _ -> true
in
Expand Down Expand Up @@ -624,9 +624,9 @@ module ExtendFunctionTable = struct
when callee |> FunctionTable.isInFunctionInTable ~functionTable ->
let functionName = Path.name callee in
args
|> List.iter (fun ((argLabel : Asttypes.Noloc.arg_label), argOpt) ->
|> List.iter (fun ((argLabel : Asttypes.arg_label), argOpt) ->
match (argLabel, argOpt |> extractLabelledArgument) with
| Labelled label, Some (path, loc)
| Labelled {txt = label}, Some (path, loc)
when path |> FunctionTable.isInFunctionInTable ~functionTable
->
functionTable
Expand Down Expand Up @@ -672,11 +672,11 @@ module CheckExpressionWellFormed = struct
->
let functionName = Path.name functionPath in
args
|> List.iter (fun ((argLabel : Asttypes.Noloc.arg_label), argOpt) ->
|> List.iter (fun ((argLabel : Asttypes.arg_label), argOpt) ->
match argOpt |> ExtendFunctionTable.extractLabelledArgument with
| Some (path, loc) -> (
match argLabel with
| Labelled label -> (
| Labelled {txt = label} -> (
if
functionTable
|> FunctionTable.functionGetKindOfLabel ~functionName
Expand Down Expand Up @@ -761,7 +761,7 @@ module Compile = struct
let argsFromKind =
innerFunctionDefinition.kind
|> List.map (fun (entry : Kind.entry) ->
( Asttypes.Noloc.Labelled entry.label,
( Asttypes.Labelled (Location.mknoloc entry.label),
Some
{
expr with
Expand All @@ -785,7 +785,7 @@ module Compile = struct
args
|> List.find_opt (fun arg ->
match arg with
| Asttypes.Noloc.Labelled s, Some _ -> s = label
| Asttypes.Labelled {txt = s}, Some _ -> s = label
| _ -> false)
in
let argOpt =
Expand Down
2 changes: 1 addition & 1 deletion analysis/reanalyze/src/DeadValue.ml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ let processOptionalArgs ~expType ~(locFrom : Location.t) ~locTo ~path args =
| None -> Some false
in
match lbl with
| Asttypes.Noloc.Optional s when not locFrom.loc_ghost ->
| Asttypes.Optional {txt = s} when not locFrom.loc_ghost ->
if argIsSupplied <> Some false then supplied := s :: !supplied;
if argIsSupplied = None then suppliedMaybe := s :: !suppliedMaybe
| _ -> ());
Expand Down
24 changes: 9 additions & 15 deletions analysis/src/Commands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,20 @@ let codeLens ~path ~debug =
in
print_endline result

let hover ~path ~pos ~currentFile ~debug ~supportsMarkdownLinks =
let hover ~path ~pos ~debug ~supportsMarkdownLinks =
let result =
match Cmt.loadFullCmtFromPath ~path with
| None -> Protocol.null
| Some full -> (
match References.getLocItem ~full ~pos ~debug with
| None -> (
if debug then
Printf.printf
"Nothing at that position. Now trying to use completion.\n";
match
Hover.getHoverViaCompletions ~debug ~path ~pos ~currentFile
~forHover:true ~supportsMarkdownLinks
with
| None -> Protocol.null
| Some hover -> hover)
| None -> Protocol.null
| Some locItem -> (
let isModule =
match locItem.locType with
| LModule _ | TopLevelModule _ -> true
| TypeDefinition _ | Typed _ | Constant _ -> false
| TypeDefinition _ | Typed _ | Constant _ | OtherExpression _
| OtherPattern _ ->
false
in
let uriLocOpt = References.definitionForLocItem ~full locItem in
let skipZero =
Expand Down Expand Up @@ -135,7 +128,9 @@ let definition ~path ~pos ~debug =
let isModule =
match locItem.locType with
| LModule _ | TopLevelModule _ -> true
| TypeDefinition _ | Typed _ | Constant _ -> false
| TypeDefinition _ | Typed _ | Constant _ | OtherExpression _
| OtherPattern _ ->
false
in
let skipLoc =
(not isModule) && (not isInterface) && posIsZero loc.loc_start
Expand Down Expand Up @@ -393,8 +388,7 @@ let test ~path =
("Hover " ^ path ^ " " ^ string_of_int line ^ ":"
^ string_of_int col);
let currentFile = createCurrentFile () in
hover ~supportsMarkdownLinks:true ~path ~pos:(line, col)
~currentFile ~debug:true;
hover ~supportsMarkdownLinks:true ~path ~pos:(line, col) ~debug:true;
Sys.remove currentFile
| "she" ->
print_endline
Expand Down
64 changes: 64 additions & 0 deletions analysis/src/CompletionBackEndRevamped.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
open SharedTypes

let resolveOpens = CompletionBackEnd.resolveOpens
let getOpens = CompletionBackEnd.getOpens

let findFields ~env ~package ~hint typ =
match TypeUtils.extractRecordType ~env ~package typ with
| None -> []
| Some (_recordEnv, fields, decl) ->
fields
|> DotCompletionUtils.filterRecordFields ~env ~prefix:hint ~exact:false
~recordAsString:(decl.item.decl |> Shared.declToString decl.name.txt)

let processCompletable ~debug ~full ~scope ~env ~pos
(completable : CompletableRevamped.t) =
let package = full.package in
let rawOpens = Scope.getRawOpens scope in
let opens = getOpens ~debug ~rawOpens ~package ~env in
let allFiles = allFilesInPackage package in

ignore pos;
ignore opens;
ignore allFiles;

match completable with
| Cexpression {kind; typeLoc} -> (
match TypeUtils.findTypeViaLoc typeLoc ~full ~debug with
| None -> []
| Some typ -> (
match kind with
| Field {hint} -> findFields ~env ~package ~hint typ))
| Cnone -> []
| CextensionNode _ -> []
| Cdecorator prefix ->
let mkDecorator (name, docstring, maybeInsertText) =
{
(Completion.create name ~synthetic:true ~includesSnippets:true
~kind:(Label "") ~env ?insertText:maybeInsertText)
with
docstring;
}
in
let isTopLevel = String.starts_with ~prefix:"@" prefix in
let prefix =
if isTopLevel then String.sub prefix 1 (String.length prefix - 1)
else prefix
in
let decorators =
if isTopLevel then CompletionDecorators.toplevel
else CompletionDecorators.local
in
decorators
|> List.filter (fun (decorator, _, _) -> Utils.startsWith decorator prefix)
|> List.map (fun (decorator, maybeInsertText, doc) ->
let parts = String.split_on_char '.' prefix in
let len = String.length prefix in
let dec2 =
if List.length parts > 1 then
String.sub decorator len (String.length decorator - len)
else decorator
in
(dec2, doc, maybeInsertText))
|> List.map mkDecorator
| CdecoratorPayload _ -> []
Loading
Loading