Skip to content

Universal dot completion #1054

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 34 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
565edda
wip complete pipeable functions from dot completion on record when re…
zth Nov 5, 2024
4347fa3
correctly insert completion item text removing the dot when selecting…
zth Nov 6, 2024
eefe5f6
add experimental mainTypeForModule annotation
zth Nov 6, 2024
ca1c8d1
complete modules in payload of mainTypeForModule
zth Nov 7, 2024
7110db8
rename attribute
zth Nov 12, 2024
af54200
hover for new decorator
zth Nov 12, 2024
e3d1470
allow extra module completions also for pipe
zth Nov 13, 2024
72a522c
make sure completions work across files
zth Nov 14, 2024
ce80c6c
filter pipe completions to only applicable functions
zth Nov 14, 2024
5ad0319
pipe complete only for functions that take the expected type as the f…
zth Nov 16, 2024
943b01f
start refactoring dot completion everywhere
zth Nov 20, 2024
ebc5d9e
refactor dot completion
zth Nov 28, 2024
8e2395e
add a few more synthetic
zth Nov 28, 2024
8e166ac
disable verbose log
zth Nov 28, 2024
2b3190c
cleanup
zth Nov 28, 2024
58cf089
pipe dot completion for builtins
zth Nov 28, 2024
70b7db6
Add example case (#1058)
nojaf Nov 29, 2024
931fd28
Additional completion tests (#1062)
nojaf Dec 19, 2024
e347146
make dot completion everywhere actually work
zth Dec 25, 2024
415eea9
do not care about ExtractedType now that we have incremental type che…
zth Dec 25, 2024
c715071
refactor to share pipe completion code logic
zth Dec 25, 2024
dfc3eb0
cleanup
zth Dec 25, 2024
4e4d03c
cleanup
zth Dec 25, 2024
0fa56aa
fix debug command
zth Dec 28, 2024
b6f7ccc
up rescript in test project
zth Dec 28, 2024
eb4cea5
change strategy for removing dot on completion
zth Dec 29, 2024
b1c6850
contonous dot completion
zth Dec 31, 2024
9c29710
handle dot completions on piped idents
zth Dec 31, 2024
9ac0817
handle scope
zth Dec 31, 2024
3d0a1c8
inline pipe completion logic again
zth Jan 2, 2025
bf7eeba
refactor
zth Jan 2, 2025
380e8a9
more compl spec
zth Jan 2, 2025
603b8d9
refactor
zth Jan 2, 2025
b5053bc
changelog
zth Jan 2, 2025
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
Prev Previous commit
Next Next commit
contonous dot completion
  • Loading branch information
zth committed Jan 2, 2025
commit b1c68509f4cd825c5e98bd6280e43af9331b1ba7
26 changes: 22 additions & 4 deletions analysis/src/CompletionBackEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
path @ [fieldName]
|> getCompletionsForPath ~debug ~opens ~full ~pos ~exact
~completionContext:Field ~env ~scope
| CPField {contextPath = cp; fieldName; fieldNameLoc; posOfDot} -> (
| CPField {contextPath = cp; fieldName; posOfDot; exprLoc} -> (
if Debug.verbose () then print_endline "[dot_completion]--> Triggered";
let completionsFromCtxPath =
cp
Expand All @@ -1102,10 +1102,28 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
DotCompletionUtils.fieldCompletionsForDotCompletion typ ~env ~package
~prefix:fieldName ?posOfDot ~exact
in
let cpAsPipeCompletion =
Completable.CPPipe
{
contextPath =
(match cp with
| CPApply (c, args) -> CPApply (c, args @ [Asttypes.Nolabel])
| c -> c);
id = fieldName;
inJsx = false;
lhsLoc = exprLoc;
}
in
let completionsFromPipeCtxPath =
cpAsPipeCompletion
|> getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos
~env:envCompletionIsMadeFrom ~exact ~scope
in
let pipeCompletions =
getPipeCompletions ~env ~full ~identifierLoc:fieldNameLoc ?posOfDot
~envCompletionIsMadeFrom ~debug ~opens ~rawOpens ~scope ~pos
~inJsx:false ~prefix:fieldName ~formatCompletionsWithPipes:true typ
completionsFromPipeCtxPath
|> List.filter_map (fun c ->
TypeUtils.transformCompletionToPipeCompletion ~synthetic:true
~env ?posOfDot c)
in
fieldCompletions @ pipeCompletions)
| CPObj (cp, label) -> (
Expand Down
24 changes: 12 additions & 12 deletions analysis/src/CompletionFrontEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,19 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
| Pexp_ident {txt; loc} ->
Some
(CPId {path = Utils.flattenLongIdent txt; completionContext = Value; loc})
| Pexp_field (e1, {txt = Lident name; loc}) -> (
| Pexp_field (e1, {txt = Lident name}) -> (
match exprToContextPath e1 with
| Some contextPath ->
Some
(CPField
{contextPath; fieldName = name; fieldNameLoc = loc; posOfDot = None})
{
contextPath;
fieldName = name;
posOfDot = None;
exprLoc = e1.pexp_loc;
})
| _ -> None)
| Pexp_field (_, {loc; txt = Ldot (lid, name)}) ->
| Pexp_field (e1, {loc; txt = Ldot (lid, name)}) ->
(* Case x.M.field ignore the x part *)
Some
(CPField
Expand All @@ -242,8 +247,8 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
loc;
};
fieldName = name;
fieldNameLoc = loc;
posOfDot = None;
exprLoc = e1.pexp_loc;
})
| Pexp_send (e1, {txt}) -> (
match exprToContextPath e1 with
Expand Down Expand Up @@ -1170,8 +1175,8 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
{
contextPath;
fieldName = name;
fieldNameLoc = fieldName.loc;
posOfDot;
exprLoc = e.pexp_loc;
}
in
setResult (Cpath contextPath)
Expand All @@ -1193,8 +1198,8 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
(* x.M. field ---> M. *) ""
else if name = "_" then ""
else name);
fieldNameLoc = fieldName.loc;
posOfDot;
exprLoc = e.pexp_loc;
}
in
setResult (Cpath contextPath)
Expand All @@ -1208,13 +1213,8 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
{
contextPath;
fieldName = "";
fieldNameLoc =
{
loc_start = e.pexp_loc.loc_end;
loc_end = e.pexp_loc.loc_end;
loc_ghost = false;
};
posOfDot;
exprLoc = e.pexp_loc;
}))
| None -> ())
| Pexp_apply ({pexp_desc = Pexp_ident compName}, args)
Expand Down
2 changes: 1 addition & 1 deletion analysis/src/SharedTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ module Completable = struct
contextPath: contextPath;
fieldName: string;
posOfDot: (int * int) option;
fieldNameLoc: Location.t;
exprLoc: Location.t;
}
| CPObj of contextPath * string
| CPAwait of contextPath
Expand Down
9 changes: 9 additions & 0 deletions analysis/tests/src/DotPipeCompletionSpec.res
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,12 @@ let ffff: builtinType = []
let nnn: typeOutsideModule = {nname: "hello"}
// nnn.
// ^com

// Continuous completion
let xxxx = [1, 2]

// xxxx->Js.Array2.filter(v => v > 10).filt
// ^com

// xxxx->Js.Array2.filter(v => v > 10)->Js.Array2.joinWith(",").includ
// ^com
54 changes: 54 additions & 0 deletions analysis/tests/src/expected/Completion.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,9 @@ Resolved opens 1 pervasives
ContextPath Value[r].""
ContextPath Value[r]
Path r
ContextPath Value[r]->
ContextPath Value[r]
Path r
CPPipe pathFromEnv: found:true
Path Completion.
[{
Expand All @@ -748,6 +751,9 @@ Resolved opens 1 pervasives
ContextPath Value[Objects, Rec, recordVal].""
ContextPath Value[Objects, Rec, recordVal]
Path Objects.Rec.recordVal
ContextPath Value[Objects, Rec, recordVal]->
ContextPath Value[Objects, Rec, recordVal]
Path Objects.Rec.recordVal
CPPipe pathFromEnv:Rec found:true
Path Objects.Rec.
[{
Expand Down Expand Up @@ -832,6 +838,18 @@ ContextPath Value[q].aa.""
ContextPath Value[q].aa
ContextPath Value[q]
Path q
ContextPath Value[q]->aa
ContextPath Value[q]
Path q
CPPipe pathFromEnv: found:true
Path Completion.aa
ContextPath Value[q].aa->
ContextPath Value[q].aa
ContextPath Value[q]
Path q
ContextPath Value[q]->aa
ContextPath Value[q]
Path q
CPPipe pathFromEnv: found:true
Path Completion.aa
CPPipe pathFromEnv: found:true
Expand Down Expand Up @@ -860,6 +878,18 @@ ContextPath Value[q].aa.n
ContextPath Value[q].aa
ContextPath Value[q]
Path q
ContextPath Value[q]->aa
ContextPath Value[q]
Path q
CPPipe pathFromEnv: found:true
Path Completion.aa
ContextPath Value[q].aa->n
ContextPath Value[q].aa
ContextPath Value[q]
Path q
ContextPath Value[q]->aa
ContextPath Value[q]
Path q
CPPipe pathFromEnv: found:true
Path Completion.aa
CPPipe pathFromEnv: found:true
Expand Down Expand Up @@ -1088,6 +1118,10 @@ ContextPath Value[FAO, forAutoObject]["forAutoLabel"].""
ContextPath Value[FAO, forAutoObject]["forAutoLabel"]
ContextPath Value[FAO, forAutoObject]
Path FAO.forAutoObject
ContextPath Value[FAO, forAutoObject]["forAutoLabel"]->
ContextPath Value[FAO, forAutoObject]["forAutoLabel"]
ContextPath Value[FAO, forAutoObject]
Path FAO.forAutoObject
CPPipe pathFromEnv:FAR found:true
Path FAR.
[{
Expand Down Expand Up @@ -1115,6 +1149,10 @@ ContextPath Value[FAO, forAutoObject]["forAutoLabel"].forAuto
ContextPath Value[FAO, forAutoObject]["forAutoLabel"]
ContextPath Value[FAO, forAutoObject]
Path FAO.forAutoObject
ContextPath Value[FAO, forAutoObject]["forAutoLabel"]->forAuto
ContextPath Value[FAO, forAutoObject]["forAutoLabel"]
ContextPath Value[FAO, forAutoObject]
Path FAO.forAutoObject
CPPipe pathFromEnv:FAR found:true
Path FAR.forAuto
CPPipe pathFromEnv:ForAuto found:false
Expand Down Expand Up @@ -1198,6 +1236,9 @@ Resolved opens 3 pervasives Completion.res Completion.res
ContextPath Value[_z].""
ContextPath Value[_z]
Path _z
ContextPath Value[_z]->
ContextPath Value[_z]
Path _z
CPPipe pathFromEnv: found:true
Path Completion.
[{
Expand Down Expand Up @@ -1358,6 +1399,9 @@ Resolved opens 3 pervasives Completion.res Completion.res
ContextPath Value[funRecord].someFun
ContextPath Value[funRecord]
Path funRecord
ContextPath Value[funRecord]->someFun
ContextPath Value[funRecord]
Path funRecord
CPPipe pathFromEnv: found:true
Path Completion.someFun
Found type for function (~name: string) => unit
Expand All @@ -1380,6 +1424,10 @@ ContextPath Value[retAA](Nolabel).""
ContextPath Value[retAA](Nolabel)
ContextPath Value[retAA]
Path retAA
ContextPath Value[retAA](Nolabel, Nolabel)->
ContextPath Value[retAA](Nolabel, Nolabel)
ContextPath Value[retAA]
Path retAA
CPPipe pathFromEnv: found:true
Path Completion.
[{
Expand Down Expand Up @@ -1912,6 +1960,9 @@ Resolved opens 3 pervasives Completion.res Completion.res
ContextPath Value[funRecord].""
ContextPath Value[funRecord]
Path funRecord
ContextPath Value[funRecord]->
ContextPath Value[funRecord]
Path funRecord
CPPipe pathFromEnv: found:true
Path Completion.
[{
Expand Down Expand Up @@ -2166,6 +2217,9 @@ Resolved opens 3 pervasives Completion.res Completion.res
ContextPath Value[rWithDepr].so
ContextPath Value[rWithDepr]
Path rWithDepr
ContextPath Value[rWithDepr]->so
ContextPath Value[rWithDepr]
Path rWithDepr
CPPipe pathFromEnv: found:true
Path Completion.so
[{
Expand Down
9 changes: 9 additions & 0 deletions analysis/tests/src/expected/CompletionExpressions.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,9 @@ Resolved opens 1 pervasives
ContextPath Value[fff].someOpt
ContextPath Value[fff]
Path fff
ContextPath Value[fff]->someOpt
ContextPath Value[fff]
Path fff
CPPipe pathFromEnv: found:true
Path CompletionExpressions.someOpt
[{
Expand Down Expand Up @@ -1417,6 +1420,9 @@ Resolved opens 2 pervasives CompletionSupport.res
ContextPath Value[someTyp].""
ContextPath Value[someTyp]
Path someTyp
ContextPath Value[someTyp]->
ContextPath Value[someTyp]
Path someTyp
CPPipe pathFromEnv: found:true
Path CompletionExpressions.
[{
Expand Down Expand Up @@ -1474,6 +1480,9 @@ Resolved opens 2 pervasives CompletionSupport.res
ContextPath Value[someTyp].""
ContextPath Value[someTyp]
Path someTyp
ContextPath Value[someTyp]->
ContextPath Value[someTyp]
Path someTyp
CPPipe pathFromEnv: found:true
Path CompletionExpressions.
[{
Expand Down
6 changes: 6 additions & 0 deletions analysis/tests/src/expected/CompletionFromModule.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Resolved opens 1 pervasives
ContextPath Value[n].""
ContextPath Value[n]
Path n
ContextPath Value[n]->
ContextPath Value[n]
Path n
CPPipe pathFromEnv:SomeModule found:true
Path SomeModule.
[{
Expand Down Expand Up @@ -38,6 +41,9 @@ Resolved opens 1 pervasives
ContextPath Value[nn].""
ContextPath Value[nn]
Path nn
ContextPath Value[nn]->
ContextPath Value[nn]
Path nn
CPPipe pathFromEnv:SomeOtherModule found:true
Path SomeOtherModule.
Path CompletionFromModule.SomeOtherModule.
Expand Down
6 changes: 6 additions & 0 deletions analysis/tests/src/expected/CompletionFromModule2.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Resolved opens 1 pervasives
ContextPath Value[CompletionFromModule, n].""
ContextPath Value[CompletionFromModule, n]
Path CompletionFromModule.n
ContextPath Value[CompletionFromModule, n]->
ContextPath Value[CompletionFromModule, n]
Path CompletionFromModule.n
CPPipe pathFromEnv:SomeModule found:true
Path CompletionFromModule.SomeModule.
[{
Expand Down Expand Up @@ -38,6 +41,9 @@ Resolved opens 1 pervasives
ContextPath Value[CompletionFromModule, nn].""
ContextPath Value[CompletionFromModule, nn]
Path CompletionFromModule.nn
ContextPath Value[CompletionFromModule, nn]->
ContextPath Value[CompletionFromModule, nn]
Path CompletionFromModule.nn
CPPipe pathFromEnv:SomeOtherModule found:true
Path CompletionFromModule.SomeOtherModule.
Path CompletionFromModule.SomeOtherModule.
Expand Down
Loading