ruby-lsp-typeprof 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2a3567db20f05419823a0f84a7779f77e9ef39606302242851232ba78bc7cc3f
4
+ data.tar.gz: 7ff4ba5760b46ac3e51c7b21294c04c84ce65c52921a3a00d900523d519930c6
5
+ SHA512:
6
+ metadata.gz: f586a90f9ade8046de2de872eabc7ba41554b18b1553e919e675daa9aa6d737f40a4b82b342f5c63f9f6892c70bed314db701bc020d4c8c83427f64b74bcf284
7
+ data.tar.gz: acba530fb0638a864b644f6d3f2b1aa07a54047e048d3dfbd5feda2f88ca2be2b47276b2bf8e11d5abfd072ec36d1db5ecb1895a134b245cf9569949a97f845b
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2026-04-27
4
+
5
+ - feat: Display type declarations using Code Lens
@@ -0,0 +1,10 @@
1
+ # Code of Conduct
2
+
3
+ "ruby-lsp-typeprof" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
4
+
5
+ * Participants will be tolerant of opposing views.
6
+ * Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
7
+ * When interpreting the words and actions of others, participants should always assume good intentions.
8
+ * Behaviour which can be reasonably considered harassment will not be tolerated.
9
+
10
+ If you have any concerns about behaviour within this project, please contact us at ["sinsoku.listy@gmail.com"](mailto:"sinsoku.listy@gmail.com").
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Takumi Shotoku
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # TypeProf add-on
2
+
3
+ The TypeProf add-on is a [Ruby LSP](https://github.com/Shopify/ruby-lsp) [add-on](https://shopify.github.io/ruby-lsp/add-ons.html) to provide type inference features.
4
+
5
+ ## Installation
6
+
7
+ Add `ruby-lsp-typeprof` to your Gemfile:
8
+
9
+ ```ruby
10
+ group :development do
11
+ gem "ruby-lsp-typeprof", require: false
12
+ end
13
+ ```
14
+
15
+ After running `bundle install`, restart Ruby LSP.
16
+
17
+ ## Development
18
+
19
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
20
+
21
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
22
+
23
+ ## Contributing
24
+
25
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sinsoku/ruby-lsp-typeprof. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/sinsoku/ruby-lsp-typeprof/blob/main/CODE_OF_CONDUCT.md).
26
+
27
+ ## License
28
+
29
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
30
+
31
+ ## Code of Conduct
32
+
33
+ Everyone interacting in the Ruby::Lsp::Typeprof project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/sinsoku/ruby-lsp-typeprof/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ruby_lsp_typeprof/version"
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ruby-lsp-typeprof"
4
+ require "ruby_lsp/addon"
5
+ require "uri"
6
+
7
+ require_relative "code_lens_listener"
8
+
9
+ module RubyLsp
10
+ module Typeprof
11
+ class Addon < ::RubyLsp::Addon
12
+ def initialize
13
+ super
14
+ @service = nil
15
+ @mutex = Mutex.new
16
+ end
17
+
18
+ def activate(global_state, _outgoing_queue)
19
+ require "typeprof"
20
+
21
+ @service = build_service(global_state.workspace_path)
22
+ rescue StandardError => e
23
+ warn "ruby-lsp-typeprof: Failed to activate: #{e.message}"
24
+ end
25
+
26
+ def deactivate
27
+ @service = nil
28
+ end
29
+
30
+ def name
31
+ "TypeProf"
32
+ end
33
+
34
+ def version
35
+ VERSION
36
+ end
37
+
38
+ def create_code_lens_listener(response_builder, uri, dispatcher)
39
+ return unless @service
40
+
41
+ CodeLensListener.new(response_builder, uri, dispatcher, @service, @mutex)
42
+ end
43
+
44
+ def workspace_did_change_watched_files(changes)
45
+ return unless @service
46
+
47
+ @mutex.synchronize do
48
+ changes.each { |change| update_changed_file(change) }
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ def build_service(workspace_path)
55
+ conf = load_typeprof_conf(workspace_path) || default_conf
56
+ rbs_dir = File.expand_path(conf[:rbs_dir], workspace_path)
57
+
58
+ service = TypeProf::Core::Service.new(conf)
59
+ conf[:analysis_unit_dirs].each do |dir|
60
+ service.add_workspace(File.expand_path(dir, workspace_path), rbs_dir)
61
+ end
62
+ service
63
+ end
64
+
65
+ def default_conf
66
+ { analysis_unit_dirs: ["."], rbs_dir: "sig/" }
67
+ end
68
+
69
+ def load_typeprof_conf(workspace_path)
70
+ conf_path = ["typeprof.conf.json", "typeprof.conf.jsonc"].find do |name|
71
+ File.readable?(File.join(workspace_path, name))
72
+ end
73
+ return unless conf_path
74
+
75
+ conf = TypeProf::LSP.load_json_with_comments(File.join(workspace_path, conf_path), symbolize_names: true)
76
+ exclude = conf.delete(:exclude)
77
+ conf[:exclude_patterns] = exclude if exclude
78
+ conf
79
+ end
80
+
81
+ def update_changed_file(change)
82
+ path = URI.parse(change[:uri]).path
83
+ return unless path&.end_with?(".rb", ".rbs")
84
+
85
+ @service.update_file(path, nil)
86
+ rescue StandardError => e
87
+ warn "ruby-lsp-typeprof: Failed to update file #{path}: #{e.message}"
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLsp
4
+ module Typeprof
5
+ class CodeLensListener
6
+ def initialize(response_builder, uri, dispatcher, service, mutex)
7
+ @response_builder = response_builder
8
+ @path = uri.to_standardized_path
9
+ @lens_cache = {}
10
+
11
+ cache_code_lens_results(service, mutex)
12
+ dispatcher.register(self, :on_def_node_enter) unless @lens_cache.empty?
13
+ end
14
+
15
+ def on_def_node_enter(node)
16
+ line = node.location.start_line
17
+ hint = @lens_cache[line]
18
+ return unless hint
19
+
20
+ @response_builder << build_code_lens(line, hint)
21
+ end
22
+
23
+ private
24
+
25
+ def build_code_lens(line, hint)
26
+ position = LanguageServer::Protocol::Interface::Position.new(line: line - 1, character: 0)
27
+
28
+ LanguageServer::Protocol::Interface::CodeLens.new(
29
+ range: LanguageServer::Protocol::Interface::Range.new(start: position, end: position),
30
+ command: LanguageServer::Protocol::Interface::Command.new(title: "#: #{hint}", command: "")
31
+ )
32
+ end
33
+
34
+ def cache_code_lens_results(service, mutex)
35
+ mutex.synchronize do
36
+ service.code_lens(@path) do |code_range, hint|
37
+ @lens_cache[code_range.first.lineno] = hint
38
+ end
39
+ end
40
+ rescue StandardError => e
41
+ warn "ruby-lsp-typeprof: Code lens error: #{e.message}"
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLsp
4
+ module Typeprof
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module RubyLsp
2
+ module Typeprof
3
+ VERSION: String
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-lsp-typeprof
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Takumi Shotoku
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: ruby-lsp
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 0.26.0
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 0.26.0
26
+ - !ruby/object:Gem::Dependency
27
+ name: typeprof
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.31.1
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 0.31.1
40
+ description: A Ruby LSP addon that integrates TypeProf to provide type inference features.
41
+ email:
42
+ - sinsoku.listy@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - CHANGELOG.md
48
+ - CODE_OF_CONDUCT.md
49
+ - LICENSE.txt
50
+ - README.md
51
+ - Rakefile
52
+ - lib/ruby-lsp-typeprof.rb
53
+ - lib/ruby_lsp/ruby_lsp_typeprof/addon.rb
54
+ - lib/ruby_lsp/ruby_lsp_typeprof/code_lens_listener.rb
55
+ - lib/ruby_lsp_typeprof/version.rb
56
+ - sig/ruby_lsp/ruby_lsp_typeprof.rbs
57
+ homepage: https://github.com/sinsoku/ruby-lsp-typeprof
58
+ licenses:
59
+ - MIT
60
+ metadata:
61
+ homepage_uri: https://github.com/sinsoku/ruby-lsp-typeprof
62
+ source_code_uri: https://github.com/sinsoku/ruby-lsp-typeprof/tree/v0.1.0
63
+ changelog_uri: https://github.com/sinsoku/ruby-lsp-typeprof/blob/v0.1.0/CHANGELOG.md
64
+ rubygems_mfa_required: 'true'
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 3.3.0
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubygems_version: 4.0.6
80
+ specification_version: 4
81
+ summary: A Ruby LSP addon for TypeProf
82
+ test_files: []