ruby-lsp-rspec 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.rubocop.yml +39 -0
  4. data/CHANGELOG.md +5 -0
  5. data/CODE_OF_CONDUCT.md +84 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +45 -0
  8. data/Rakefile +12 -0
  9. data/lib/ruby-lsp-rspec.rb +11 -0
  10. data/lib/ruby_lsp/ruby_lsp_rspec/code_lens.rb +146 -0
  11. data/lib/ruby_lsp/ruby_lsp_rspec/extension.rb +38 -0
  12. data/lib/ruby_lsp_rspec/version.rb +8 -0
  13. data/misc/example.png +0 -0
  14. data/sorbet/config +4 -0
  15. data/sorbet/rbi/annotations/rainbow.rbi +269 -0
  16. data/sorbet/rbi/gems/ast@2.4.2.rbi +584 -0
  17. data/sorbet/rbi/gems/base64@0.1.1.rbi +172 -0
  18. data/sorbet/rbi/gems/diff-lcs@1.5.0.rbi +1083 -0
  19. data/sorbet/rbi/gems/erubi@1.12.0.rbi +145 -0
  20. data/sorbet/rbi/gems/io-console@0.6.0.rbi +8 -0
  21. data/sorbet/rbi/gems/json@2.6.3.rbi +1533 -0
  22. data/sorbet/rbi/gems/language_server-protocol@3.17.0.3.rbi +14237 -0
  23. data/sorbet/rbi/gems/netrc@0.11.0.rbi +158 -0
  24. data/sorbet/rbi/gems/parallel@1.23.0.rbi +273 -0
  25. data/sorbet/rbi/gems/parser@3.2.2.3.rbi +7253 -0
  26. data/sorbet/rbi/gems/prettier_print@1.2.1.rbi +951 -0
  27. data/sorbet/rbi/gems/psych@5.1.0.rbi +1760 -0
  28. data/sorbet/rbi/gems/racc@1.7.1.rbi +161 -0
  29. data/sorbet/rbi/gems/rainbow@3.1.1.rbi +402 -0
  30. data/sorbet/rbi/gems/rake@13.0.6.rbi +3024 -0
  31. data/sorbet/rbi/gems/rbi@0.0.17.rbi +2972 -0
  32. data/sorbet/rbi/gems/regexp_parser@2.8.1.rbi +3749 -0
  33. data/sorbet/rbi/gems/reline@0.3.8.rbi +2260 -0
  34. data/sorbet/rbi/gems/rexml@3.2.6.rbi +4781 -0
  35. data/sorbet/rbi/gems/rspec-core@3.12.2.rbi +10805 -0
  36. data/sorbet/rbi/gems/rspec-expectations@3.12.3.rbi +8100 -0
  37. data/sorbet/rbi/gems/rspec-mocks@3.12.5.rbi +5305 -0
  38. data/sorbet/rbi/gems/rspec-support@3.12.0.rbi +1611 -0
  39. data/sorbet/rbi/gems/rspec@3.12.0.rbi +82 -0
  40. data/sorbet/rbi/gems/rubocop-ast@1.29.0.rbi +6985 -0
  41. data/sorbet/rbi/gems/rubocop@1.56.2.rbi +56538 -0
  42. data/sorbet/rbi/gems/ruby-lsp@0.10.1.rbi +2903 -0
  43. data/sorbet/rbi/gems/ruby-progressbar@1.13.0.rbi +1317 -0
  44. data/sorbet/rbi/gems/spoom@1.2.3.rbi +3203 -0
  45. data/sorbet/rbi/gems/stringio@3.0.8.rbi +8 -0
  46. data/sorbet/rbi/gems/syntax_tree@6.1.1.rbi +22855 -0
  47. data/sorbet/rbi/gems/tapioca@0.11.8.rbi +3349 -0
  48. data/sorbet/rbi/gems/thor@1.2.2.rbi +3965 -0
  49. data/sorbet/rbi/gems/unicode-display_width@2.4.2.rbi +65 -0
  50. data/sorbet/rbi/gems/unparser@0.6.8.rbi +4525 -0
  51. data/sorbet/rbi/gems/yard-sorbet@0.8.1.rbi +428 -0
  52. data/sorbet/rbi/gems/yard@0.9.34.rbi +18219 -0
  53. data/sorbet/rbi/gems/yarp@0.11.0.rbi +15141 -0
  54. data/sorbet/rbi/shims/uri.rbi +14 -0
  55. data/sorbet/tapioca/config.yml +13 -0
  56. data/sorbet/tapioca/require.rb +8 -0
  57. metadata +115 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c36d67cb9d922ed7bcbd2e485bcac49fa2ea74aa460d7161bc224f55e3cecb00
4
+ data.tar.gz: 48925c65752d53395dd31dd8b335ea5b62eb5182fffb4202384ddc05a609ff9a
5
+ SHA512:
6
+ metadata.gz: f7b82553a837b8ea44a62a85c387e1f3c3b770fd9c239328a989aaf66a15496391338859c657b51b4403320f89b55e14ddc555d798f31fbab4395c137d5341d0
7
+ data.tar.gz: 1c400c09903e197e5b0a727359a6f9d35e7b5c03f18c5ea6261647dbf63e760bcdf70e106fe726617712bf7ffeae3dc79dfa7db6ec5ff390c0d6aa1c0cf6e5d2
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,39 @@
1
+ inherit_gem:
2
+ rubocop-shopify: rubocop.yml
3
+
4
+ require:
5
+ - rubocop-sorbet
6
+ - rubocop-rake
7
+
8
+ AllCops:
9
+ NewCops: disable
10
+ SuggestExtensions: false
11
+ TargetRubyVersion: 3.0
12
+
13
+ Naming/FileName:
14
+ Exclude:
15
+ - "lib/ruby-lsp-rspec.rb"
16
+
17
+ Sorbet/FalseSigil:
18
+ Enabled: false
19
+
20
+ Sorbet/TrueSigil:
21
+ Enabled: true
22
+ Exclude:
23
+ - "**/*.rake"
24
+ - "lib/**/*.rb"
25
+ - "spec/**/*.rb"
26
+
27
+ Sorbet/StrictSigil:
28
+ Enabled: true
29
+ Include:
30
+ - "lib/**/*.rb"
31
+ Exclude:
32
+ - "**/*.rake"
33
+ - "spec/**/*.rb"
34
+
35
+ Style/StderrPuts:
36
+ Enabled: true
37
+
38
+ Style/MethodCallWithArgsParentheses:
39
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-09-10
4
+
5
+ - Initial release
@@ -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,45 @@
1
+ # Ruby LSP RSpec
2
+
3
+ Ruby LSP RSpec is a [Ruby LSP](https://github.com/Shopify/ruby-lsp) extension for displaying code-lenses for RSpec tests.
4
+
5
+ ![Screenshot of the code lenses](/misc/example.png)
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-rspec"
15
+ end
16
+ ```
17
+
18
+ After running `bundle install`, restart Ruby LSP and you should start seeing code-lenses in your RSpec test files.
19
+
20
+ ## Usages (with VS Code)
21
+
22
+ 1. When clicking `Run`, the test(s) will be executed via the Test Explorer.
23
+ - However, deeply nested tests may not be displayed correctly at the moment.
24
+ 2. When clicking `Run In Terminal`, a test command will be generated in the terminal.
25
+ 3. When clicking `Debug`, the test(s) will be executed with VS Code debugger enabled (requires the [`debug`](https://github.com/ruby/debug) gem).
26
+ - [Learn how to set breakpoints in VS Code](https://code.visualstudio.com/docs/editor/debugging#_breakpoints).
27
+
28
+
29
+ ## Development
30
+
31
+ 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.
32
+
33
+ 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).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/st0012/ruby-lsp-rspec. 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/st0012/ruby-lsp-rspec/blob/main/CODE_OF_CONDUCT.md).
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
42
+
43
+ ## Code of Conduct
44
+
45
+ Everyone interacting in the Ruby::Lsp::Rspec project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/st0012/ruby-lsp-rspec/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: [:spec, :rubocop]
@@ -0,0 +1,11 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "sorbet-runtime"
5
+ require "ruby_lsp_rspec/version"
6
+ require "ruby_lsp/ruby_lsp_rspec/extension"
7
+
8
+ module RubyLsp
9
+ module RSpec
10
+ end
11
+ end
@@ -0,0 +1,146 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module RubyLsp
5
+ module RSpec
6
+ class CodeLens < ::RubyLsp::Listener
7
+ extend T::Sig
8
+ extend T::Generic
9
+
10
+ include ::RubyLsp::Requests::Support::Common
11
+
12
+ ResponseType = type_member { { fixed: T::Array[::RubyLsp::Interface::CodeLens] } }
13
+ BASE_COMMAND = T.let((File.exist?("Gemfile.lock") ? "bundle exec rspec" : "rspec"), String)
14
+
15
+ sig { override.returns(ResponseType) }
16
+ attr_reader :_response
17
+
18
+ sig { params(uri: URI::Generic, emitter: EventEmitter, message_queue: Thread::Queue).void }
19
+ def initialize(uri, emitter, message_queue)
20
+ @_response = T.let([], ResponseType)
21
+ @path = T.let(uri.to_standardized_path, T.nilable(String))
22
+ emitter.register(self, :on_command, :on_command_call, :on_call)
23
+
24
+ super(emitter, message_queue)
25
+ end
26
+
27
+ sig { params(node: SyntaxTree::CallNode).void }
28
+ def on_call(node)
29
+ add_group_code_lens(node)
30
+ end
31
+
32
+ sig { params(node: SyntaxTree::CommandCall).void }
33
+ def on_command_call(node)
34
+ add_group_code_lens(node)
35
+ end
36
+
37
+ sig { params(node: SyntaxTree::Command).void }
38
+ def on_command(node)
39
+ message_value = node.message.value
40
+ if message_value == "it"
41
+ argument = node.arguments.parts.first
42
+
43
+ name = case argument
44
+ when SyntaxTree::StringLiteral
45
+ argument.parts.first.value
46
+ when SyntaxTree::VarRef
47
+ argument.value.value
48
+ end
49
+
50
+ add_test_code_lens(node, name: name, kind: :example)
51
+ elsif message_value == "describe" || message_value == "context"
52
+ add_group_code_lens(node)
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ sig do
59
+ params(node: T.any(
60
+ SyntaxTree::StringLiteral,
61
+ SyntaxTree::ConstPathRef,
62
+ SyntaxTree::ConstRef,
63
+ SyntaxTree::TopConstRef,
64
+ SyntaxTree::VarRef,
65
+ )).returns(T.nilable(String))
66
+ end
67
+ def get_group_name(node)
68
+ case node
69
+ when SyntaxTree::StringLiteral
70
+ node.parts.first.value
71
+ when SyntaxTree::ConstPathRef, SyntaxTree::ConstRef, SyntaxTree::TopConstRef
72
+ full_constant_name(node)
73
+ when SyntaxTree::VarRef
74
+ node.value.value
75
+ end
76
+ end
77
+
78
+ sig { params(node: T.any(SyntaxTree::CallNode, SyntaxTree::CommandCall, SyntaxTree::Command)).void }
79
+ def add_group_code_lens(node)
80
+ return unless node.message.value == "describe" || node.message.value == "context"
81
+
82
+ case node
83
+ when SyntaxTree::CommandCall, SyntaxTree::CallNode
84
+ return if node.receiver && node.receiver.value.value != "RSpec"
85
+ end
86
+
87
+ argument = case node
88
+ when SyntaxTree::CallNode
89
+ node.arguments.arguments.parts.first
90
+ when SyntaxTree::CommandCall, SyntaxTree::Command
91
+ node.arguments.parts.first
92
+ end
93
+
94
+ name = get_group_name(argument)
95
+
96
+ return unless name
97
+
98
+ add_test_code_lens(node, name: name, kind: :group)
99
+ end
100
+
101
+ sig { params(node: SyntaxTree::Node, name: String, kind: Symbol).void }
102
+ def add_test_code_lens(node, name:, kind:)
103
+ return unless @path
104
+
105
+ line_number = node.location.start_line
106
+ command = "#{BASE_COMMAND} #{@path}:#{line_number}"
107
+
108
+ arguments = [
109
+ @path,
110
+ name,
111
+ command,
112
+ {
113
+ start_line: node.location.start_line - 1,
114
+ start_column: node.location.start_column,
115
+ end_line: node.location.end_line - 1,
116
+ end_column: node.location.end_column,
117
+ },
118
+ ]
119
+
120
+ @_response << create_code_lens(
121
+ node,
122
+ title: "Run",
123
+ command_name: "rubyLsp.runTest",
124
+ arguments: arguments,
125
+ data: { type: "test", kind: kind },
126
+ )
127
+
128
+ @_response << create_code_lens(
129
+ node,
130
+ title: "Run In Terminal",
131
+ command_name: "rubyLsp.runTestInTerminal",
132
+ arguments: arguments,
133
+ data: { type: "test_in_terminal", kind: kind },
134
+ )
135
+
136
+ @_response << create_code_lens(
137
+ node,
138
+ title: "Debug",
139
+ command_name: "rubyLsp.debugTest",
140
+ arguments: arguments,
141
+ data: { type: "debug", kind: kind },
142
+ )
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,38 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "ruby_lsp/extension"
5
+ require "ruby_lsp/internal"
6
+
7
+ require_relative "code_lens"
8
+
9
+ module RubyLsp
10
+ module RSpec
11
+ class Extension < ::RubyLsp::Extension
12
+ extend T::Sig
13
+
14
+ sig { override.void }
15
+ def activate; end
16
+
17
+ sig { override.void }
18
+ def deactivate; end
19
+
20
+ # Creates a new CodeLens listener. This method is invoked on every CodeLens request
21
+ sig do
22
+ override.params(
23
+ uri: URI::Generic,
24
+ emitter: EventEmitter,
25
+ message_queue: Thread::Queue,
26
+ ).returns(T.nilable(Listener[T::Array[Interface::CodeLens]]))
27
+ end
28
+ def create_code_lens_listener(uri, emitter, message_queue)
29
+ CodeLens.new(uri, emitter, message_queue)
30
+ end
31
+
32
+ sig { override.returns(String) }
33
+ def name
34
+ "Ruby LSP RSpec"
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,8 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module RubyLsp
5
+ module RSpec
6
+ VERSION = "0.1.0"
7
+ end
8
+ end
data/misc/example.png ADDED
Binary file
data/sorbet/config ADDED
@@ -0,0 +1,4 @@
1
+ --dir
2
+ .
3
+ --ignore=tmp/
4
+ --ignore=vendor/