typeprof 0.30.0 → 0.30.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/doc.ja.md +1 -1
- data/lib/typeprof/cli/cli.rb +1 -3
- data/lib/typeprof/cli.rb +1 -0
- data/lib/typeprof/core/ast/call.rb +9 -1
- data/lib/typeprof/core/ast/control.rb +6 -5
- data/lib/typeprof/core/ast/method.rb +4 -0
- data/lib/typeprof/core/ast/value.rb +1 -1
- data/lib/typeprof/core/env.rb +7 -1
- data/lib/typeprof/core/graph/box.rb +11 -4
- data/lib/typeprof/core/graph/vertex.rb +3 -0
- data/lib/typeprof/core/service.rb +32 -40
- data/lib/typeprof/core/type.rb +4 -0
- data/lib/typeprof/core.rb +0 -1
- data/lib/typeprof/lsp/messages.rb +13 -28
- data/lib/typeprof/lsp/server.rb +27 -1
- data/lib/typeprof/lsp/util.rb +0 -10
- data/lib/typeprof/version.rb +1 -1
- metadata +6 -5
- data/lib/typeprof/core/graph.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f42086b6df655b0df5ea0e11633500c15735fc81713833c477536138de6cd70
|
4
|
+
data.tar.gz: 8e2c1bbd37db3e87fea65136cdbb78c31853ed0db434aeee76e9066cb15c125a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89feb1071cf88fb006b7c04312d2ef576e940023e096b0fed10178b1b89f70301cf50f8d53343983e33760f258d96e2c9244de44bec55e1437bf0857951d4b91
|
7
|
+
data.tar.gz: 4f63149902b7b926df8159a1d2dc18a7472d15e07df9a441483b1e401a313c9b0ddf201ffdaa8eaccda4115bf3ae88d1ec282e8c66a11230b342275842809ba4
|
data/doc/doc.ja.md
CHANGED
data/lib/typeprof/cli/cli.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require "io/console"
|
2
|
-
|
3
1
|
module TypeProf::CLI
|
4
2
|
class CLI
|
5
3
|
def initialize(argv)
|
@@ -49,7 +47,7 @@ module TypeProf::CLI
|
|
49
47
|
|
50
48
|
opt.parse!(argv)
|
51
49
|
|
52
|
-
if cli_options[:lsp] && !lsp_options.empty?
|
50
|
+
if !cli_options[:lsp] && !lsp_options.empty?
|
53
51
|
raise OptionParser::InvalidOption.new("lsp options with non-lsp mode")
|
54
52
|
end
|
55
53
|
|
data/lib/typeprof/cli.rb
CHANGED
@@ -124,7 +124,15 @@ module TypeProf::Core
|
|
124
124
|
|
125
125
|
a_args = ActualArguments.new(positional_args, @splat_flags, keyword_args, blk_ty)
|
126
126
|
box = @changes.add_method_call_box(genv, recv, @mid, a_args, !@recv)
|
127
|
-
|
127
|
+
|
128
|
+
if @block_body && @block_body.lenv.break_vtx
|
129
|
+
ret = Vertex.new(self)
|
130
|
+
@changes.add_edge(genv, box.ret, ret)
|
131
|
+
@changes.add_edge(genv, @block_body.lenv.break_vtx, ret)
|
132
|
+
ret
|
133
|
+
else
|
134
|
+
box.ret
|
135
|
+
end
|
128
136
|
end
|
129
137
|
|
130
138
|
def block_last_stmt_code_range
|
@@ -176,7 +176,7 @@ module TypeProf::Core
|
|
176
176
|
class BreakNode < Node
|
177
177
|
def initialize(raw_node, lenv)
|
178
178
|
super(raw_node, lenv)
|
179
|
-
@arg =
|
179
|
+
@arg = AST.parse_return_arguments(raw_node, lenv, code_range)
|
180
180
|
end
|
181
181
|
|
182
182
|
attr_reader :arg
|
@@ -184,8 +184,9 @@ module TypeProf::Core
|
|
184
184
|
def subnodes = { arg: }
|
185
185
|
|
186
186
|
def install0(genv)
|
187
|
-
|
188
|
-
|
187
|
+
arg = @arg.install(genv)
|
188
|
+
@changes.add_edge(genv, arg, @lenv.get_break_vtx)
|
189
|
+
Source.new()
|
189
190
|
end
|
190
191
|
end
|
191
192
|
|
@@ -365,8 +366,8 @@ module TypeProf::Core
|
|
365
366
|
end
|
366
367
|
raw_res = raw_res.subsequent
|
367
368
|
end
|
368
|
-
@else_clause = raw_node.else_clause ? AST.create_node(raw_node.else_clause.statements, lenv) : DummyNilNode.new(code_range, lenv)
|
369
|
-
@ensure_clause = raw_node.ensure_clause ? AST.create_node(raw_node.ensure_clause.statements, lenv) : DummyNilNode.new(code_range, lenv)
|
369
|
+
@else_clause = raw_node.else_clause&.statements ? AST.create_node(raw_node.else_clause.statements, lenv) : DummyNilNode.new(code_range, lenv)
|
370
|
+
@ensure_clause = raw_node.ensure_clause&.statements ? AST.create_node(raw_node.ensure_clause.statements, lenv) : DummyNilNode.new(code_range, lenv)
|
370
371
|
end
|
371
372
|
|
372
373
|
attr_reader :body, :rescue_conds, :rescue_clauses, :else_clause, :ensure_clause
|
@@ -220,6 +220,10 @@ module TypeProf::Core
|
|
220
220
|
rest_keywords = @rest_keywords ? @body.lenv.new_var(@rest_keywords, self) : nil
|
221
221
|
block = @block ? @body.lenv.new_var(@block, self) : nil
|
222
222
|
|
223
|
+
if rest_positionals
|
224
|
+
@changes.add_edge(genv, Source.new(genv.gen_ary_type(Vertex.new(self))), rest_positionals)
|
225
|
+
end
|
226
|
+
|
223
227
|
@opt_positional_defaults.zip(opt_positionals) do |expr, vtx|
|
224
228
|
@changes.add_edge(genv, expr.install(genv), vtx)
|
225
229
|
end
|
@@ -5,7 +5,7 @@ module TypeProf::Core
|
|
5
5
|
when :string_node
|
6
6
|
AST.create_node(raw_part, lenv)
|
7
7
|
when :embedded_statements_node
|
8
|
-
AST.create_node(raw_part.statements, lenv)
|
8
|
+
raw_part.statements ? AST.create_node(raw_part.statements, lenv) : DummyNilNode.new(TypeProf::CodeRange.from_node(raw_part), lenv)
|
9
9
|
when :embedded_variable_node
|
10
10
|
AST.create_node(raw_part.variable, lenv)
|
11
11
|
else
|
data/lib/typeprof/core/env.rb
CHANGED
@@ -282,11 +282,12 @@ module TypeProf::Core
|
|
282
282
|
@cref = cref
|
283
283
|
@locals = locals
|
284
284
|
@return_boxes = return_boxes
|
285
|
+
@break_vtx = nil
|
285
286
|
@next_boxes = []
|
286
287
|
@filters = {}
|
287
288
|
end
|
288
289
|
|
289
|
-
attr_reader :path, :cref, :locals, :return_boxes, :next_boxes
|
290
|
+
attr_reader :path, :cref, :locals, :return_boxes, :break_vtx, :next_boxes
|
290
291
|
|
291
292
|
def new_var(name, node)
|
292
293
|
@locals[name] = Vertex.new(node)
|
@@ -312,6 +313,11 @@ module TypeProf::Core
|
|
312
313
|
@next_boxes << box
|
313
314
|
end
|
314
315
|
|
316
|
+
def get_break_vtx
|
317
|
+
@break_vtx ||= Vertex.new(:break_vtx)
|
318
|
+
end
|
319
|
+
|
320
|
+
|
315
321
|
def push_read_filter(name, type)
|
316
322
|
(@filters[name] ||= []) << type
|
317
323
|
end
|
@@ -485,7 +485,11 @@ module TypeProf::Core
|
|
485
485
|
|
486
486
|
if @f_args.rest_positionals
|
487
487
|
rest_vtxs.each do |vtx|
|
488
|
-
|
488
|
+
@f_args.rest_positionals.each_type do |ty|
|
489
|
+
if ty.is_a?(Type::Instance) && ty.mod == genv.mod_ary && ty.args[0]
|
490
|
+
changes.add_edge(genv, vtx, ty.args[0])
|
491
|
+
end
|
492
|
+
end
|
489
493
|
end
|
490
494
|
end
|
491
495
|
else
|
@@ -519,9 +523,12 @@ module TypeProf::Core
|
|
519
523
|
|
520
524
|
if start_rest < end_rest
|
521
525
|
if @f_args.rest_positionals
|
522
|
-
f_arg = @f_args.rest_positionals
|
523
526
|
(start_rest..end_rest-1).each do |i|
|
524
|
-
|
527
|
+
@f_args.rest_positionals.each_type do |ty|
|
528
|
+
if ty.is_a?(Type::Instance) && ty.mod == genv.mod_ary && ty.args[0]
|
529
|
+
changes.add_edge(genv, a_args.positionals[i], ty.args[0])
|
530
|
+
end
|
531
|
+
end
|
525
532
|
end
|
526
533
|
end
|
527
534
|
end
|
@@ -569,7 +576,7 @@ module TypeProf::Core
|
|
569
576
|
args << ("?" + Type.strip_parens(f_vtx.show))
|
570
577
|
end
|
571
578
|
if @f_args.rest_positionals
|
572
|
-
args << ("*" + Type.strip_parens(@f_args.rest_positionals.show))
|
579
|
+
args << ("*" + Type.strip_array(Type.strip_parens(@f_args.rest_positionals.show)))
|
573
580
|
end
|
574
581
|
@f_args.post_positionals.each do |var|
|
575
582
|
args << Type.strip_parens(var.show)
|
@@ -42,6 +42,7 @@ module TypeProf::Core
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def show
|
45
|
+
Fiber[:show_rec] ||= Set[]
|
45
46
|
if Fiber[:show_rec].include?(self)
|
46
47
|
"untyped"
|
47
48
|
else
|
@@ -117,6 +118,7 @@ module TypeProf::Core
|
|
117
118
|
end
|
118
119
|
|
119
120
|
def show
|
121
|
+
Fiber[:show_rec] ||= Set[]
|
120
122
|
if Fiber[:show_rec].include?(self)
|
121
123
|
"...(recursive)..."
|
122
124
|
else
|
@@ -146,6 +148,7 @@ module TypeProf::Core
|
|
146
148
|
when ValueEntity
|
147
149
|
when ActualArguments
|
148
150
|
when Array
|
151
|
+
when Symbol
|
149
152
|
else
|
150
153
|
raise "unknown class: #{ origin.class }"
|
151
154
|
end
|
@@ -3,7 +3,8 @@ module TypeProf::Core
|
|
3
3
|
def initialize(options)
|
4
4
|
@options = options
|
5
5
|
|
6
|
-
@
|
6
|
+
@rb_text_nodes = {}
|
7
|
+
@rbs_text_nodes = {}
|
7
8
|
|
8
9
|
@genv = GlobalEnv.new
|
9
10
|
@genv.load_core_rbs(load_rbs_declarations(@options[:rbs_collection]).declarations)
|
@@ -26,43 +27,39 @@ module TypeProf::Core
|
|
26
27
|
attr_reader :genv
|
27
28
|
|
28
29
|
def reset!
|
29
|
-
@
|
30
|
-
|
31
|
-
node.each {|n| n.undefine(@genv) }
|
32
|
-
else
|
33
|
-
node.undefine(@genv)
|
34
|
-
end
|
35
|
-
end
|
30
|
+
@rb_text_nodes.each_value {|node| node.undefine(@genv) }
|
31
|
+
@rbs_text_nodes.each_value {|nodes| nodes.each {|n| n.undefine(@genv) } }
|
36
32
|
@genv.define_all
|
37
|
-
@
|
38
|
-
|
39
|
-
node.each {|n| n.uninstall(@genv) }
|
40
|
-
else
|
41
|
-
node.uninstall(@genv)
|
42
|
-
end
|
43
|
-
end
|
33
|
+
@rb_text_nodes.each_value {|node| node.uninstall(@genv) }
|
34
|
+
@rbs_text_nodes.each_value {|nodes| nodes.each {|n| n.uninstall(@genv) } }
|
44
35
|
@genv.run_all
|
45
|
-
@
|
36
|
+
@rb_text_nodes.clear
|
37
|
+
@rbs_text_nodes.clear
|
46
38
|
end
|
47
39
|
|
48
40
|
def add_workspace(rb_folder, rbs_folder)
|
49
|
-
Dir.glob(File.expand_path(rb_folder + "/**/*.rb")) do |path|
|
50
|
-
|
41
|
+
Dir.glob(File.expand_path(rb_folder + "/**/*.{rb,rbs}")) do |path|
|
42
|
+
update_file(path, nil)
|
51
43
|
end
|
52
|
-
|
53
|
-
|
44
|
+
end
|
45
|
+
|
46
|
+
def update_file(path, code)
|
47
|
+
if File.extname(path) == ".rbs"
|
48
|
+
update_rbs_file(path, code)
|
49
|
+
else
|
50
|
+
update_rb_file(path, code)
|
54
51
|
end
|
55
52
|
end
|
56
53
|
|
57
54
|
def update_rb_file(path, code)
|
58
|
-
prev_node = @
|
55
|
+
prev_node = @rb_text_nodes[path]
|
59
56
|
|
60
57
|
code = File.read(path) unless code
|
61
58
|
node = AST.parse_rb(path, code)
|
62
59
|
return false unless node
|
63
60
|
|
64
|
-
node.diff(@
|
65
|
-
@
|
61
|
+
node.diff(@rb_text_nodes[path]) if prev_node
|
62
|
+
@rb_text_nodes[path] = node
|
66
63
|
|
67
64
|
node.define(@genv)
|
68
65
|
prev_node.undefine(@genv) if prev_node
|
@@ -115,7 +112,7 @@ module TypeProf::Core
|
|
115
112
|
end
|
116
113
|
|
117
114
|
def update_rbs_file(path, code)
|
118
|
-
prev_decls = @
|
115
|
+
prev_decls = @rbs_text_nodes[path]
|
119
116
|
|
120
117
|
code = File.read(path) unless code
|
121
118
|
begin
|
@@ -125,7 +122,7 @@ module TypeProf::Core
|
|
125
122
|
end
|
126
123
|
|
127
124
|
# TODO: diff
|
128
|
-
@
|
125
|
+
@rbs_text_nodes[path] = decls
|
129
126
|
|
130
127
|
decls.each {|decl| decl.define(@genv) }
|
131
128
|
prev_decls.each {|decl| decl.undefine(@genv) } if prev_decls
|
@@ -139,13 +136,12 @@ module TypeProf::Core
|
|
139
136
|
end
|
140
137
|
|
141
138
|
def diagnostics(path, &blk)
|
142
|
-
|
143
|
-
node.diagnostics(@genv, &blk) if node
|
139
|
+
@rb_text_nodes[path]&.diagnostics(@genv, &blk)
|
144
140
|
end
|
145
141
|
|
146
142
|
def definitions(path, pos)
|
147
143
|
defs = []
|
148
|
-
@
|
144
|
+
@rb_text_nodes[path]&.retrieve_at(pos) do |node|
|
149
145
|
node.boxes(:cread) do |box|
|
150
146
|
if box.const_read && box.const_read.cdef
|
151
147
|
box.const_read.cdef.defs.each do |cdef_node|
|
@@ -184,7 +180,7 @@ module TypeProf::Core
|
|
184
180
|
end
|
185
181
|
|
186
182
|
def type_definitions(path, pos)
|
187
|
-
@
|
183
|
+
@rb_text_nodes[path]&.retrieve_at(pos) do |node|
|
188
184
|
if node.ret
|
189
185
|
ty_defs = []
|
190
186
|
node.ret.types.map do |ty, _source|
|
@@ -206,7 +202,7 @@ module TypeProf::Core
|
|
206
202
|
#: (String, TypeProf::CodePosition) -> Array[[String?, TypeProf::CodeRange]]?
|
207
203
|
def references(path, pos)
|
208
204
|
refs = []
|
209
|
-
@
|
205
|
+
@rb_text_nodes[path]&.retrieve_at(pos) do |node|
|
210
206
|
case node
|
211
207
|
when AST::DefNode
|
212
208
|
if node.mid_code_range.include?(pos)
|
@@ -246,7 +242,7 @@ module TypeProf::Core
|
|
246
242
|
def rename(path, pos)
|
247
243
|
mdefs = []
|
248
244
|
cdefs = []
|
249
|
-
@
|
245
|
+
@rb_text_nodes[path]&.retrieve_at(pos) do |node|
|
250
246
|
node.boxes(:mcall) do |box|
|
251
247
|
box.resolve(genv, nil) do |me, _ty, _mid, _orig_ty|
|
252
248
|
next unless me
|
@@ -298,7 +294,7 @@ module TypeProf::Core
|
|
298
294
|
end
|
299
295
|
|
300
296
|
def hover(path, pos)
|
301
|
-
@
|
297
|
+
@rb_text_nodes[path]&.retrieve_at(pos) do |node|
|
302
298
|
node.boxes(:mcall) do |box|
|
303
299
|
boxes = []
|
304
300
|
box.changes.boxes.each do |key, box|
|
@@ -332,7 +328,7 @@ module TypeProf::Core
|
|
332
328
|
|
333
329
|
def code_lens(path)
|
334
330
|
cpaths = []
|
335
|
-
@
|
331
|
+
@rb_text_nodes[path]&.traverse do |event, node|
|
336
332
|
if node.is_a?(AST::ModuleBaseNode)
|
337
333
|
if node.static_cpath
|
338
334
|
if event == :enter
|
@@ -356,7 +352,7 @@ module TypeProf::Core
|
|
356
352
|
end
|
357
353
|
|
358
354
|
def completion(path, trigger, pos)
|
359
|
-
@
|
355
|
+
@rb_text_nodes[path]&.retrieve_at(pos) do |node|
|
360
356
|
if node.code_range.last == pos.right
|
361
357
|
node.ret.types.map do |ty, _source|
|
362
358
|
base_ty = ty.base_type(genv)
|
@@ -386,7 +382,7 @@ module TypeProf::Core
|
|
386
382
|
def dump_declarations(path)
|
387
383
|
stack = []
|
388
384
|
out = []
|
389
|
-
@
|
385
|
+
@rb_text_nodes[path]&.traverse do |event, node|
|
390
386
|
case node
|
391
387
|
when AST::ModuleNode
|
392
388
|
if node.static_cpath
|
@@ -481,11 +477,7 @@ module TypeProf::Core
|
|
481
477
|
i += 1
|
482
478
|
end
|
483
479
|
|
484
|
-
|
485
|
-
res = update_rbs_file(file, File.read(file))
|
486
|
-
else
|
487
|
-
res = update_rb_file(file, File.read(file))
|
488
|
-
end
|
480
|
+
res = update_file(file, File.read(file))
|
489
481
|
|
490
482
|
if res
|
491
483
|
true
|
data/lib/typeprof/core/type.rb
CHANGED
@@ -11,6 +11,10 @@ module TypeProf::Core
|
|
11
11
|
s.start_with?("(") && s.end_with?(")") ? s[1..-2] || raise : s
|
12
12
|
end
|
13
13
|
|
14
|
+
def self.strip_array(s)
|
15
|
+
s.start_with?("Array[") && s.end_with?("]") ? s[6..-2] || raise : s
|
16
|
+
end
|
17
|
+
|
14
18
|
def self.default_param_map(genv, ty)
|
15
19
|
ty = ty.base_type(genv)
|
16
20
|
instance_ty = ty.is_a?(Type::Instance) ? ty : Type::Instance.new(genv, ty.mod, []) # TODO: type params
|
data/lib/typeprof/core.rb
CHANGED
@@ -23,7 +23,6 @@ require_relative "core/env/type_alias_entity"
|
|
23
23
|
require_relative "core/env/value_entity"
|
24
24
|
require_relative "core/env/method"
|
25
25
|
require_relative "core/env/static_read"
|
26
|
-
require_relative "core/graph"
|
27
26
|
require_relative "core/graph/change_set"
|
28
27
|
require_relative "core/graph/vertex"
|
29
28
|
require_relative "core/graph/filter"
|
@@ -28,21 +28,6 @@ module TypeProf::LSP
|
|
28
28
|
@server.send_notification(method, **params)
|
29
29
|
end
|
30
30
|
|
31
|
-
def publish_diagnostics(uri)
|
32
|
-
text = @server.open_texts[uri]
|
33
|
-
diags = []
|
34
|
-
if text
|
35
|
-
@server.core.diagnostics(text.path) do |diag|
|
36
|
-
diags << diag.to_lsp
|
37
|
-
end
|
38
|
-
end
|
39
|
-
notify(
|
40
|
-
"textDocument/publishDiagnostics",
|
41
|
-
uri: uri,
|
42
|
-
diagnostics: diags
|
43
|
-
)
|
44
|
-
end
|
45
|
-
|
46
31
|
Classes = []
|
47
32
|
def self.inherited(klass)
|
48
33
|
Classes << klass
|
@@ -72,7 +57,7 @@ module TypeProf::LSP
|
|
72
57
|
def run
|
73
58
|
folders = @params[:workspaceFolders].map do |folder|
|
74
59
|
folder => { uri:, }
|
75
|
-
|
60
|
+
@server.uri_to_path(uri)
|
76
61
|
end
|
77
62
|
|
78
63
|
@server.add_workspaces(folders)
|
@@ -146,14 +131,14 @@ module TypeProf::LSP
|
|
146
131
|
def run
|
147
132
|
@params => { textDocument: { uri:, version:, text: } }
|
148
133
|
|
149
|
-
path =
|
134
|
+
path = @server.uri_to_path(uri)
|
150
135
|
return unless @server.target_path?(path)
|
151
136
|
|
152
137
|
text = Text.new(path, text, version)
|
153
138
|
@server.open_texts[uri] = text
|
154
|
-
@server.core.
|
139
|
+
@server.core.update_file(text.path, text.string)
|
155
140
|
@server.send_request("workspace/codeLens/refresh")
|
156
|
-
publish_diagnostics(uri)
|
141
|
+
@server.publish_diagnostics(uri)
|
157
142
|
end
|
158
143
|
end
|
159
144
|
|
@@ -164,9 +149,9 @@ module TypeProf::LSP
|
|
164
149
|
text = @server.open_texts[uri]
|
165
150
|
return unless text
|
166
151
|
text.apply_changes(changes, version)
|
167
|
-
@server.core.
|
152
|
+
@server.core.update_file(text.path, text.string)
|
168
153
|
@server.send_request("workspace/codeLens/refresh")
|
169
|
-
publish_diagnostics(uri)
|
154
|
+
@server.publish_diagnostics(uri)
|
170
155
|
end
|
171
156
|
end
|
172
157
|
|
@@ -180,7 +165,7 @@ module TypeProf::LSP
|
|
180
165
|
@params => { textDocument: { uri: } }
|
181
166
|
text = @server.open_texts.delete(uri)
|
182
167
|
return unless text
|
183
|
-
@server.core.
|
168
|
+
@server.core.update_file(text.path, nil)
|
184
169
|
end
|
185
170
|
end
|
186
171
|
|
@@ -204,7 +189,7 @@ module TypeProf::LSP
|
|
204
189
|
else
|
205
190
|
respond(defs.map do |path, code_range|
|
206
191
|
{
|
207
|
-
uri:
|
192
|
+
uri: @server.path_to_uri(path),
|
208
193
|
range: code_range.to_lsp,
|
209
194
|
}
|
210
195
|
end)
|
@@ -230,7 +215,7 @@ module TypeProf::LSP
|
|
230
215
|
else
|
231
216
|
respond(defs.map do |path, code_range|
|
232
217
|
{
|
233
|
-
uri:
|
218
|
+
uri: @server.path_to_uri(path),
|
234
219
|
range: code_range.to_lsp,
|
235
220
|
}
|
236
221
|
end)
|
@@ -254,7 +239,7 @@ module TypeProf::LSP
|
|
254
239
|
if callsites
|
255
240
|
respond(callsites.map do |path, code_range|
|
256
241
|
{
|
257
|
-
uri:
|
242
|
+
uri: @server.path_to_uri(path),
|
258
243
|
range: code_range.to_lsp,
|
259
244
|
}
|
260
245
|
end)
|
@@ -332,7 +317,7 @@ module TypeProf::LSP
|
|
332
317
|
items = []
|
333
318
|
sort = "aaaa"
|
334
319
|
text.modify_for_completion(text, pos) do |string, trigger, pos|
|
335
|
-
@server.core.
|
320
|
+
@server.core.update_file(text.path, string)
|
336
321
|
pos = TypeProf::CodePosition.from_lsp(pos)
|
337
322
|
@server.core.completion(text.path, trigger, pos) do |mid, hint|
|
338
323
|
items << {
|
@@ -348,7 +333,7 @@ module TypeProf::LSP
|
|
348
333
|
isIncomplete: false,
|
349
334
|
items: items,
|
350
335
|
)
|
351
|
-
@server.core.
|
336
|
+
@server.core.update_file(text.path, text.string)
|
352
337
|
end
|
353
338
|
end
|
354
339
|
|
@@ -373,7 +358,7 @@ module TypeProf::LSP
|
|
373
358
|
if renames
|
374
359
|
changes = {}
|
375
360
|
renames.each do |path, cr|
|
376
|
-
(changes[
|
361
|
+
(changes[@server.path_to_uri(path)] ||= []) << {
|
377
362
|
range: cr.to_lsp,
|
378
363
|
newText: newName,
|
379
364
|
}
|
data/lib/typeprof/lsp/server.rb
CHANGED
@@ -44,7 +44,7 @@ module TypeProf::LSP
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def initialize(core, reader, writer)
|
47
|
+
def initialize(core, reader, writer, url_schema: nil, publish_all_diagnostics: false)
|
48
48
|
@core = core
|
49
49
|
@workspaces = {}
|
50
50
|
@reader = reader
|
@@ -55,11 +55,21 @@ module TypeProf::LSP
|
|
55
55
|
@open_texts = {}
|
56
56
|
@exit = false
|
57
57
|
@signature_enabled = true
|
58
|
+
@url_schema = url_schema || (File::ALT_SEPARATOR != "\\" ? "file://" : "file:///")
|
59
|
+
@publish_all_diagnostics = publish_all_diagnostics # TODO: implement more dedicated publish feature
|
58
60
|
end
|
59
61
|
|
60
62
|
attr_reader :core, :open_texts
|
61
63
|
attr_accessor :signature_enabled
|
62
64
|
|
65
|
+
def path_to_uri(path)
|
66
|
+
@url_schema + File.expand_path(path)
|
67
|
+
end
|
68
|
+
|
69
|
+
def uri_to_path(url)
|
70
|
+
url.delete_prefix(@url_schema)
|
71
|
+
end
|
72
|
+
|
63
73
|
def add_workspaces(folders)
|
64
74
|
folders.each do |path|
|
65
75
|
conf_path = File.join(path, "typeprof.conf.json")
|
@@ -136,6 +146,22 @@ module TypeProf::LSP
|
|
136
146
|
def exit
|
137
147
|
@exit = true
|
138
148
|
end
|
149
|
+
|
150
|
+
def publish_diagnostics(uri)
|
151
|
+
(@publish_all_diagnostics ? @open_texts : [[uri, @open_texts[uri]]]).each do |uri, text|
|
152
|
+
diags = []
|
153
|
+
if text
|
154
|
+
@core.diagnostics(text.path) do |diag|
|
155
|
+
diags << diag.to_lsp
|
156
|
+
end
|
157
|
+
end
|
158
|
+
send_notification(
|
159
|
+
"textDocument/publishDiagnostics",
|
160
|
+
uri: uri,
|
161
|
+
diagnostics: diags
|
162
|
+
)
|
163
|
+
end
|
164
|
+
end
|
139
165
|
end
|
140
166
|
|
141
167
|
class Reader
|
data/lib/typeprof/lsp/util.rb
CHANGED
@@ -48,14 +48,4 @@ module TypeProf::LSP
|
|
48
48
|
|
49
49
|
JSON.parse(json, **opts)
|
50
50
|
end
|
51
|
-
|
52
|
-
FILE_URL_PREFIX = File::ALT_SEPARATOR != "\\" ? "file://" : "file:///"
|
53
|
-
|
54
|
-
def self.file_path_to_uri(path)
|
55
|
-
FILE_URL_PREFIX + File.expand_path(path)
|
56
|
-
end
|
57
|
-
|
58
|
-
def self.file_uri_to_path(url)
|
59
|
-
url.delete_prefix(FILE_URL_PREFIX)
|
60
|
-
end
|
61
51
|
end
|
data/lib/typeprof/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typeprof
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.30.
|
4
|
+
version: 0.30.1
|
5
5
|
platform: ruby
|
6
|
-
original_platform: ''
|
7
6
|
authors:
|
8
7
|
- Yusuke Endoh
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rbs
|
@@ -67,7 +67,6 @@ files:
|
|
67
67
|
- lib/typeprof/core/env/static_read.rb
|
68
68
|
- lib/typeprof/core/env/type_alias_entity.rb
|
69
69
|
- lib/typeprof/core/env/value_entity.rb
|
70
|
-
- lib/typeprof/core/graph.rb
|
71
70
|
- lib/typeprof/core/graph/box.rb
|
72
71
|
- lib/typeprof/core/graph/change_set.rb
|
73
72
|
- lib/typeprof/core/graph/filter.rb
|
@@ -89,6 +88,7 @@ licenses:
|
|
89
88
|
metadata:
|
90
89
|
homepage_uri: https://github.com/ruby/typeprof
|
91
90
|
source_code_uri: https://github.com/ruby/typeprof
|
91
|
+
post_install_message:
|
92
92
|
rdoc_options: []
|
93
93
|
require_paths:
|
94
94
|
- lib
|
@@ -103,7 +103,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
|
-
rubygems_version: 3.
|
106
|
+
rubygems_version: 3.5.22
|
107
|
+
signing_key:
|
107
108
|
specification_version: 4
|
108
109
|
summary: TypeProf is a type analysis tool for Ruby code based on abstract interpretation
|
109
110
|
test_files: []
|
data/lib/typeprof/core/graph.rb
DELETED