typeprof 0.20.0 → 0.20.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (344) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/doc/ide.md +81 -0
  4. data/doc/typeprof-for-ide-log.png +0 -0
  5. data/doc/typeprof-for-ide.png +0 -0
  6. data/lib/typeprof/analyzer.rb +7 -2
  7. data/lib/typeprof/cli.rb +1 -3
  8. data/lib/typeprof/config.rb +1 -5
  9. data/lib/typeprof/import.rb +22 -19
  10. data/lib/typeprof/iseq.rb +5 -0
  11. data/lib/typeprof/lsp.rb +40 -21
  12. data/lib/typeprof/version.rb +1 -1
  13. data/lib/typeprof.rb +0 -5
  14. data/typeprof.gemspec +1 -1
  15. metadata +5 -331
  16. data/smoke/alias.rb +0 -31
  17. data/smoke/alias2.rb +0 -21
  18. data/smoke/any-cbase.rb +0 -5
  19. data/smoke/any1.rb +0 -16
  20. data/smoke/any2.rb +0 -18
  21. data/smoke/arguments.rb +0 -17
  22. data/smoke/arguments2.rb +0 -56
  23. data/smoke/array-each.rb +0 -15
  24. data/smoke/array-each2.rb +0 -16
  25. data/smoke/array-each3.rb +0 -13
  26. data/smoke/array-ltlt.rb +0 -14
  27. data/smoke/array-ltlt2.rb +0 -17
  28. data/smoke/array-map.rb +0 -12
  29. data/smoke/array-map2.rb +0 -11
  30. data/smoke/array-map3.rb +0 -23
  31. data/smoke/array-mul.rb +0 -18
  32. data/smoke/array-plus1.rb +0 -11
  33. data/smoke/array-plus2.rb +0 -16
  34. data/smoke/array-pop.rb +0 -12
  35. data/smoke/array-range-aref.rb +0 -71
  36. data/smoke/array-replace.rb +0 -13
  37. data/smoke/array-s-aref.rb +0 -12
  38. data/smoke/array1.rb +0 -27
  39. data/smoke/array10.rb +0 -15
  40. data/smoke/array11.rb +0 -14
  41. data/smoke/array12.rb +0 -25
  42. data/smoke/array13.rb +0 -31
  43. data/smoke/array14.rb +0 -14
  44. data/smoke/array15.rb +0 -16
  45. data/smoke/array2.rb +0 -28
  46. data/smoke/array3.rb +0 -26
  47. data/smoke/array4.rb +0 -15
  48. data/smoke/array5.rb +0 -14
  49. data/smoke/array6.rb +0 -17
  50. data/smoke/array7.rb +0 -14
  51. data/smoke/array8.rb +0 -13
  52. data/smoke/array9.rb +0 -13
  53. data/smoke/attr-module.rb +0 -24
  54. data/smoke/attr-vis.rb +0 -43
  55. data/smoke/attr-vis.rbs +0 -4
  56. data/smoke/attr.rb +0 -28
  57. data/smoke/autoload.rb +0 -14
  58. data/smoke/backtrace.rb +0 -33
  59. data/smoke/block-ambiguous.rb +0 -37
  60. data/smoke/block-args1-rest.rb +0 -64
  61. data/smoke/block-args1.rb +0 -60
  62. data/smoke/block-args2-rest.rb +0 -64
  63. data/smoke/block-args2.rb +0 -60
  64. data/smoke/block-args3-rest.rb +0 -75
  65. data/smoke/block-args3.rb +0 -71
  66. data/smoke/block-blockarg.rb +0 -28
  67. data/smoke/block-kwarg.rb +0 -53
  68. data/smoke/block1.rb +0 -23
  69. data/smoke/block10.rb +0 -15
  70. data/smoke/block11.rb +0 -40
  71. data/smoke/block12.rb +0 -23
  72. data/smoke/block13.rb +0 -9
  73. data/smoke/block13.rbs +0 -3
  74. data/smoke/block14.rb +0 -18
  75. data/smoke/block2.rb +0 -15
  76. data/smoke/block3.rb +0 -38
  77. data/smoke/block4.rb +0 -19
  78. data/smoke/block5.rb +0 -21
  79. data/smoke/block6.rb +0 -21
  80. data/smoke/block7.rb +0 -19
  81. data/smoke/block8.rb +0 -28
  82. data/smoke/block9.rb +0 -13
  83. data/smoke/block_given.rb +0 -37
  84. data/smoke/blown.rb +0 -13
  85. data/smoke/break1.rb +0 -19
  86. data/smoke/break2.rb +0 -16
  87. data/smoke/break3.rb +0 -13
  88. data/smoke/break4.rb +0 -17
  89. data/smoke/case.rb +0 -17
  90. data/smoke/case2.rb +0 -18
  91. data/smoke/case3.rb +0 -17
  92. data/smoke/class-hierarchy.rb +0 -54
  93. data/smoke/class-hierarchy2.rb +0 -27
  94. data/smoke/class-new.rb +0 -15
  95. data/smoke/class.rb +0 -7
  96. data/smoke/class_eval.rb +0 -22
  97. data/smoke/class_instance_var.rb +0 -9
  98. data/smoke/class_method.rb +0 -25
  99. data/smoke/class_method2.rb +0 -21
  100. data/smoke/class_method3.rb +0 -29
  101. data/smoke/constant1.rb +0 -46
  102. data/smoke/constant2.rb +0 -36
  103. data/smoke/constant3.rb +0 -10
  104. data/smoke/constant4.rb +0 -12
  105. data/smoke/context-sensitive1.rb +0 -13
  106. data/smoke/cvar.rb +0 -31
  107. data/smoke/cvar2.rb +0 -17
  108. data/smoke/define_method.rb +0 -16
  109. data/smoke/define_method2.rb +0 -18
  110. data/smoke/define_method3.rb +0 -14
  111. data/smoke/define_method3.rbs +0 -3
  112. data/smoke/define_method4.rb +0 -15
  113. data/smoke/define_method4.rbs +0 -3
  114. data/smoke/define_method5.rb +0 -12
  115. data/smoke/define_method6.rb +0 -19
  116. data/smoke/define_method7.rb +0 -18
  117. data/smoke/demo.rb +0 -81
  118. data/smoke/demo1.rb +0 -17
  119. data/smoke/demo10.rb +0 -21
  120. data/smoke/demo11.rb +0 -12
  121. data/smoke/demo2.rb +0 -15
  122. data/smoke/demo3.rb +0 -17
  123. data/smoke/demo4.rb +0 -27
  124. data/smoke/demo5.rb +0 -16
  125. data/smoke/demo6.rb +0 -22
  126. data/smoke/demo7.rb +0 -15
  127. data/smoke/demo8.rb +0 -19
  128. data/smoke/demo9.rb +0 -18
  129. data/smoke/dummy-execution1.rb +0 -15
  130. data/smoke/dummy-execution2.rb +0 -16
  131. data/smoke/dummy_element.rb +0 -14
  132. data/smoke/ensure1.rb +0 -21
  133. data/smoke/enum_for.rb +0 -15
  134. data/smoke/enum_for2.rb +0 -17
  135. data/smoke/enumerator.rb +0 -16
  136. data/smoke/expandarray1.rb +0 -23
  137. data/smoke/expandarray2.rb +0 -24
  138. data/smoke/extended.rb +0 -38
  139. data/smoke/fib.rb +0 -28
  140. data/smoke/flip-flop.rb +0 -28
  141. data/smoke/flow1.rb +0 -17
  142. data/smoke/flow10.rb +0 -17
  143. data/smoke/flow11.rb +0 -17
  144. data/smoke/flow2.rb +0 -15
  145. data/smoke/flow3.rb +0 -15
  146. data/smoke/flow4.rb +0 -5
  147. data/smoke/flow5.rb +0 -20
  148. data/smoke/flow6.rb +0 -20
  149. data/smoke/flow7.rb +0 -21
  150. data/smoke/flow8.rb +0 -14
  151. data/smoke/flow9.rb +0 -12
  152. data/smoke/for.rb +0 -9
  153. data/smoke/freeze.rb +0 -12
  154. data/smoke/function.rb +0 -17
  155. data/smoke/gvar.rb +0 -14
  156. data/smoke/gvar2.rb +0 -15
  157. data/smoke/gvar2.rbs +0 -1
  158. data/smoke/hash-bot.rb +0 -12
  159. data/smoke/hash-fetch.rb +0 -28
  160. data/smoke/hash-merge-bang.rb +0 -12
  161. data/smoke/hash1.rb +0 -20
  162. data/smoke/hash2.rb +0 -13
  163. data/smoke/hash3.rb +0 -14
  164. data/smoke/hash4.rb +0 -11
  165. data/smoke/hash5.rb +0 -14
  166. data/smoke/huge_union.rb +0 -86
  167. data/smoke/identifier_keywords.rb +0 -17
  168. data/smoke/included.rb +0 -38
  169. data/smoke/inheritance.rb +0 -34
  170. data/smoke/inheritance2.rb +0 -35
  171. data/smoke/inherited.rb +0 -26
  172. data/smoke/initialize.rb +0 -28
  173. data/smoke/instance_eval.rb +0 -18
  174. data/smoke/instance_eval2.rb +0 -10
  175. data/smoke/instance_eval3.rb +0 -25
  176. data/smoke/instance_eval4.rb +0 -12
  177. data/smoke/int_times.rb +0 -15
  178. data/smoke/integer.rb +0 -11
  179. data/smoke/ivar.rb +0 -31
  180. data/smoke/ivar2.rb +0 -30
  181. data/smoke/ivar3.rb +0 -17
  182. data/smoke/ivar3.rbs +0 -3
  183. data/smoke/ivar4.rb +0 -21
  184. data/smoke/kernel-class.rb +0 -13
  185. data/smoke/keyword1.rb +0 -12
  186. data/smoke/keyword2.rb +0 -12
  187. data/smoke/keyword3.rb +0 -12
  188. data/smoke/keyword4.rb +0 -12
  189. data/smoke/keyword5.rb +0 -16
  190. data/smoke/kwrest.rb +0 -13
  191. data/smoke/kwrest.rbs +0 -3
  192. data/smoke/kwsplat1.rb +0 -43
  193. data/smoke/kwsplat2.rb +0 -13
  194. data/smoke/lit-complex.rb +0 -10
  195. data/smoke/lit-encoding.rb +0 -10
  196. data/smoke/manual-rbs.rb +0 -29
  197. data/smoke/manual-rbs.rbs +0 -3
  198. data/smoke/manual-rbs2.rb +0 -21
  199. data/smoke/manual-rbs2.rbs +0 -8
  200. data/smoke/manual-rbs3.rb +0 -13
  201. data/smoke/manual-rbs3.rbs +0 -3
  202. data/smoke/masgn1.rb +0 -14
  203. data/smoke/masgn2.rb +0 -18
  204. data/smoke/masgn3.rb +0 -13
  205. data/smoke/method_in_branch.rb +0 -23
  206. data/smoke/method_missing.rb +0 -29
  207. data/smoke/module1.rb +0 -29
  208. data/smoke/module2.rb +0 -28
  209. data/smoke/module3.rb +0 -33
  210. data/smoke/module4.rb +0 -35
  211. data/smoke/module5.rb +0 -17
  212. data/smoke/module6.rb +0 -40
  213. data/smoke/module_function1.rb +0 -29
  214. data/smoke/module_function2.rb +0 -29
  215. data/smoke/multiple-include.rb +0 -15
  216. data/smoke/multiple-superclass.rb +0 -28
  217. data/smoke/next1.rb +0 -21
  218. data/smoke/next2.rb +0 -17
  219. data/smoke/noname.rb +0 -9
  220. data/smoke/object-send1.rb +0 -23
  221. data/smoke/object-send2.rb +0 -10
  222. data/smoke/object-send3.rb +0 -18
  223. data/smoke/once.rb +0 -13
  224. data/smoke/optional1.rb +0 -14
  225. data/smoke/optional2.rb +0 -16
  226. data/smoke/optional3.rb +0 -11
  227. data/smoke/or_raise.rb +0 -18
  228. data/smoke/parameterizedd-self.rb +0 -20
  229. data/smoke/parameterizedd-self2.rb +0 -15
  230. data/smoke/pathname1.rb +0 -14
  231. data/smoke/pathname2.rb +0 -14
  232. data/smoke/pattern-match1.rb +0 -19
  233. data/smoke/pattern-match2.rb +0 -16
  234. data/smoke/prepend1.rb +0 -33
  235. data/smoke/prepend2.rb +0 -10
  236. data/smoke/prepend2.rbs +0 -9
  237. data/smoke/primitive_method.rb +0 -19
  238. data/smoke/printf.rb +0 -20
  239. data/smoke/proc.rb +0 -20
  240. data/smoke/proc2.rb +0 -17
  241. data/smoke/proc3.rb +0 -15
  242. data/smoke/proc4.rb +0 -12
  243. data/smoke/proc5.rb +0 -19
  244. data/smoke/proc6.rb +0 -13
  245. data/smoke/proc7.rb +0 -32
  246. data/smoke/public.rb +0 -38
  247. data/smoke/range.rb +0 -14
  248. data/smoke/rbs-alias.rb +0 -10
  249. data/smoke/rbs-alias.rbs +0 -4
  250. data/smoke/rbs-attr.rb +0 -27
  251. data/smoke/rbs-attr.rbs +0 -5
  252. data/smoke/rbs-attr2.rb +0 -11
  253. data/smoke/rbs-attr2.rbs +0 -3
  254. data/smoke/rbs-extend.rb +0 -10
  255. data/smoke/rbs-extend.rbs +0 -7
  256. data/smoke/rbs-interface.rb +0 -25
  257. data/smoke/rbs-interface.rbs +0 -12
  258. data/smoke/rbs-module.rb +0 -26
  259. data/smoke/rbs-module.rbs +0 -4
  260. data/smoke/rbs-opt-and-rest.rb +0 -10
  261. data/smoke/rbs-opt-and-rest.rbs +0 -3
  262. data/smoke/rbs-proc1.rb +0 -10
  263. data/smoke/rbs-proc1.rbs +0 -3
  264. data/smoke/rbs-proc2.rb +0 -21
  265. data/smoke/rbs-proc2.rbs +0 -3
  266. data/smoke/rbs-proc3.rb +0 -14
  267. data/smoke/rbs-proc3.rbs +0 -4
  268. data/smoke/rbs-record.rb +0 -18
  269. data/smoke/rbs-record.rbs +0 -4
  270. data/smoke/rbs-tyvar.rb +0 -19
  271. data/smoke/rbs-tyvar.rbs +0 -5
  272. data/smoke/rbs-tyvar2.rb +0 -21
  273. data/smoke/rbs-tyvar2.rbs +0 -9
  274. data/smoke/rbs-tyvar3.rb +0 -18
  275. data/smoke/rbs-tyvar3.rbs +0 -5
  276. data/smoke/rbs-tyvar4.rb +0 -37
  277. data/smoke/rbs-tyvar5.rb +0 -13
  278. data/smoke/rbs-tyvar5.rbs +0 -8
  279. data/smoke/rbs-tyvar6.rb +0 -18
  280. data/smoke/rbs-tyvar6.rbs +0 -12
  281. data/smoke/rbs-tyvar7.rb +0 -12
  282. data/smoke/rbs-tyvar7.rbs +0 -7
  283. data/smoke/rbs-vars.rb +0 -35
  284. data/smoke/rbs-vars.rbs +0 -7
  285. data/smoke/redo1.rb +0 -22
  286. data/smoke/redo2.rb +0 -23
  287. data/smoke/req-keyword.rb +0 -13
  288. data/smoke/require1.rb +0 -13
  289. data/smoke/require2.rb +0 -13
  290. data/smoke/rescue1.rb +0 -21
  291. data/smoke/rescue2.rb +0 -23
  292. data/smoke/rescue3.rb +0 -20
  293. data/smoke/rescue4.rb +0 -17
  294. data/smoke/respond_to.rb +0 -23
  295. data/smoke/rest-farg.rb +0 -11
  296. data/smoke/rest1.rb +0 -26
  297. data/smoke/rest2.rb +0 -31
  298. data/smoke/rest3.rb +0 -37
  299. data/smoke/rest4.rb +0 -19
  300. data/smoke/rest5.rb +0 -11
  301. data/smoke/rest6.rb +0 -12
  302. data/smoke/retry1.rb +0 -21
  303. data/smoke/return.rb +0 -14
  304. data/smoke/reveal.rb +0 -13
  305. data/smoke/simple.rb +0 -12
  306. data/smoke/singleton_class.rb +0 -8
  307. data/smoke/singleton_method.rb +0 -12
  308. data/smoke/step.rb +0 -18
  309. data/smoke/string-split.rb +0 -12
  310. data/smoke/struct-keyword_init.rb +0 -10
  311. data/smoke/struct.rb +0 -13
  312. data/smoke/struct2.rb +0 -25
  313. data/smoke/struct3.rb +0 -14
  314. data/smoke/struct4.rb +0 -7
  315. data/smoke/struct5.rb +0 -16
  316. data/smoke/struct6.rb +0 -15
  317. data/smoke/struct7.rb +0 -17
  318. data/smoke/stub-keyword.rb +0 -10
  319. data/smoke/super1.rb +0 -69
  320. data/smoke/super2.rb +0 -16
  321. data/smoke/super3.rb +0 -20
  322. data/smoke/super4.rb +0 -45
  323. data/smoke/super5.rb +0 -38
  324. data/smoke/svar1.rb +0 -13
  325. data/smoke/symbol-proc-attr.rb +0 -22
  326. data/smoke/symbol-proc-attr2.rb +0 -15
  327. data/smoke/symbol-proc-bot.rb +0 -13
  328. data/smoke/symbol-proc.rb +0 -25
  329. data/smoke/tap1.rb +0 -18
  330. data/smoke/toplevel.rb +0 -13
  331. data/smoke/two-map.rb +0 -18
  332. data/smoke/type_var.rb +0 -11
  333. data/smoke/typed_method.rb +0 -16
  334. data/smoke/uninitialize-var.rb +0 -13
  335. data/smoke/union-recv.rb +0 -35
  336. data/smoke/user-demo.rb +0 -15
  337. data/smoke/wrong-extend.rb +0 -27
  338. data/smoke/wrong-include.rb +0 -27
  339. data/smoke/wrong-include2.rb +0 -17
  340. data/smoke/wrong-rbs.rb +0 -15
  341. data/smoke/wrong-rbs.rbs +0 -7
  342. data/testbed/ao.rb +0 -297
  343. data/testbed/diff-lcs-entrypoint.rb +0 -4
  344. data/testbed/goodcheck-Gemfile.lock +0 -51
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 109bbaf7daec0e4dce2f23c17a73d9528c51441cf61f1e23f5dc5d3c2c47dbff
4
- data.tar.gz: bbd47838c15aa0e2a12645a8c9d5f56b0587323e96d919240681d747e2b73696
3
+ metadata.gz: b3938be1edd2b64861739d4ea2f801972c32fc67b4b791837e2b238d9be3a5bb
4
+ data.tar.gz: 8ba23caae4ab25ea713a1b4fca1850cbc44954aaecabcfd9a3e7a3db18c6ea4b
5
5
  SHA512:
6
- metadata.gz: 6e1ff8245d59eb81f253544b9a1a0e6a54f154fb17634e739210d4320e96619d59b70f9efd6811f600ab67e52ea341d3d9a886ab2b00d397ede5594f23ce8340
7
- data.tar.gz: 2723c535e5f42e13e419e2646607ba9a5ec0a90c266fd2a927e658b133703f658af0cdfc2f392c6acd7f6f96fbbb54019251163f2109b1624158a48e019a56f2
6
+ metadata.gz: e946bed7229effa1d0d95fd665875b39344d8aa959e6fa126631b914e8f9ead55a2a5cababd2ea390f1275b04d1e73bec2b4969c3ccc549acfdeb09512ed8626
7
+ data.tar.gz: e31d656a00087bb096c91e2c3da129e7d81ee480e99d67685b1c458a5cbf1a2e97c3ea0feef1657b1a895fc44bd2011ba3fd6ef8b387833967e99c1c728b6e4b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- typeprof (0.20.0)
4
+ typeprof (0.20.1)
5
5
  rbs (>= 1.6.2)
6
6
 
7
7
  GEM
data/doc/ide.md ADDED
@@ -0,0 +1,81 @@
1
+ # How to use TypeProf for IDE
2
+
3
+ First, try it with an already-configured repository!
4
+
5
+ 1. `rbenv install 3.1.0-dev`
6
+ 2. `git clone https://github.com/mame/rbswiki`
7
+ 3. `cd rbswiki && bundle install`
8
+ 4. `rbs collection install`
9
+ 5. install [VSCode extension for TypeProf](https://marketplace.visualstudio.com/items?itemName=mame.ruby-typeprof) to your VSCode
10
+ 6. open the `rbswiki` folder by VSCode
11
+ 7. open `lib/rbswiki/wiki.rb`
12
+
13
+ If everything goes well, you will see guessed signatures for each method:
14
+
15
+ ![Screenshot](typeprof-for-ide.png)
16
+
17
+ ### Troubleshooting
18
+
19
+ * Make sure that you are using ruby 3.1.0-dev.
20
+
21
+ ```
22
+ $ ruby -v
23
+ ruby 3.1.0dev (2021-09-28T11:03:54Z master 545e01645f) [x86_64-linux]
24
+ ```
25
+
26
+ * Check if typeprof version is 0.20.0 or later.
27
+
28
+ ```
29
+ $ bundle exec typeprof --version
30
+ typeprof 0.20.0
31
+ ```
32
+
33
+ * Check if TypeProf can analyze `lib/rbswiki/wiki.rb` within one second.
34
+
35
+ ```
36
+ $ bundle exec typeprof lib/rbswiki/wiki.rb
37
+ warning: rbs collection is experimental, and the behavior may change until RBS v2.0
38
+ # TypeProf 0.20.0
39
+
40
+ # Classes
41
+ module RBSWiki
42
+ class Wiki
43
+ @content: Hash[String, String]
44
+ ...
45
+ ```
46
+
47
+ * See the log of "Ruby TypeProf" in vscode's "OUTPUT" panel.
48
+
49
+ ![Log of TypeProf for IDE](typeprof-for-ide-log.png)
50
+
51
+ ## How to configure TypeProf for your code
52
+
53
+ 1. Write `gem "typeprof"` to your `Gemfile`, and run `bundle install`
54
+ 2. Write `rbs_collection.yaml`, and run `rbs collection install`
55
+ 3. Test if TypeProf works well by running `bundle exec typeprof your_code.rb`
56
+ 4. Open your repository with vscode
57
+
58
+ ### Troubleshooting
59
+
60
+ *TBD*
61
+
62
+ ## Protips, limitation, unimplemented features, ...
63
+
64
+ TypeProf for IDE is extremely preliminary! Please give it a try with a warm heart...
65
+
66
+ * Write a simple (type-level) test in each file with `if $0 == __FILE__` guard to guide TypeProf to infer method signatures.
67
+ * Use `require` only for loading gems. To load your code, use `require_relative` instead of `require`. (Or, create `bin/typeprof` and pass `-Ilib`. TBD for details)
68
+ * Currently, TypeProf for IDE loads `typeprof.rbs` at the top folder. (I'll need to improve it to read `sig/` directory)
69
+ * TypeProf for IDE analyzes each file within one second. Unfortunately, it takes very long to analyze big code, or complex code, or code that requires a big gem. In this case, TypeProf for IDE cannot show any guesses. Splitting a file or manually writing RBS may make the analysis faster. (TBD for details)
70
+ * Unfortunately, TypeProf may report some false positive errors that you cannot stop. I'll create an option to configure error level.
71
+ * TypeProf for IDE tries to invoke TypeProf as follows:
72
+ * If your repository has `bin/typeprof` executable, it is invoked.
73
+ * Otherwise, it will try to invoke a command specified in VS`typeprof.server.path`.
74
+ * Otherwise, it will try to invoke `bundle exec typeprof`.
75
+ * Otherwise, it will try to invoke `typeprof`.
76
+ * Otherwise, TypeProf for IDE gives up.
77
+ * Some people says TypeProf for IDE works with vim! (TBD for details)
78
+
79
+ ## How to develop TypeProf for IDE
80
+
81
+ See `../vscode/development.md`.
Binary file
Binary file
@@ -1933,8 +1933,13 @@ module TypeProf
1933
1933
  when :setconstant
1934
1934
  name, = operands
1935
1935
  env, (ty, cbase) = env.pop(2)
1936
- old_ty, = get_constant(cbase, name)
1937
- if old_ty != Type.any # XXX???
1936
+ old_ty, old_locs = get_constant(cbase, name)
1937
+ if old_locs == [nil] # RBS defined
1938
+ # TODO: it would be better to check if ty is consistent with old_ty (defined in RBS)
1939
+ # instead of extending the type
1940
+ env, old_ty = localize_type(globalize_type(old_ty, env, ep), env, ep)
1941
+ ty = ty.union(old_ty)
1942
+ elsif old_ty != Type.any # XXX???
1938
1943
  warn(ep, "already initialized constant #{ Type::Instance.new(cbase).screen_name(self) }::#{ name }")
1939
1944
  end
1940
1945
  ty.each_child do |ty|
data/lib/typeprof/cli.rb CHANGED
@@ -21,7 +21,6 @@ module TypeProf
21
21
  lsp_options = {}
22
22
  dir_filter = nil
23
23
  gem_rbs_features = []
24
- gem_repo_dirs = []
25
24
  show_version = false
26
25
  max_sec = max_iter = nil
27
26
  collection_path = RBS::Collection::Config::PATH
@@ -36,7 +35,6 @@ module TypeProf
36
35
  opt.on("--version", "Display typeprof version") { show_version = true }
37
36
  opt.on("-I DIR", "Add DIR to the load/require path") {|v| load_path_ext << v }
38
37
  opt.on("-r FEATURE", "Require RBS of the FEATURE gem") {|v| gem_rbs_features << v }
39
- opt.on("--repo DIR", "Add DIR to the RBS repository") {|v| gem_repo_dirs << v }
40
38
  opt.on("--collection PATH", "File path of collection configuration") { |v| collection_path = v }
41
39
  opt.on("--no-collection", "Ignore collection configuration") { collection_path = nil }
42
40
  opt.on("--lsp", "LSP mode") {|v| options[:lsp] = true }
@@ -78,6 +76,7 @@ module TypeProf
78
76
  opt.separator ""
79
77
  opt.separator "LSP options:"
80
78
  opt.on("--port PORT", Integer, "Specify a port number to listen for requests on") {|v| lsp_options[:port] = v }
79
+ opt.on("--stdio", "Use stdio for LSP transport") {|v| lsp_options[:stdio] = v }
81
80
 
82
81
  opt.parse!(argv)
83
82
 
@@ -110,7 +109,6 @@ module TypeProf
110
109
  rbs_files: rbs_files,
111
110
  output: output,
112
111
  gem_rbs_features: gem_rbs_features,
113
- gem_repo_dirs: gem_repo_dirs,
114
112
  collection_path: collection_path,
115
113
  verbose: verbose,
116
114
  dir_filter: dir_filter,
@@ -6,7 +6,6 @@ module TypeProf
6
6
  :rbs_files,
7
7
  :output,
8
8
  :gem_rbs_features,
9
- :gem_repo_dirs,
10
9
  :collection_path,
11
10
  :verbose,
12
11
  :dir_filter,
@@ -29,7 +28,6 @@ module TypeProf
29
28
  def initialize(**opt)
30
29
  opt[:output] ||= $stdout
31
30
  opt[:gem_rbs_features] ||= []
32
- opt[:gem_repo_dirs] ||= []
33
31
  opt[:dir_filter] ||= DEFAULT_DIR_FILTER
34
32
  opt[:verbose] ||= 0
35
33
  opt[:options] ||= {}
@@ -48,6 +46,7 @@ module TypeProf
48
46
  }.merge(opt[:options])
49
47
  opt[:lsp_options] = {
50
48
  port: 0,
49
+ stdio: false,
51
50
  }.merge(opt[:lsp_options] || {})
52
51
  super(**opt)
53
52
  end
@@ -94,9 +93,6 @@ module TypeProf
94
93
  Import.import_library(scratch, feature)
95
94
  end
96
95
 
97
- collection_path = config.collection_path
98
- Import.import_rbs_collection(scratch, collection_path) if collection_path&.exist?
99
-
100
96
  rbs_files = []
101
97
  rbs_codes = []
102
98
  Config.current.rbs_files.each do |rbs|
@@ -4,36 +4,49 @@ module TypeProf
4
4
  class RBSReader
5
5
  def initialize
6
6
  @repo = RBS::Repository.new
7
- Config.current.gem_repo_dirs.each do |dir|
8
- @repo.add(Pathname(dir))
9
- end
10
7
  collection_path = Config.current.collection_path
11
8
  if collection_path&.exist?
12
9
  collection_lock = RBS::Collection::Config.lockfile_of(collection_path)
13
10
  @repo.add(collection_lock.repo_path)
14
11
  end
15
- @env, @builtin_env_json = RBSReader.get_builtin_env
12
+ @env, @loaded_gems, @builtin_env_json = RBSReader.get_builtin_env
16
13
  end
17
14
 
18
15
  @builtin_env = @builtin_env_json = nil
19
16
  def self.get_builtin_env
17
+ @loaded_gems = []
20
18
  unless @builtin_env
21
19
  @builtin_env = RBS::Environment.new
22
20
 
23
- loader = RBS::EnvironmentLoader.new(repository: @repo)
21
+ loader = RBS::EnvironmentLoader.new
22
+
23
+ # TODO: invalidate this cache when rbs_collection.yml was changed
24
+ collection_path = Config.current.collection_path
25
+ if collection_path&.exist?
26
+ collection_lock = RBS::Collection::Config.lockfile_of(collection_path)
27
+ collection_lock.gems.each {|gem| @loaded_gems << gem["name"] }
28
+ loader.add_collection(collection_lock)
29
+ end
30
+
24
31
  new_decls = loader.load(env: @builtin_env).map {|decl,| decl }
25
32
  @builtin_env_json = load_rbs(@builtin_env, new_decls)
26
33
  end
27
34
 
28
- return @builtin_env.dup, @builtin_env_json
35
+ return @builtin_env.dup, @loaded_gems.dup, @builtin_env_json
29
36
  end
30
37
 
31
38
  def load_builtin
32
39
  @builtin_env_json
33
40
  end
34
41
 
42
+ class RBSCollectionDefined < StandardError; end
43
+
35
44
  def load_library(lib)
36
45
  loader = RBS::EnvironmentLoader.new(core_root: nil, repository: @repo)
46
+ if @loaded_gems.include?(lib)
47
+ raise RBSCollectionDefined
48
+ end
49
+ @loaded_gems << lib
37
50
  loader.add(library: lib)
38
51
 
39
52
  case lib
@@ -71,14 +84,6 @@ module TypeProf
71
84
  RBSReader.load_rbs(@env, new_decls)
72
85
  end
73
86
 
74
- def load_rbs_collection(collection_path)
75
- loader = RBS::EnvironmentLoader.new(core_root: nil)
76
- collection_lock = RBS::Collection::Config.lockfile_of(collection_path)
77
- loader.add_collection(collection_lock)
78
- new_decls = loader.load(env: @env).map {|decl,| decl }
79
- RBSReader.load_rbs(@env, new_decls)
80
- end
81
-
82
87
  def self.load_rbs(env, new_decls)
83
88
  all_env = env.resolve_type_names
84
89
  resolver = RBS::TypeNameResolver.from_env(all_env)
@@ -483,6 +488,7 @@ module TypeProf
483
488
  when RBS::Types::Interface
484
489
  # XXX: Currently, only a few builtin interfaces are supported
485
490
  case ty.to_s
491
+ when "::_ToS" then [:str]
486
492
  when "::_ToStr" then [:str]
487
493
  when "::_ToInt" then [:int]
488
494
  when "::_ToAry[U]" then [:array, [:Array], [], [:var, :U]]
@@ -490,6 +496,7 @@ module TypeProf
490
496
  [:instance, conv_type_name(ty.name)]
491
497
  end
492
498
  when RBS::Types::Bases::Instance then [:any] # XXX: not implemented yet
499
+ when RBS::Types::Bases::Class then [:any] # XXX: not implemented yet
493
500
  when RBS::Types::Record
494
501
  [:hash_record, [:Hash], ty.fields.map {|key, ty| [key, conv_type(ty)] }]
495
502
  when RBS::Types::Proc
@@ -515,7 +522,7 @@ module TypeProf
515
522
  json = scratch.rbs_reader.load_library(feature)
516
523
  rescue RBS::EnvironmentLoader::UnknownLibraryError
517
524
  return nil
518
- rescue RBS::DuplicatedDeclarationError
525
+ rescue RBS::DuplicatedDeclarationError, RBSReader::RBSCollectionDefined
519
526
  return true
520
527
  end
521
528
  # need cache?
@@ -531,10 +538,6 @@ module TypeProf
531
538
  Import.new(scratch, scratch.rbs_reader.load_rbs_string(rbs_name, rbs_code)).import(true)
532
539
  end
533
540
 
534
- def self.import_rbs_collection(scratch, collection_path)
535
- Import.new(scratch, scratch.rbs_reader.load_rbs_collection(collection_path)).import(true)
536
- end
537
-
538
541
  def initialize(scratch, json)
539
542
  @scratch = scratch
540
543
  @json = json
data/lib/typeprof/iseq.rb CHANGED
@@ -34,6 +34,11 @@ module TypeProf
34
34
  parse_opts = {}
35
35
  parse_opts[:keep_script_lines] = true if RICH_AST
36
36
 
37
+ unless defined?(RubyVM::InstructionSequence)
38
+ puts "Currently, TypeProf can work on a Ruby implementation that supports RubyVM::InstructionSequence, such as CRuby."
39
+ exit 1
40
+ end
41
+
37
42
  if str
38
43
  node = RubyVM::AbstractSyntaxTree.parse(str, **parse_opts)
39
44
  iseq = RubyVM::InstructionSequence.compile(str, path, **opt)
data/lib/typeprof/lsp.rb CHANGED
@@ -4,27 +4,35 @@ require "uri"
4
4
 
5
5
  module TypeProf
6
6
  def self.start_lsp_server(config)
7
- Socket.tcp_server_sockets("localhost", config.lsp_options[:port]) do |servs|
8
- serv = servs[0].local_address
9
- $stdout << JSON.generate({
10
- host: serv.ip_address,
11
- port: serv.ip_port,
12
- pid: $$,
13
- })
14
- $stdout.flush
15
-
7
+ if config.lsp_options[:stdio]
8
+ reader = LSP::Reader.new($stdin)
9
+ writer = LSP::Writer.new($stdout)
10
+ # pipe all builtin print output to stderr to avoid conflicting with lsp
16
11
  $stdout = $stderr
17
-
18
- Socket.accept_loop(servs) do |sock|
19
- sock.set_encoding("UTF-8")
20
- begin
21
- reader = LSP::Reader.new(sock)
22
- writer = LSP::Writer.new(sock)
23
- TypeProf::LSP::Server.new(config, reader, writer).run
24
- ensure
25
- sock.close
12
+ TypeProf::LSP::Server.new(config, reader, writer).run
13
+ else
14
+ Socket.tcp_server_sockets("localhost", config.lsp_options[:port]) do |servs|
15
+ serv = servs[0].local_address
16
+ $stdout << JSON.generate({
17
+ host: serv.ip_address,
18
+ port: serv.ip_port,
19
+ pid: $$,
20
+ })
21
+ $stdout.flush
22
+
23
+ $stdout = $stderr
24
+
25
+ Socket.accept_loop(servs) do |sock|
26
+ sock.set_encoding("UTF-8")
27
+ begin
28
+ reader = LSP::Reader.new(sock)
29
+ writer = LSP::Writer.new(sock)
30
+ TypeProf::LSP::Server.new(config, reader, writer).run
31
+ ensure
32
+ sock.close
33
+ end
34
+ exit
26
35
  end
27
- exit
28
36
  end
29
37
  end
30
38
  end
@@ -330,8 +338,8 @@ module TypeProf
330
338
  end
331
339
 
332
340
  diagnostics = {}
333
- res[:errors].each do |(file, code_range), msg|
334
- next unless file
341
+ res[:errors]&.each do |(file, code_range), msg|
342
+ next unless file and code_range
335
343
  uri0 = "file://" + file
336
344
  diagnostics[uri0] ||= []
337
345
  diagnostics[uri0] << {
@@ -675,6 +683,11 @@ module TypeProf
675
683
  triggerKind: trigger_kind
676
684
  },
677
685
  }
686
+ in {
687
+ textDocument: { uri:, },
688
+ position: loc,
689
+ }
690
+ trigger_kind = 1
678
691
  else
679
692
  raise
680
693
  end
@@ -705,6 +718,11 @@ module TypeProf
705
718
  triggerKind: trigger_kind
706
719
  },
707
720
  }
721
+ in {
722
+ textDocument: { uri:, },
723
+ position: loc,
724
+ }
725
+ trigger_kind = 1
708
726
  else
709
727
  raise
710
728
  end
@@ -783,6 +801,7 @@ module TypeProf
783
801
  def write(**json)
784
802
  json = JSON.generate(json.merge(jsonrpc: "2.0"))
785
803
  @io << "Content-Length: #{ json.bytesize }\r\n\r\n" << json
804
+ @io.flush
786
805
  end
787
806
 
788
807
  module ErrorCodes
@@ -1,3 +1,3 @@
1
1
  module TypeProf
2
- VERSION = "0.20.0"
2
+ VERSION = "0.20.1"
3
3
  end
data/lib/typeprof.rb CHANGED
@@ -1,8 +1,3 @@
1
- unless defined?(RubyVM::InstructionSequence)
2
- puts "Currently, TypeProf can work on a Ruby implementation that supports RubyVM::InstructionSequence, such as CRuby."
3
- exit 1
4
- end
5
-
6
1
  module TypeProf end
7
2
 
8
3
  require_relative "typeprof/version"
data/typeprof.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  # Specify which files should be added to the gem when it is released.
25
25
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
26
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
27
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|smoke|testbed)/}) }
28
28
  end
29
29
  spec.bindir = "exe"
30
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }