@@ -1765,125 +1765,118 @@ let printConstructorArgs argsLen ~asSnippet =
1765
1765
if List. length ! args > 0 then " (" ^ (! args |> String. concat " , " ) ^ " )"
1766
1766
else " "
1767
1767
1768
- let completeTypedValue ~env ~full ~prefix ~completionContext =
1769
- let completeTypedValueInner t ~env ~full ~prefix =
1770
- let items =
1771
- match t |> extractType ~env ~package: full.package with
1772
- | Some (Tbool env ) ->
1773
- [
1774
- Completion. create ~name: " true"
1775
- ~kind: (Label (t |> Shared. typeToString))
1776
- ~env ;
1777
- Completion. create ~name: " false"
1778
- ~kind: (Label (t |> Shared. typeToString))
1779
- ~env ;
1780
- ]
1781
- |> filterItems ~prefix
1782
- | Some (Tvariant {env; constructors; variantDecl; variantName} ) ->
1783
- constructors
1784
- |> List. map (fun (constructor : Constructor.t ) ->
1785
- Completion. createWithSnippet
1786
- ~name:
1787
- (constructor.cname.txt
1788
- ^ printConstructorArgs
1789
- (List. length constructor.args)
1790
- ~as Snippet:false )
1791
- ~insert Text:
1792
- (constructor.cname.txt
1793
- ^ printConstructorArgs
1794
- (List. length constructor.args)
1795
- ~as Snippet:true )
1796
- ~kind:
1797
- (Constructor
1798
- ( constructor,
1799
- variantDecl |> Shared. declToString variantName ))
1800
- ~env () )
1801
- |> filterItems ~prefix
1802
- | Some (Tpolyvariant {env; constructors; typeExpr} ) ->
1803
- constructors
1804
- |> List. map (fun (constructor : polyVariantConstructor ) ->
1805
- Completion. createWithSnippet
1806
- ~name:
1807
- (" #" ^ constructor.name
1808
- ^ printConstructorArgs
1809
- (List. length constructor.args)
1810
- ~as Snippet:false )
1811
- ~insert Text:
1812
- ((if Utils. startsWith prefix " #" then " " else " #" )
1813
- ^ constructor.name
1814
- ^ printConstructorArgs
1815
- (List. length constructor.args)
1816
- ~as Snippet:true )
1817
- ~kind:
1818
- (PolyvariantConstructor
1819
- (constructor, typeExpr |> Shared. typeToString))
1820
- ~env () )
1821
- |> filterItems ~prefix
1822
- | Some (Toption (env , t )) ->
1823
- [
1824
- Completion. create ~name: " None"
1825
- ~kind: (Label (t |> Shared. typeToString))
1826
- ~env ;
1827
- Completion. createWithSnippet ~name: " Some(_)"
1828
- ~kind: (Label (t |> Shared. typeToString))
1829
- ~env ~insert Text:" Some(${1:_})" () ;
1830
- ]
1831
- |> filterItems ~prefix
1832
- | Some (Tuple (env , exprs , typ )) ->
1833
- let numExprs = List. length exprs in
1768
+ let completeTypedValue (t : Types.type_expr ) ~env ~full ~prefix
1769
+ ~completionContext =
1770
+ match t |> extractType ~env ~package: full.package with
1771
+ | Some (Tbool env ) ->
1772
+ [
1773
+ Completion. create ~name: " true"
1774
+ ~kind: (Label (t |> Shared. typeToString))
1775
+ ~env ;
1776
+ Completion. create ~name: " false"
1777
+ ~kind: (Label (t |> Shared. typeToString))
1778
+ ~env ;
1779
+ ]
1780
+ |> filterItems ~prefix
1781
+ | Some (Tvariant {env; constructors; variantDecl; variantName} ) ->
1782
+ constructors
1783
+ |> List. map (fun (constructor : Constructor.t ) ->
1784
+ Completion. createWithSnippet
1785
+ ~name:
1786
+ (constructor.cname.txt
1787
+ ^ printConstructorArgs
1788
+ (List. length constructor.args)
1789
+ ~as Snippet:false )
1790
+ ~insert Text:
1791
+ (constructor.cname.txt
1792
+ ^ printConstructorArgs
1793
+ (List. length constructor.args)
1794
+ ~as Snippet:true )
1795
+ ~kind:
1796
+ (Constructor
1797
+ (constructor, variantDecl |> Shared. declToString variantName))
1798
+ ~env () )
1799
+ |> filterItems ~prefix
1800
+ | Some (Tpolyvariant {env; constructors; typeExpr} ) ->
1801
+ constructors
1802
+ |> List. map (fun (constructor : polyVariantConstructor ) ->
1803
+ Completion. createWithSnippet
1804
+ ~name:
1805
+ (" #" ^ constructor.name
1806
+ ^ printConstructorArgs
1807
+ (List. length constructor.args)
1808
+ ~as Snippet:false )
1809
+ ~insert Text:
1810
+ ((if Utils. startsWith prefix " #" then " " else " #" )
1811
+ ^ constructor.name
1812
+ ^ printConstructorArgs
1813
+ (List. length constructor.args)
1814
+ ~as Snippet:true )
1815
+ ~kind:
1816
+ (PolyvariantConstructor
1817
+ (constructor, typeExpr |> Shared. typeToString))
1818
+ ~env () )
1819
+ |> filterItems ~prefix
1820
+ | Some (Toption (env , t )) ->
1821
+ [
1822
+ Completion. create ~name: " None"
1823
+ ~kind: (Label (t |> Shared. typeToString))
1824
+ ~env ;
1825
+ Completion. createWithSnippet ~name: " Some(_)"
1826
+ ~kind: (Label (t |> Shared. typeToString))
1827
+ ~env ~insert Text:" Some(${1:_})" () ;
1828
+ ]
1829
+ |> filterItems ~prefix
1830
+ | Some (Tuple (env , exprs , typ )) ->
1831
+ let numExprs = List. length exprs in
1832
+ [
1833
+ Completion. createWithSnippet
1834
+ ~name: (printConstructorArgs numExprs ~as Snippet:false )
1835
+ ~insert Text:(printConstructorArgs numExprs ~as Snippet:true )
1836
+ ~kind: (Value typ) ~env () ;
1837
+ ]
1838
+ | Some (Trecord {env; fields; typeExpr} ) -> (
1839
+ (* As we're completing for a record, we'll need a hint (completionContext)
1840
+ here to figure out whether we should complete for a record field, or
1841
+ the record body itself. *)
1842
+ match completionContext with
1843
+ | Some (Completable. RecordField {seenFields} ) ->
1844
+ fields
1845
+ |> List. filter (fun (field : field ) ->
1846
+ List. mem field.fname.txt seenFields = false )
1847
+ |> List. map (fun (field : field ) ->
1848
+ Completion. create ~name: field.fname.txt
1849
+ ~kind: (Field (field, typeExpr |> Shared. typeToString))
1850
+ ~env )
1851
+ |> filterItems ~prefix
1852
+ | None ->
1853
+ if prefix = " " then
1834
1854
[
1835
- Completion. createWithSnippet
1836
- ~name: (printConstructorArgs numExprs ~as Snippet:false )
1837
- ~insert Text:(printConstructorArgs numExprs ~as Snippet:true )
1838
- ~kind: (Value typ) ~env () ;
1855
+ Completion. createWithSnippet ~name: " {}"
1856
+ ~insert Text:(if ! Cfg. supportsSnippets then " {$0}" else " {}" )
1857
+ ~sort Text:" A" ~kind: (Value typeExpr) ~env () ;
1839
1858
]
1840
- | Some (Trecord {env; fields; typeExpr} ) -> (
1841
- (* As we're completing for a record, we'll need a hint (completionContext)
1842
- here to figure out whether we should complete for a record field, or
1843
- the record body itself. *)
1844
- match completionContext with
1845
- | Some (Completable. RecordField {seenFields} ) ->
1846
- fields
1847
- |> List. filter (fun (field : field ) ->
1848
- List. mem field.fname.txt seenFields = false )
1849
- |> List. map (fun (field : field ) ->
1850
- Completion. create ~name: field.fname.txt
1851
- ~kind: (Field (field, typeExpr |> Shared. typeToString))
1852
- ~env )
1853
- |> filterItems ~prefix
1854
- | None ->
1855
- if prefix = " " then
1856
- [
1857
- Completion. createWithSnippet ~name: " {}"
1858
- ~insert Text:(if ! Cfg. supportsSnippets then " {$0}" else " {}" )
1859
- ~sort Text:" A" ~kind: (Value typeExpr) ~env () ;
1860
- ]
1861
- else [] )
1862
- | Some (Tarray (env , typeExpr )) ->
1863
- if prefix = " " then
1864
- [
1865
- Completion. createWithSnippet ~name: " []"
1866
- ~insert Text:(if ! Cfg. supportsSnippets then " [$0]" else " []" )
1867
- ~sort Text:" A" ~kind: (Value typeExpr) ~env () ;
1868
- ]
1869
- else []
1870
- | Some (Tstring env ) ->
1871
- if prefix = " " then
1872
- [
1873
- Completion. createWithSnippet ~name: " \"\" "
1874
- ~insert Text:(if ! Cfg. supportsSnippets then " \" $0\" " else " \"\" " )
1875
- ~sort Text:" A"
1876
- ~kind:
1877
- (Value
1878
- (Ctype. newconstr (Path. Pident (Ident. create " string" )) [] ))
1879
- ~env () ;
1880
- ]
1881
- else []
1882
- | _ -> []
1883
- in
1884
- items
1885
- in
1886
- completeTypedValueInner ~env ~full ~prefix
1859
+ else [] )
1860
+ | Some (Tarray (env , typeExpr )) ->
1861
+ if prefix = " " then
1862
+ [
1863
+ Completion. createWithSnippet ~name: " []"
1864
+ ~insert Text:(if ! Cfg. supportsSnippets then " [$0]" else " []" )
1865
+ ~sort Text:" A" ~kind: (Value typeExpr) ~env () ;
1866
+ ]
1867
+ else []
1868
+ | Some (Tstring env ) ->
1869
+ if prefix = " " then
1870
+ [
1871
+ Completion. createWithSnippet ~name: " \"\" "
1872
+ ~insert Text:(if ! Cfg. supportsSnippets then " \" $0\" " else " \"\" " )
1873
+ ~sort Text:" A"
1874
+ ~kind:
1875
+ (Value (Ctype. newconstr (Path. Pident (Ident. create " string" )) [] ))
1876
+ ~env () ;
1877
+ ]
1878
+ else []
1879
+ | _ -> []
1887
1880
1888
1881
(* * This moves through a nested path via a set of instructions, trying to resolve the type at the end of the path. *)
1889
1882
let rec resolveNested typ ~env ~package ~nested =
0 commit comments