ruby-lsp-typeprof 0.4.0 → 0.5.0
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/README.md +3 -1
- data/lib/ruby_lsp/ruby_lsp_typeprof/addon.rb +10 -0
- data/lib/ruby_lsp/ruby_lsp_typeprof/code_lens_listener.rb +4 -19
- data/lib/ruby_lsp/ruby_lsp_typeprof/document_symbol_listener.rb +63 -0
- data/lib/ruby_lsp/ruby_lsp_typeprof/signature_cache.rb +35 -0
- data/lib/ruby_lsp_typeprof/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1b0dc266b02ba9428bd88e6001b094436c17fe94407477e1e2f184825416a40a
|
|
4
|
+
data.tar.gz: 70fa07a521a222f5c9e1ac9a62e2458bd41308b1eb6559a7252d8cfe8298008c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4ed5ddf9b0a88bd9ad17fa748225ad62d23b1ab5e99f181b21a5dea1f10c2fecab850403c39470447487550b11f7a03989b648f7d61aa8ab586b5f8b75d5d50c
|
|
7
|
+
data.tar.gz: 33ea5a60eeb2295adff2ad7f73828d17dabe17cbcc01be64209bca361e8bb8bcd36f61f5b6e84a40601be2e9299817652dae9915024f90a8c6738d1447cdf1c7
|
data/README.md
CHANGED
|
@@ -27,7 +27,8 @@ Configure them in VS Code's `settings.json`:
|
|
|
27
27
|
"rubyLsp.addonSettings": {
|
|
28
28
|
"TypeProf": {
|
|
29
29
|
"enabled": false,
|
|
30
|
-
"enableCodeLens": false
|
|
30
|
+
"enableCodeLens": false,
|
|
31
|
+
"enableDocumentSymbol": false
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
}
|
|
@@ -45,6 +46,7 @@ You can place this configuration in either:
|
|
|
45
46
|
| --- | --- | --- | --- |
|
|
46
47
|
| `enabled` | boolean | `true` | Master switch. When `false`, the add-on skips loading TypeProf entirely and disables every feature. |
|
|
47
48
|
| `enableCodeLens` | boolean | `true` | Show inferred type signatures as code lens above method definitions. Has no effect when `enabled` is `false`. |
|
|
49
|
+
| `enableDocumentSymbol` | boolean | `true` | Add inferred type signatures as child symbols of method definitions in the document symbol response, so clients that do not support code lens (for example Claude Code) can see them. Has no effect when `enabled` is `false`. |
|
|
48
50
|
|
|
49
51
|
After changing the setting, restart Ruby LSP via the "Ruby LSP: Restart"
|
|
50
52
|
command for it to take effect.
|
|
@@ -5,6 +5,7 @@ require "ruby_lsp/addon"
|
|
|
5
5
|
require "uri"
|
|
6
6
|
|
|
7
7
|
require_relative "code_lens_listener"
|
|
8
|
+
require_relative "document_symbol_listener"
|
|
8
9
|
require_relative "loggable"
|
|
9
10
|
|
|
10
11
|
module RubyLsp
|
|
@@ -18,6 +19,7 @@ module RubyLsp
|
|
|
18
19
|
@mutex = Mutex.new
|
|
19
20
|
@enabled = true
|
|
20
21
|
@code_lens_enabled = true
|
|
22
|
+
@document_symbol_enabled = true
|
|
21
23
|
end
|
|
22
24
|
|
|
23
25
|
def activate(global_state, outgoing_queue)
|
|
@@ -52,6 +54,13 @@ module RubyLsp
|
|
|
52
54
|
CodeLensListener.new(response_builder, uri, dispatcher, @service, @mutex, @outgoing_queue)
|
|
53
55
|
end
|
|
54
56
|
|
|
57
|
+
def create_document_symbol_listener(response_builder, dispatcher)
|
|
58
|
+
return unless @service
|
|
59
|
+
return unless @document_symbol_enabled
|
|
60
|
+
|
|
61
|
+
DocumentSymbolListener.new(response_builder, dispatcher, @service, @mutex, @outgoing_queue)
|
|
62
|
+
end
|
|
63
|
+
|
|
55
64
|
def workspace_did_change_watched_files(changes)
|
|
56
65
|
return unless @service
|
|
57
66
|
|
|
@@ -66,6 +75,7 @@ module RubyLsp
|
|
|
66
75
|
settings = global_state.settings_for_addon(name)
|
|
67
76
|
@enabled = settings&.dig(:enabled) != false
|
|
68
77
|
@code_lens_enabled = settings&.dig(:enableCodeLens) != false
|
|
78
|
+
@document_symbol_enabled = settings&.dig(:enableDocumentSymbol) != false
|
|
69
79
|
end
|
|
70
80
|
|
|
71
81
|
def build_service(workspace_path)
|
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative "
|
|
3
|
+
require_relative "signature_cache"
|
|
4
4
|
|
|
5
5
|
module RubyLsp
|
|
6
6
|
module Typeprof
|
|
7
7
|
class CodeLensListener
|
|
8
|
-
include Loggable
|
|
9
|
-
|
|
10
8
|
def initialize(response_builder, uri, dispatcher, service, mutex, outgoing_queue)
|
|
11
9
|
@response_builder = response_builder
|
|
12
|
-
@
|
|
13
|
-
@lens_cache = {}
|
|
14
|
-
@outgoing_queue = outgoing_queue
|
|
10
|
+
@signatures = SignatureCache.new(service, mutex, uri.to_standardized_path, outgoing_queue, feature: "code lens")
|
|
15
11
|
|
|
16
|
-
|
|
17
|
-
dispatcher.register(self, :on_def_node_enter) unless @lens_cache.empty?
|
|
12
|
+
dispatcher.register(self, :on_def_node_enter) unless @signatures.empty?
|
|
18
13
|
end
|
|
19
14
|
|
|
20
15
|
def on_def_node_enter(node)
|
|
21
16
|
line = node.location.start_line
|
|
22
|
-
hint = @
|
|
17
|
+
hint = @signatures[line]
|
|
23
18
|
return unless hint
|
|
24
19
|
|
|
25
20
|
@response_builder << build_code_lens(line, hint)
|
|
@@ -35,16 +30,6 @@ module RubyLsp
|
|
|
35
30
|
command: LanguageServer::Protocol::Interface::Command.new(title: "#: #{hint}", command: "")
|
|
36
31
|
)
|
|
37
32
|
end
|
|
38
|
-
|
|
39
|
-
def cache_code_lens_results(service, mutex)
|
|
40
|
-
mutex.synchronize do
|
|
41
|
-
service.code_lens(@path) do |code_range, hint|
|
|
42
|
-
@lens_cache[code_range.first.lineno] = hint
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
rescue StandardError => e
|
|
46
|
-
log_error("Ruby LSP TypeProf failed to compute code lens for #{@path}: #{e.full_message(highlight: false)}")
|
|
47
|
-
end
|
|
48
33
|
end
|
|
49
34
|
end
|
|
50
35
|
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "signature_cache"
|
|
4
|
+
|
|
5
|
+
module RubyLsp
|
|
6
|
+
module Typeprof
|
|
7
|
+
# Appends the inferred method signature as a child symbol of each method
|
|
8
|
+
# definition symbol produced by Ruby LSP's own DocumentSymbol listener.
|
|
9
|
+
#
|
|
10
|
+
# Ruby LSP does not pass the document URI to `create_document_symbol_listener`,
|
|
11
|
+
# so the URI is read from the core listener already registered on the dispatcher.
|
|
12
|
+
class DocumentSymbolListener
|
|
13
|
+
def initialize(response_builder, dispatcher, service, mutex, outgoing_queue)
|
|
14
|
+
@response_builder = response_builder
|
|
15
|
+
path = document_path(dispatcher)
|
|
16
|
+
@signatures = SignatureCache.new(service, mutex, path, outgoing_queue, feature: "document symbol")
|
|
17
|
+
|
|
18
|
+
dispatcher.register(self, :on_def_node_enter) unless @signatures.empty?
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def on_def_node_enter(node)
|
|
22
|
+
hint = @signatures[node.location.start_line]
|
|
23
|
+
return unless hint
|
|
24
|
+
|
|
25
|
+
parent = @response_builder.last
|
|
26
|
+
return unless parent.is_a?(LanguageServer::Protocol::Interface::DocumentSymbol)
|
|
27
|
+
|
|
28
|
+
parent.children << build_signature_symbol(node, hint)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def document_path(dispatcher)
|
|
34
|
+
core_listener = dispatcher.listeners.each_value.flat_map(&:itself).find do |listener|
|
|
35
|
+
listener.is_a?(::RubyLsp::Listeners::DocumentSymbol)
|
|
36
|
+
end
|
|
37
|
+
core_listener&.instance_variable_get(:@uri)&.to_standardized_path
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def build_signature_symbol(node, hint)
|
|
41
|
+
range = range_from_location(node.name_loc)
|
|
42
|
+
|
|
43
|
+
LanguageServer::Protocol::Interface::DocumentSymbol.new(
|
|
44
|
+
name: hint,
|
|
45
|
+
kind: ::RubyLsp::Constant::SymbolKind::TYPE_PARAMETER,
|
|
46
|
+
range: range,
|
|
47
|
+
selection_range: range
|
|
48
|
+
)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def range_from_location(location)
|
|
52
|
+
LanguageServer::Protocol::Interface::Range.new(
|
|
53
|
+
start: LanguageServer::Protocol::Interface::Position.new(
|
|
54
|
+
line: location.start_line - 1, character: location.start_column
|
|
55
|
+
),
|
|
56
|
+
end: LanguageServer::Protocol::Interface::Position.new(
|
|
57
|
+
line: location.end_line - 1, character: location.end_column
|
|
58
|
+
)
|
|
59
|
+
)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "loggable"
|
|
4
|
+
|
|
5
|
+
module RubyLsp
|
|
6
|
+
module Typeprof
|
|
7
|
+
# Collects the method signatures TypeProf inferred for a single file,
|
|
8
|
+
# keyed by the 1-based line number of the method definition.
|
|
9
|
+
class SignatureCache
|
|
10
|
+
include Loggable
|
|
11
|
+
|
|
12
|
+
def initialize(service, mutex, path, outgoing_queue, feature:)
|
|
13
|
+
@outgoing_queue = outgoing_queue
|
|
14
|
+
@hints = {}
|
|
15
|
+
return unless path
|
|
16
|
+
|
|
17
|
+
mutex.synchronize do
|
|
18
|
+
service.code_lens(path) do |code_range, hint|
|
|
19
|
+
@hints[code_range.first.lineno] = hint
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
rescue StandardError => e
|
|
23
|
+
log_error("Ruby LSP TypeProf failed to compute #{feature} for #{path}: #{e.full_message(highlight: false)}")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def [](line)
|
|
27
|
+
@hints[line]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def empty?
|
|
31
|
+
@hints.empty?
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby-lsp-typeprof
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Takumi Shotoku
|
|
@@ -51,7 +51,9 @@ files:
|
|
|
51
51
|
- lib/ruby-lsp-typeprof.rb
|
|
52
52
|
- lib/ruby_lsp/ruby_lsp_typeprof/addon.rb
|
|
53
53
|
- lib/ruby_lsp/ruby_lsp_typeprof/code_lens_listener.rb
|
|
54
|
+
- lib/ruby_lsp/ruby_lsp_typeprof/document_symbol_listener.rb
|
|
54
55
|
- lib/ruby_lsp/ruby_lsp_typeprof/loggable.rb
|
|
56
|
+
- lib/ruby_lsp/ruby_lsp_typeprof/signature_cache.rb
|
|
55
57
|
- lib/ruby_lsp_typeprof/version.rb
|
|
56
58
|
- sig/ruby_lsp_typeprof/version.rbs
|
|
57
59
|
homepage: https://github.com/sinsoku/ruby-lsp-typeprof
|
|
@@ -59,7 +61,7 @@ licenses:
|
|
|
59
61
|
- MIT
|
|
60
62
|
metadata:
|
|
61
63
|
homepage_uri: https://github.com/sinsoku/ruby-lsp-typeprof
|
|
62
|
-
source_code_uri: https://github.com/sinsoku/ruby-lsp-typeprof/tree/v0.
|
|
64
|
+
source_code_uri: https://github.com/sinsoku/ruby-lsp-typeprof/tree/v0.5.0
|
|
63
65
|
changelog_uri: https://github.com/sinsoku/ruby-lsp-typeprof/releases
|
|
64
66
|
rubygems_mfa_required: 'true'
|
|
65
67
|
rdoc_options: []
|
|
@@ -76,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
76
78
|
- !ruby/object:Gem::Version
|
|
77
79
|
version: '0'
|
|
78
80
|
requirements: []
|
|
79
|
-
rubygems_version: 4.0.
|
|
81
|
+
rubygems_version: 4.0.16
|
|
80
82
|
specification_version: 4
|
|
81
83
|
summary: A Ruby LSP addon for TypeProf
|
|
82
84
|
test_files: []
|