solargraph-rspec 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.
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Credits: This file is a copy of the file from the solargraph-rspec gem
4
+
5
+ # rubocop:disable Naming/MethodParameterName
6
+ module Solargraph
7
+ module Rspec
8
+ # Utility methods for building pins and references.
9
+ module Util
10
+ def self.build_public_method(
11
+ ns,
12
+ name,
13
+ types: nil,
14
+ location: nil,
15
+ comments: [],
16
+ attribute: false,
17
+ scope: :instance
18
+ )
19
+ opts = {
20
+ name: name,
21
+ location: location,
22
+ closure: ns,
23
+ scope: scope,
24
+ attribute: attribute,
25
+ comments: []
26
+ }
27
+
28
+ comments << "@return [#{types.join(",")}]" if types
29
+
30
+ opts[:comments] = comments.join("\n")
31
+
32
+ Solargraph::Pin::Method.new(**opts)
33
+ end
34
+
35
+ def self.build_module_include(ns, module_name, location)
36
+ Solargraph::Pin::Reference::Include.new(
37
+ closure: ns,
38
+ name: module_name,
39
+ location: location
40
+ )
41
+ end
42
+
43
+ def self.build_module_extend(ns, module_name, location)
44
+ Solargraph::Pin::Reference::Extend.new(
45
+ closure: ns,
46
+ name: module_name,
47
+ location: location
48
+ )
49
+ end
50
+
51
+ def self.dummy_location(path)
52
+ Solargraph::Location.new(
53
+ File.expand_path(path),
54
+ Solargraph::Range.from_to(0, 0, 0, 0)
55
+ )
56
+ end
57
+
58
+ # @param ast [Parser::AST::Node]
59
+ def self.build_location(ast, path)
60
+ Solargraph::Location.new(
61
+ File.expand_path(path),
62
+ Solargraph::Range.from_to(
63
+ ast.location.first_line,
64
+ ast.location.column,
65
+ ast.location.last_line,
66
+ ast.location.last_column
67
+ )
68
+ )
69
+ end
70
+
71
+ def self.method_return(path, type)
72
+ Solargraph::Pin::Reference::Override.method_return(path, type)
73
+ end
74
+ end
75
+ end
76
+ end
77
+ # rubocop:enable Naming/MethodParameterName
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Rspec
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Credits: This file is a copy of the original file from the solargraph-rails gem.
4
+
5
+ module Solargraph
6
+ module Rspec
7
+ class Walker
8
+ class Hook
9
+ attr_reader :node_type
10
+
11
+ # @param node_type [Symbol]
12
+ # @param args [Array]
13
+ # @param block [Proc]
14
+ def initialize(node_type, args, &block)
15
+ @node_type = node_type
16
+ @args = args
17
+ @proc = Proc.new(&block)
18
+ end
19
+
20
+ # @param node [Parser::AST::Node]
21
+ # @return [void]
22
+ def visit(node)
23
+ return unless matches?(node)
24
+
25
+ if @proc.arity == 1
26
+ @proc.call(node)
27
+ elsif @proc.arity == 2
28
+ walker = Walker.new(node)
29
+ @proc.call(node, walker)
30
+ walker.walk
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ # @param node [Parser::AST::Node]
37
+ # @return [Boolean]
38
+ def matches?(node)
39
+ return false unless node.type == node_type
40
+ return false unless node.children
41
+ return true if @args.empty?
42
+
43
+ a_child_matches = node.children.first.is_a?(::Parser::AST::Node) && node.children.any? do |child|
44
+ child.is_a?(::Parser::AST::Node) &&
45
+ match_children(child.children, @args[1..])
46
+ end
47
+
48
+ return true if a_child_matches
49
+
50
+ match_children(node.children)
51
+ end
52
+
53
+ # @param children [Array<Parser::AST::Node>]
54
+ def match_children(children, args = @args)
55
+ args.each_with_index.all? do |arg, i|
56
+ if arg == :any
57
+ true
58
+ elsif children[i].is_a?(::Parser::AST::Node) && arg.is_a?(Symbol)
59
+ children[i].type == arg
60
+ else
61
+ children[i] == arg
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ # https://github.com/castwide/solargraph/issues/522
68
+ def self.normalize_ast(source)
69
+ ast = source.node
70
+
71
+ if ast.is_a?(::Parser::AST::Node)
72
+ ast
73
+ else
74
+ NodeParser.parse_with_comments(source.code, source.filename)
75
+ end
76
+ end
77
+
78
+ # @param source [Solargraph::Source]
79
+ def self.from_source(source)
80
+ new(*normalize_ast(source))
81
+ end
82
+
83
+ # @return ast [Parser::AST::Node]
84
+ attr_reader :ast
85
+ # @return comments [Hash]
86
+ attr_reader :comments
87
+
88
+ # @param ast [Parser::AST::Node]
89
+ # @param comments [Hash]
90
+ def initialize(ast, comments = {})
91
+ @comments = comments
92
+ @ast = ast
93
+ @hooks = Hash.new([])
94
+ end
95
+
96
+ # @param node_type [Symbol]
97
+ # @param args [Array]
98
+ # @param block [Proc]
99
+ def on(node_type, args = [], &block)
100
+ @hooks[node_type] << Hook.new(node_type, args, &block)
101
+ end
102
+
103
+ # @return [void]
104
+ def walk
105
+ @ast.is_a?(Array) ? @ast.each { |node| traverse(node) } : traverse(@ast)
106
+ end
107
+
108
+ private
109
+
110
+ # @param node [Parser::AST::Node]
111
+ def traverse(node)
112
+ return unless node.is_a?(::Parser::AST::Node)
113
+
114
+ @hooks[node.type].each { |hook| hook.visit(node) }
115
+
116
+ node.children.each { |child| traverse(child) }
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,19 @@
1
+ # rubocop:disable Naming/FileName
2
+ # frozen_string_literal: true
3
+
4
+ require 'solargraph'
5
+ require 'active_support'
6
+
7
+ require_relative 'solargraph/rspec/version'
8
+ require_relative 'solargraph/rspec/convention'
9
+
10
+ module Solargraph
11
+ module Rspec
12
+ class NodeParser
13
+ extend Solargraph::Parser::Legacy::ClassMethods
14
+ end
15
+ end
16
+ end
17
+
18
+ Solargraph::Convention.register Solargraph::Rspec::Convention
19
+ # rubocop:enable Naming/FileName
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'solargraph-rspec'
@@ -0,0 +1,6 @@
1
+ module Solargraph
2
+ module Rspec
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/solargraph/rspec/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'solargraph-rspec'
7
+ spec.version = Solargraph::Rspec::VERSION
8
+ spec.authors = ['Lekë Mula']
9
+ spec.email = ['leke.mula@gmail.com']
10
+
11
+ spec.summary = 'Solargraph plugin supporting RSpec code completion'
12
+ spec.description = 'RSpec is a testing tool of choice for many Ruby developers. ' \
13
+ 'This plugin provides code completion and other features for RSpec files in Solargraph.'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 2.6.0'
16
+
17
+ spec.metadata['source_code_uri'] = 'https://github.com/lekemula/solargraph-rspec'
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(__dir__) do
22
+ `git ls-files -z`.split("\x0").reject do |f|
23
+ (File.expand_path(f) == __FILE__) ||
24
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
25
+ end
26
+ end
27
+ spec.bindir = 'exe'
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ['lib']
30
+
31
+ spec.add_runtime_dependency 'activesupport', '~> 6.0'
32
+ spec.add_runtime_dependency 'solargraph', '~> 0.49', '>= 0.49.0'
33
+
34
+ # For more information and examples about making a new gem, check out our
35
+ # guide at: https://bundler.io/guides/creating_gem.html
36
+ spec.metadata['rubygems_mfa_required'] = 'true'
37
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: solargraph-rspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Lekë Mula
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-05-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '6.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: solargraph
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.49.0
34
+ - - "~>"
35
+ - !ruby/object:Gem::Version
36
+ version: '0.49'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.49.0
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.49'
47
+ description: RSpec is a testing tool of choice for many Ruby developers. This plugin
48
+ provides code completion and other features for RSpec files in Solargraph.
49
+ email:
50
+ - leke.mula@gmail.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - ".rspec"
56
+ - ".rubocop.yml"
57
+ - CHANGELOG.md
58
+ - CODE_OF_CONDUCT.md
59
+ - LICENSE.txt
60
+ - README.md
61
+ - Rakefile
62
+ - lib/solargraph-rspec.rb
63
+ - lib/solargraph/rspec/config.rb
64
+ - lib/solargraph/rspec/convention.rb
65
+ - lib/solargraph/rspec/correctors/base.rb
66
+ - lib/solargraph/rspec/correctors/context_block_methods_corrector.rb
67
+ - lib/solargraph/rspec/correctors/context_block_namespace_corrector.rb
68
+ - lib/solargraph/rspec/correctors/described_class_corrector.rb
69
+ - lib/solargraph/rspec/correctors/dsl_methods_corrector.rb
70
+ - lib/solargraph/rspec/correctors/example_and_hook_blocks_binding_corrector.rb
71
+ - lib/solargraph/rspec/correctors/implicit_subject_method_corrector.rb
72
+ - lib/solargraph/rspec/correctors/let_methods_corrector.rb
73
+ - lib/solargraph/rspec/correctors/subject_method_corrector.rb
74
+ - lib/solargraph/rspec/correctors/walker_base.rb
75
+ - lib/solargraph/rspec/spec_walker.rb
76
+ - lib/solargraph/rspec/util.rb
77
+ - lib/solargraph/rspec/version.rb
78
+ - lib/solargraph/rspec/walker.rb
79
+ - lib/solargraph_rspec.rb
80
+ - sig/solargraph/rspec.rbs
81
+ - solargraph-rspec.gemspec
82
+ homepage:
83
+ licenses:
84
+ - MIT
85
+ metadata:
86
+ source_code_uri: https://github.com/lekemula/solargraph-rspec
87
+ rubygems_mfa_required: 'true'
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 2.6.0
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubygems_version: 3.0.9
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Solargraph plugin supporting RSpec code completion
107
+ test_files: []