Skip to content
This repository was archived by the owner on Apr 24, 2021. It is now read-only.

Commit dd83be0

Browse files
committed
Pipe autocomplete for array literals and types.
1 parent ae9c086 commit dd83be0

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

examples/example-project/src/ZZ.res

+2
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,5 @@ let lll = List.make(3, 4)
138138

139139
let abc = "abc"
140140

141+
let arr = [1, 2, 3]
142+

src/NewCompletions.ml

+3
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ let processCompletable ~findItems ~full ~package ~pos ~rawOpens
513513
mkItem ~name ~kind:(kindToInt item) ~deprecated
514514
~detail:(detail name item) ~docstring ~uri ~pos_lnum)
515515
| Cpipe (pipe, partialName) -> (
516+
let arrayModulePath = ["Js"; "Array2"] in
516517
let stringModulePath = ["Js"; "String2"] in
517518
let getModulePath path =
518519
let rec loop (path : Path.t) =
@@ -523,6 +524,7 @@ let processCompletable ~findItems ~full ~package ~pos ~rawOpens
523524
in
524525
match path with
525526
| Path.Pident id when Ident.name id = "string" -> stringModulePath
527+
| Path.Pident id when Ident.name id = "array" -> arrayModulePath
526528
| _ -> ( match loop path with _ :: rest -> List.rev rest | [] -> [])
527529
in
528530
let getLhsPath ~pipeId ~partialName =
@@ -541,6 +543,7 @@ let processCompletable ~findItems ~full ~package ~pos ~rawOpens
541543
match pipe with
542544
| PipeId pipeId -> getLhsPath ~pipeId ~partialName
543545
| PipeString -> Some (stringModulePath, partialName)
546+
| PipeArray -> Some (arrayModulePath, partialName)
544547
in
545548
let removePackageOpens modulePath =
546549
match modulePath with

src/PartialParser.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ let findJsxContext text offset =
109109
in
110110
loop offset
111111

112-
type pipe = PipeId of string | PipeString
112+
type pipe = PipeId of string | PipeArray | PipeString
113113

114114
type completable =
115115
| Cdecorator of string (** e.g. @module *)
@@ -155,6 +155,7 @@ let findCompletable text offset =
155155
match text.[i] with
156156
| 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '.' | '_' -> loop (i - 1)
157157
| '"' when i == off -> Some PipeString
158+
| ']' when i == off -> Some PipeArray
158159
| _ -> Some (PipeId (String.sub text (i + 1) (off - i))))
159160
in
160161
match loop off with

0 commit comments

Comments
 (0)