ruby-lsp-fabrication 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 41245403043d46a85c04a5f22cbb630e2703b9e0b6d07af780c6aba81fd89e33
4
- data.tar.gz: '08fe0bd02656e31325b509100e2074276b12e7be3fada5efda0118457911330a'
3
+ metadata.gz: 6dfcaaeba451c5437a79bb927dd6c817c73757112a4168dd4b7d049f48100a71
4
+ data.tar.gz: d4dc18ec2ffdd331f642c4283c8e27d8f83843fd052539ead712edb31ec6d431
5
5
  SHA512:
6
- metadata.gz: d2906bb1066e587e558860c661c3994a737b4a550733aada97341f754d55284495170c35a43c41471afaae061b561961e85474abf83d5534d360dbb081881e37
7
- data.tar.gz: 757855c7fe8e3636e669039104eb2c242d5a4068a1da66f0c579d5a0dd49138965000295ee5efbac2301580e54b5bd15770f7ceeb87d3356bb212652d89af182
6
+ metadata.gz: 91abb3ec38b1bef86f7d0367dcea20d5567ec5e5285d81dd8b428ec66b97716dbf70abc8fb352eec4d754214553c15e671f318ee1cb40636fe128e56fdcdafa3
7
+ data.tar.gz: 6aae1b41682d74aa96db2e00c3296ddad751cd33734e90f7715a4d9f31ad30b58fe70752e2869f6a5df02192aae2283ae87779c4e5e7d011321471d638545fc4
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+
4
+ Style/Documentation:
5
+ Enabled: false
6
+
7
+ Metrics/MethodLength:
8
+ Enabled: false
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ - Demonstrating empathy and kindness toward other people
14
+ - Being respectful of differing opinions, viewpoints, and experiences
15
+ - Giving and gracefully accepting constructive feedback
16
+ - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ - Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ - The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ - Trolling, insulting or derogatory comments, and personal or political attacks
24
+ - Public or private harassment
25
+ - Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ - Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at stan.lo@shopify.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Stan Lo
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,32 @@
1
+ # Ruby LSP Fabrication
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/ruby-lsp-fabrication.svg)](https://badge.fury.io/rb/ruby-lsp-fabrication)
4
+
5
+ Ruby LSP Fabrication is a [Ruby LSP](https://github.com/Shopify/ruby-lsp) addon for displaying and linking [Fabricators](https://fabricationgem.org/)
6
+
7
+ ## Installation
8
+
9
+ To install, add the following line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ # Gemfile
13
+ group :development do
14
+ gem "ruby-lsp-fabrication", require: false
15
+ end
16
+ ```
17
+
18
+ After running `bundle install`, restart Ruby LSP and you should start seeing Document Symbols.
19
+
20
+ ## Development
21
+
22
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
23
+
24
+ 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).
25
+
26
+ ## Contributing
27
+
28
+ Bug reports and pull requests are welcome on GitHub at https://github.com/imcauley/ruby-lsp-fabrication. See Code of Conduct
29
+
30
+ ## License
31
+
32
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ruby_lsp/addon'
4
+ require 'ruby_lsp/internal'
5
+
6
+ require_relative 'document_symbol'
7
+ require_relative 'indexing_enhancement'
8
+ require_relative 'definition'
9
+
10
+ module RubyLsp
11
+ module Fabrication
12
+ class Addon < ::RubyLsp::Addon
13
+ def activate(global_state, _message_queue)
14
+ @index = global_state.index
15
+ @index.register_enhancement(IndexingEnhancement.new)
16
+ end
17
+
18
+ def deactivate; end
19
+
20
+ def create_definition_listener(response_builder, uri, node_context, dispatcher)
21
+ Definition.new(response_builder, uri, node_context, @index, dispatcher)
22
+ end
23
+
24
+ def create_document_symbol_listener(response_builder, dispatcher)
25
+ DocumentSymbol.new(response_builder, dispatcher)
26
+ end
27
+
28
+ def name
29
+ 'Ruby LSP Fabrication'
30
+ end
31
+
32
+ def version
33
+ VERSION
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLsp
4
+ module Fabrication
5
+ class Definition
6
+ include ::RubyLsp::Requests::Support::Common
7
+
8
+ def initialize(response_builder, uri, node_context, index, dispatcher)
9
+ @response_builder = response_builder
10
+ @uri = uri
11
+ @node_context = node_context
12
+ @index = index
13
+ dispatcher.register(self, :on_symbol_node_enter)
14
+ end
15
+
16
+ def on_symbol_node_enter(node)
17
+ if @node_context.call_node.message == 'Fabricator' && inherited?(node)
18
+ entries = @index["#{node.value}Fabricator"]
19
+
20
+ return if entries.blank? || entries.empty?
21
+
22
+ entries.each do |entry|
23
+ @response_builder << Interface::LocationLink.new(
24
+ target_uri: URI::Generic.from_path(path: entry.file_path).to_s,
25
+ target_range: range_from_location(entry.location),
26
+ target_selection_range: range_from_location(entry.name_location)
27
+ )
28
+ end
29
+
30
+ return
31
+ end
32
+
33
+ return unless @node_context.call_node.message == 'Fabricate'
34
+
35
+ fabricator_name = generate_fabricator_name(@node_context.call_node)
36
+ entries = @index[fabricator_name]
37
+ return if entries.blank? || entries.empty?
38
+
39
+ entries.each do |entry|
40
+ @response_builder << Interface::LocationLink.new(
41
+ target_uri: URI::Generic.from_path(path: entry.file_path).to_s,
42
+ target_range: range_from_location(entry.location),
43
+ target_selection_range: range_from_location(entry.name_location)
44
+ )
45
+ end
46
+ end
47
+
48
+ def inherited?(node)
49
+ @node_context.parent.compact_child_nodes.first.compact_child_nodes.each do |n|
50
+ next unless n.type == :keyword_hash_node
51
+
52
+ first_child = n.compact_child_nodes.first
53
+ next unless first_child.type == :assoc_node
54
+ next unless first_child.key.value == 'from'
55
+ next unless first_child.value.value == node.value
56
+
57
+ return true
58
+ end
59
+
60
+ false
61
+ end
62
+
63
+ def generate_fabricator_name(node)
64
+ arguments = node.compact_child_nodes.first
65
+ name = arguments.compact_child_nodes.first.value
66
+
67
+ "#{name}Fabricator"
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLsp
4
+ module Fabrication
5
+ class DocumentSymbol
6
+ include ::RubyLsp::Requests::Support::Common
7
+
8
+ def initialize(response_builder, dispatcher)
9
+ @response_builder = response_builder
10
+
11
+ dispatcher.register(self, :on_call_node_enter, :on_call_node_leave)
12
+ end
13
+
14
+ def on_call_node_enter(node)
15
+ case node.message
16
+ when 'Fabricator'
17
+ @response_builder.last.children << RubyLsp::Interface::DocumentSymbol.new(
18
+ name: generate_fabricator_name(node),
19
+ kind: LanguageServer::Protocol::Constant::SymbolKind::CLASS,
20
+ selection_range: range_from_node(node),
21
+ range: range_from_node(node)
22
+ )
23
+ when 'Fabricate'
24
+ @response_builder.last.children << RubyLsp::Interface::DocumentSymbol.new(
25
+ name: generate_fabricate_name(node),
26
+ kind: LanguageServer::Protocol::Constant::SymbolKind::OBJECT,
27
+ selection_range: range_from_node(node),
28
+ range: range_from_node(node)
29
+ )
30
+ end
31
+ end
32
+
33
+ def on_call_node_leave(node); end
34
+
35
+ def generate_fabricator_name(node)
36
+ arguments = node.compact_child_nodes.first
37
+ name = arguments.compact_child_nodes.first.value
38
+
39
+ "#{name.titleize} Fabricator"
40
+ end
41
+
42
+ def generate_fabricate_name(node)
43
+ arguments = node.compact_child_nodes.first
44
+ name = arguments.compact_child_nodes.first.value
45
+
46
+ "Fabricated #{name.titleize}"
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLsp
4
+ module Fabrication
5
+ class IndexingEnhancement
6
+ include RubyIndexer::Enhancement
7
+
8
+ def on_call_node(index, owner, node, file_path, code_units_cache)
9
+ name = node.message
10
+
11
+ return unless name == 'Fabricator'
12
+
13
+ index.add(RubyIndexer::Entry::Method.new(
14
+ generate_fabricator_name(node),
15
+ file_path,
16
+ RubyIndexer::Location.from_prism_location(node.location, code_units_cache),
17
+ RubyIndexer::Location.from_prism_location(node.location, code_units_cache),
18
+ nil,
19
+ [RubyIndexer::Entry::Signature.new([])],
20
+ RubyIndexer::Entry::Visibility::PUBLIC,
21
+ owner
22
+ ))
23
+ end
24
+
25
+ def generate_fabricator_name(node)
26
+ arguments = node.compact_child_nodes.first
27
+ name = arguments.compact_child_nodes.first.value
28
+
29
+ "#{name}Fabricator"
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLsp
4
+ module Fabrication
5
+ VERSION = '0.3.0'
6
+ end
7
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/ruby_lsp_fabrication/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'ruby-lsp-fabrication'
7
+ s.version = RubyLsp::Fabrication::VERSION
8
+ s.email = ['mcauleyisaac@gmail.com']
9
+ s.summary = 'Ruby LSP Addon for Fabrication support'
10
+ s.authors = ['Isaac McAuley']
11
+ s.license = 'MIT'
12
+ s.homepage = 'https://github.com/imcauley/ruby-lsp-fabrication'
13
+ s.required_ruby_version = '>= 3.0.0'
14
+
15
+ s.files = Dir.chdir(__dir__) do
16
+ `git ls-files -z`.split("\x0").reject do |f|
17
+ (File.expand_path(f) == __FILE__) ||
18
+ f.start_with?(
19
+ 'bin/',
20
+ 'test/',
21
+ 'spec/',
22
+ 'features/',
23
+ '.git',
24
+ '.circleci',
25
+ 'appveyor',
26
+ 'Gemfile',
27
+ 'misc/',
28
+ 'sorbet/'
29
+ )
30
+ end
31
+ end
32
+ s.require_paths = ['lib']
33
+
34
+ s.add_dependency 'ruby-lsp', '~> 0.20.1'
35
+ end
metadata CHANGED
@@ -1,24 +1,50 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lsp-fabrication
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Isaac McAuley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-20 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-12-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby-lsp
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.20.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.20.1
13
27
  description:
14
28
  email:
29
+ - mcauleyisaac@gmail.com
15
30
  executables: []
16
31
  extensions: []
17
32
  extra_rdoc_files: []
18
33
  files:
34
+ - ".rubocop.yml"
35
+ - CODE_OF_CONDUCT.md
36
+ - LICENSE.txt
37
+ - README.md
19
38
  - lib/ruby-lsp-fabrication.rb
20
- homepage:
21
- licenses: []
39
+ - lib/ruby_lsp/ruby_lsp_fabrication/addon.rb
40
+ - lib/ruby_lsp/ruby_lsp_fabrication/definition.rb
41
+ - lib/ruby_lsp/ruby_lsp_fabrication/document_symbol.rb
42
+ - lib/ruby_lsp/ruby_lsp_fabrication/indexing_enhancement.rb
43
+ - lib/ruby_lsp_fabrication/version.rb
44
+ - ruby-lsp-fabrication.gemspec
45
+ homepage: https://github.com/imcauley/ruby-lsp-fabrication
46
+ licenses:
47
+ - MIT
22
48
  metadata: {}
23
49
  post_install_message:
24
50
  rdoc_options: []
@@ -28,14 +54,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
28
54
  requirements:
29
55
  - - ">="
30
56
  - !ruby/object:Gem::Version
31
- version: '0'
57
+ version: 3.0.0
32
58
  required_rubygems_version: !ruby/object:Gem::Requirement
33
59
  requirements:
34
60
  - - ">="
35
61
  - !ruby/object:Gem::Version
36
62
  version: '0'
37
63
  requirements: []
38
- rubygems_version: 3.3.26
64
+ rubygems_version: 3.5.16
39
65
  signing_key:
40
66
  specification_version: 4
41
67
  summary: Ruby LSP Addon for Fabrication support