typeprof 0.20.0 → 0.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/doc/ide.md +81 -0
- data/doc/typeprof-for-ide-log.png +0 -0
- data/doc/typeprof-for-ide.png +0 -0
- data/lib/typeprof/analyzer.rb +7 -2
- data/lib/typeprof/cli.rb +1 -3
- data/lib/typeprof/config.rb +1 -5
- data/lib/typeprof/import.rb +22 -19
- data/lib/typeprof/iseq.rb +5 -0
- data/lib/typeprof/lsp.rb +40 -21
- data/lib/typeprof/version.rb +1 -1
- data/lib/typeprof.rb +0 -5
- data/typeprof.gemspec +1 -1
- metadata +5 -331
- data/smoke/alias.rb +0 -31
- data/smoke/alias2.rb +0 -21
- data/smoke/any-cbase.rb +0 -5
- data/smoke/any1.rb +0 -16
- data/smoke/any2.rb +0 -18
- data/smoke/arguments.rb +0 -17
- data/smoke/arguments2.rb +0 -56
- data/smoke/array-each.rb +0 -15
- data/smoke/array-each2.rb +0 -16
- data/smoke/array-each3.rb +0 -13
- data/smoke/array-ltlt.rb +0 -14
- data/smoke/array-ltlt2.rb +0 -17
- data/smoke/array-map.rb +0 -12
- data/smoke/array-map2.rb +0 -11
- data/smoke/array-map3.rb +0 -23
- data/smoke/array-mul.rb +0 -18
- data/smoke/array-plus1.rb +0 -11
- data/smoke/array-plus2.rb +0 -16
- data/smoke/array-pop.rb +0 -12
- data/smoke/array-range-aref.rb +0 -71
- data/smoke/array-replace.rb +0 -13
- data/smoke/array-s-aref.rb +0 -12
- data/smoke/array1.rb +0 -27
- data/smoke/array10.rb +0 -15
- data/smoke/array11.rb +0 -14
- data/smoke/array12.rb +0 -25
- data/smoke/array13.rb +0 -31
- data/smoke/array14.rb +0 -14
- data/smoke/array15.rb +0 -16
- data/smoke/array2.rb +0 -28
- data/smoke/array3.rb +0 -26
- data/smoke/array4.rb +0 -15
- data/smoke/array5.rb +0 -14
- data/smoke/array6.rb +0 -17
- data/smoke/array7.rb +0 -14
- data/smoke/array8.rb +0 -13
- data/smoke/array9.rb +0 -13
- data/smoke/attr-module.rb +0 -24
- data/smoke/attr-vis.rb +0 -43
- data/smoke/attr-vis.rbs +0 -4
- data/smoke/attr.rb +0 -28
- data/smoke/autoload.rb +0 -14
- data/smoke/backtrace.rb +0 -33
- data/smoke/block-ambiguous.rb +0 -37
- data/smoke/block-args1-rest.rb +0 -64
- data/smoke/block-args1.rb +0 -60
- data/smoke/block-args2-rest.rb +0 -64
- data/smoke/block-args2.rb +0 -60
- data/smoke/block-args3-rest.rb +0 -75
- data/smoke/block-args3.rb +0 -71
- data/smoke/block-blockarg.rb +0 -28
- data/smoke/block-kwarg.rb +0 -53
- data/smoke/block1.rb +0 -23
- data/smoke/block10.rb +0 -15
- data/smoke/block11.rb +0 -40
- data/smoke/block12.rb +0 -23
- data/smoke/block13.rb +0 -9
- data/smoke/block13.rbs +0 -3
- data/smoke/block14.rb +0 -18
- data/smoke/block2.rb +0 -15
- data/smoke/block3.rb +0 -38
- data/smoke/block4.rb +0 -19
- data/smoke/block5.rb +0 -21
- data/smoke/block6.rb +0 -21
- data/smoke/block7.rb +0 -19
- data/smoke/block8.rb +0 -28
- data/smoke/block9.rb +0 -13
- data/smoke/block_given.rb +0 -37
- data/smoke/blown.rb +0 -13
- data/smoke/break1.rb +0 -19
- data/smoke/break2.rb +0 -16
- data/smoke/break3.rb +0 -13
- data/smoke/break4.rb +0 -17
- data/smoke/case.rb +0 -17
- data/smoke/case2.rb +0 -18
- data/smoke/case3.rb +0 -17
- data/smoke/class-hierarchy.rb +0 -54
- data/smoke/class-hierarchy2.rb +0 -27
- data/smoke/class-new.rb +0 -15
- data/smoke/class.rb +0 -7
- data/smoke/class_eval.rb +0 -22
- data/smoke/class_instance_var.rb +0 -9
- data/smoke/class_method.rb +0 -25
- data/smoke/class_method2.rb +0 -21
- data/smoke/class_method3.rb +0 -29
- data/smoke/constant1.rb +0 -46
- data/smoke/constant2.rb +0 -36
- data/smoke/constant3.rb +0 -10
- data/smoke/constant4.rb +0 -12
- data/smoke/context-sensitive1.rb +0 -13
- data/smoke/cvar.rb +0 -31
- data/smoke/cvar2.rb +0 -17
- data/smoke/define_method.rb +0 -16
- data/smoke/define_method2.rb +0 -18
- data/smoke/define_method3.rb +0 -14
- data/smoke/define_method3.rbs +0 -3
- data/smoke/define_method4.rb +0 -15
- data/smoke/define_method4.rbs +0 -3
- data/smoke/define_method5.rb +0 -12
- data/smoke/define_method6.rb +0 -19
- data/smoke/define_method7.rb +0 -18
- data/smoke/demo.rb +0 -81
- data/smoke/demo1.rb +0 -17
- data/smoke/demo10.rb +0 -21
- data/smoke/demo11.rb +0 -12
- data/smoke/demo2.rb +0 -15
- data/smoke/demo3.rb +0 -17
- data/smoke/demo4.rb +0 -27
- data/smoke/demo5.rb +0 -16
- data/smoke/demo6.rb +0 -22
- data/smoke/demo7.rb +0 -15
- data/smoke/demo8.rb +0 -19
- data/smoke/demo9.rb +0 -18
- data/smoke/dummy-execution1.rb +0 -15
- data/smoke/dummy-execution2.rb +0 -16
- data/smoke/dummy_element.rb +0 -14
- data/smoke/ensure1.rb +0 -21
- data/smoke/enum_for.rb +0 -15
- data/smoke/enum_for2.rb +0 -17
- data/smoke/enumerator.rb +0 -16
- data/smoke/expandarray1.rb +0 -23
- data/smoke/expandarray2.rb +0 -24
- data/smoke/extended.rb +0 -38
- data/smoke/fib.rb +0 -28
- data/smoke/flip-flop.rb +0 -28
- data/smoke/flow1.rb +0 -17
- data/smoke/flow10.rb +0 -17
- data/smoke/flow11.rb +0 -17
- data/smoke/flow2.rb +0 -15
- data/smoke/flow3.rb +0 -15
- data/smoke/flow4.rb +0 -5
- data/smoke/flow5.rb +0 -20
- data/smoke/flow6.rb +0 -20
- data/smoke/flow7.rb +0 -21
- data/smoke/flow8.rb +0 -14
- data/smoke/flow9.rb +0 -12
- data/smoke/for.rb +0 -9
- data/smoke/freeze.rb +0 -12
- data/smoke/function.rb +0 -17
- data/smoke/gvar.rb +0 -14
- data/smoke/gvar2.rb +0 -15
- data/smoke/gvar2.rbs +0 -1
- data/smoke/hash-bot.rb +0 -12
- data/smoke/hash-fetch.rb +0 -28
- data/smoke/hash-merge-bang.rb +0 -12
- data/smoke/hash1.rb +0 -20
- data/smoke/hash2.rb +0 -13
- data/smoke/hash3.rb +0 -14
- data/smoke/hash4.rb +0 -11
- data/smoke/hash5.rb +0 -14
- data/smoke/huge_union.rb +0 -86
- data/smoke/identifier_keywords.rb +0 -17
- data/smoke/included.rb +0 -38
- data/smoke/inheritance.rb +0 -34
- data/smoke/inheritance2.rb +0 -35
- data/smoke/inherited.rb +0 -26
- data/smoke/initialize.rb +0 -28
- data/smoke/instance_eval.rb +0 -18
- data/smoke/instance_eval2.rb +0 -10
- data/smoke/instance_eval3.rb +0 -25
- data/smoke/instance_eval4.rb +0 -12
- data/smoke/int_times.rb +0 -15
- data/smoke/integer.rb +0 -11
- data/smoke/ivar.rb +0 -31
- data/smoke/ivar2.rb +0 -30
- data/smoke/ivar3.rb +0 -17
- data/smoke/ivar3.rbs +0 -3
- data/smoke/ivar4.rb +0 -21
- data/smoke/kernel-class.rb +0 -13
- data/smoke/keyword1.rb +0 -12
- data/smoke/keyword2.rb +0 -12
- data/smoke/keyword3.rb +0 -12
- data/smoke/keyword4.rb +0 -12
- data/smoke/keyword5.rb +0 -16
- data/smoke/kwrest.rb +0 -13
- data/smoke/kwrest.rbs +0 -3
- data/smoke/kwsplat1.rb +0 -43
- data/smoke/kwsplat2.rb +0 -13
- data/smoke/lit-complex.rb +0 -10
- data/smoke/lit-encoding.rb +0 -10
- data/smoke/manual-rbs.rb +0 -29
- data/smoke/manual-rbs.rbs +0 -3
- data/smoke/manual-rbs2.rb +0 -21
- data/smoke/manual-rbs2.rbs +0 -8
- data/smoke/manual-rbs3.rb +0 -13
- data/smoke/manual-rbs3.rbs +0 -3
- data/smoke/masgn1.rb +0 -14
- data/smoke/masgn2.rb +0 -18
- data/smoke/masgn3.rb +0 -13
- data/smoke/method_in_branch.rb +0 -23
- data/smoke/method_missing.rb +0 -29
- data/smoke/module1.rb +0 -29
- data/smoke/module2.rb +0 -28
- data/smoke/module3.rb +0 -33
- data/smoke/module4.rb +0 -35
- data/smoke/module5.rb +0 -17
- data/smoke/module6.rb +0 -40
- data/smoke/module_function1.rb +0 -29
- data/smoke/module_function2.rb +0 -29
- data/smoke/multiple-include.rb +0 -15
- data/smoke/multiple-superclass.rb +0 -28
- data/smoke/next1.rb +0 -21
- data/smoke/next2.rb +0 -17
- data/smoke/noname.rb +0 -9
- data/smoke/object-send1.rb +0 -23
- data/smoke/object-send2.rb +0 -10
- data/smoke/object-send3.rb +0 -18
- data/smoke/once.rb +0 -13
- data/smoke/optional1.rb +0 -14
- data/smoke/optional2.rb +0 -16
- data/smoke/optional3.rb +0 -11
- data/smoke/or_raise.rb +0 -18
- data/smoke/parameterizedd-self.rb +0 -20
- data/smoke/parameterizedd-self2.rb +0 -15
- data/smoke/pathname1.rb +0 -14
- data/smoke/pathname2.rb +0 -14
- data/smoke/pattern-match1.rb +0 -19
- data/smoke/pattern-match2.rb +0 -16
- data/smoke/prepend1.rb +0 -33
- data/smoke/prepend2.rb +0 -10
- data/smoke/prepend2.rbs +0 -9
- data/smoke/primitive_method.rb +0 -19
- data/smoke/printf.rb +0 -20
- data/smoke/proc.rb +0 -20
- data/smoke/proc2.rb +0 -17
- data/smoke/proc3.rb +0 -15
- data/smoke/proc4.rb +0 -12
- data/smoke/proc5.rb +0 -19
- data/smoke/proc6.rb +0 -13
- data/smoke/proc7.rb +0 -32
- data/smoke/public.rb +0 -38
- data/smoke/range.rb +0 -14
- data/smoke/rbs-alias.rb +0 -10
- data/smoke/rbs-alias.rbs +0 -4
- data/smoke/rbs-attr.rb +0 -27
- data/smoke/rbs-attr.rbs +0 -5
- data/smoke/rbs-attr2.rb +0 -11
- data/smoke/rbs-attr2.rbs +0 -3
- data/smoke/rbs-extend.rb +0 -10
- data/smoke/rbs-extend.rbs +0 -7
- data/smoke/rbs-interface.rb +0 -25
- data/smoke/rbs-interface.rbs +0 -12
- data/smoke/rbs-module.rb +0 -26
- data/smoke/rbs-module.rbs +0 -4
- data/smoke/rbs-opt-and-rest.rb +0 -10
- data/smoke/rbs-opt-and-rest.rbs +0 -3
- data/smoke/rbs-proc1.rb +0 -10
- data/smoke/rbs-proc1.rbs +0 -3
- data/smoke/rbs-proc2.rb +0 -21
- data/smoke/rbs-proc2.rbs +0 -3
- data/smoke/rbs-proc3.rb +0 -14
- data/smoke/rbs-proc3.rbs +0 -4
- data/smoke/rbs-record.rb +0 -18
- data/smoke/rbs-record.rbs +0 -4
- data/smoke/rbs-tyvar.rb +0 -19
- data/smoke/rbs-tyvar.rbs +0 -5
- data/smoke/rbs-tyvar2.rb +0 -21
- data/smoke/rbs-tyvar2.rbs +0 -9
- data/smoke/rbs-tyvar3.rb +0 -18
- data/smoke/rbs-tyvar3.rbs +0 -5
- data/smoke/rbs-tyvar4.rb +0 -37
- data/smoke/rbs-tyvar5.rb +0 -13
- data/smoke/rbs-tyvar5.rbs +0 -8
- data/smoke/rbs-tyvar6.rb +0 -18
- data/smoke/rbs-tyvar6.rbs +0 -12
- data/smoke/rbs-tyvar7.rb +0 -12
- data/smoke/rbs-tyvar7.rbs +0 -7
- data/smoke/rbs-vars.rb +0 -35
- data/smoke/rbs-vars.rbs +0 -7
- data/smoke/redo1.rb +0 -22
- data/smoke/redo2.rb +0 -23
- data/smoke/req-keyword.rb +0 -13
- data/smoke/require1.rb +0 -13
- data/smoke/require2.rb +0 -13
- data/smoke/rescue1.rb +0 -21
- data/smoke/rescue2.rb +0 -23
- data/smoke/rescue3.rb +0 -20
- data/smoke/rescue4.rb +0 -17
- data/smoke/respond_to.rb +0 -23
- data/smoke/rest-farg.rb +0 -11
- data/smoke/rest1.rb +0 -26
- data/smoke/rest2.rb +0 -31
- data/smoke/rest3.rb +0 -37
- data/smoke/rest4.rb +0 -19
- data/smoke/rest5.rb +0 -11
- data/smoke/rest6.rb +0 -12
- data/smoke/retry1.rb +0 -21
- data/smoke/return.rb +0 -14
- data/smoke/reveal.rb +0 -13
- data/smoke/simple.rb +0 -12
- data/smoke/singleton_class.rb +0 -8
- data/smoke/singleton_method.rb +0 -12
- data/smoke/step.rb +0 -18
- data/smoke/string-split.rb +0 -12
- data/smoke/struct-keyword_init.rb +0 -10
- data/smoke/struct.rb +0 -13
- data/smoke/struct2.rb +0 -25
- data/smoke/struct3.rb +0 -14
- data/smoke/struct4.rb +0 -7
- data/smoke/struct5.rb +0 -16
- data/smoke/struct6.rb +0 -15
- data/smoke/struct7.rb +0 -17
- data/smoke/stub-keyword.rb +0 -10
- data/smoke/super1.rb +0 -69
- data/smoke/super2.rb +0 -16
- data/smoke/super3.rb +0 -20
- data/smoke/super4.rb +0 -45
- data/smoke/super5.rb +0 -38
- data/smoke/svar1.rb +0 -13
- data/smoke/symbol-proc-attr.rb +0 -22
- data/smoke/symbol-proc-attr2.rb +0 -15
- data/smoke/symbol-proc-bot.rb +0 -13
- data/smoke/symbol-proc.rb +0 -25
- data/smoke/tap1.rb +0 -18
- data/smoke/toplevel.rb +0 -13
- data/smoke/two-map.rb +0 -18
- data/smoke/type_var.rb +0 -11
- data/smoke/typed_method.rb +0 -16
- data/smoke/uninitialize-var.rb +0 -13
- data/smoke/union-recv.rb +0 -35
- data/smoke/user-demo.rb +0 -15
- data/smoke/wrong-extend.rb +0 -27
- data/smoke/wrong-include.rb +0 -27
- data/smoke/wrong-include2.rb +0 -17
- data/smoke/wrong-rbs.rb +0 -15
- data/smoke/wrong-rbs.rbs +0 -7
- data/testbed/ao.rb +0 -297
- data/testbed/diff-lcs-entrypoint.rb +0 -4
- data/testbed/goodcheck-Gemfile.lock +0 -51
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b3938be1edd2b64861739d4ea2f801972c32fc67b4b791837e2b238d9be3a5bb
|
|
4
|
+
data.tar.gz: 8ba23caae4ab25ea713a1b4fca1850cbc44954aaecabcfd9a3e7a3db18c6ea4b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e946bed7229effa1d0d95fd665875b39344d8aa959e6fa126631b914e8f9ead55a2a5cababd2ea390f1275b04d1e73bec2b4969c3ccc549acfdeb09512ed8626
|
|
7
|
+
data.tar.gz: e31d656a00087bb096c91e2c3da129e7d81ee480e99d67685b1c458a5cbf1a2e97c3ea0feef1657b1a895fc44bd2011ba3fd6ef8b387833967e99c1c728b6e4b
|
data/Gemfile.lock
CHANGED
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
|
+

|
|
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
|
+

|
|
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
|
data/lib/typeprof/analyzer.rb
CHANGED
|
@@ -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
|
|
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,
|
data/lib/typeprof/config.rb
CHANGED
|
@@ -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|
|
data/lib/typeprof/import.rb
CHANGED
|
@@ -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
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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]
|
|
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
|
data/lib/typeprof/version.rb
CHANGED
data/lib/typeprof.rb
CHANGED
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) }
|