solargraph-rails 0.3.1 → 1.0.0.pre.1

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.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solargraph-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 1.0.0.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fritz Meissner
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-04 00:00:00.000000000 Z
11
+ date: 2022-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.2.10
19
+ version: '2.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.2.10
26
+ version: '2.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: solargraph
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.41.1
61
+ version: 0.44.2
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.41.1
68
+ version: 0.44.2
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activesupport
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -88,10 +88,14 @@ executables: []
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
92
+ - ".github/workflows/ruby.yml"
91
93
  - ".gitignore"
92
94
  - ".rspec"
95
+ - ".solargraph.yml"
93
96
  - ".travis.yml"
94
97
  - CHANGELOG.md
98
+ - DEVELOPMENT.md
95
99
  - Gemfile
96
100
  - LICENSE.txt
97
101
  - README.md
@@ -103,14 +107,21 @@ files:
103
107
  - bin/console
104
108
  - bin/setup
105
109
  - lib/solargraph-rails.rb
106
- - lib/solargraph/rails/files_loader.rb
107
- - lib/solargraph/rails/meta_source/association/belongs_to_matcher.rb
108
- - lib/solargraph/rails/meta_source/association/has_and_belongs_to_many_matcher.rb
109
- - lib/solargraph/rails/meta_source/association/has_many_matcher.rb
110
- - lib/solargraph/rails/meta_source/association/has_one_matcher.rb
111
- - lib/solargraph/rails/pin_creator.rb
112
- - lib/solargraph/rails/ruby_parser.rb
110
+ - lib/solargraph/rails/annotate.rb
111
+ - lib/solargraph/rails/annotations.rb
112
+ - lib/solargraph/rails/autoload.rb
113
+ - lib/solargraph/rails/debug.rb
114
+ - lib/solargraph/rails/delegate.rb
115
+ - lib/solargraph/rails/devise.rb
116
+ - lib/solargraph/rails/model.rb
117
+ - lib/solargraph/rails/rails_api.rb
118
+ - lib/solargraph/rails/schema.rb
119
+ - lib/solargraph/rails/storage.rb
120
+ - lib/solargraph/rails/types.yml
121
+ - lib/solargraph/rails/util.rb
113
122
  - lib/solargraph/rails/version.rb
123
+ - lib/solargraph/rails/walker.rb
124
+ - script/generate_definitions.rb
114
125
  - solargraph-rails.gemspec
115
126
  homepage: https://github.com/iftheshoefritz/solargraph-rails
116
127
  licenses:
@@ -127,9 +138,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
138
  version: '0'
128
139
  required_rubygems_version: !ruby/object:Gem::Requirement
129
140
  requirements:
130
- - - ">="
141
+ - - ">"
131
142
  - !ruby/object:Gem::Version
132
- version: '0'
143
+ version: 1.3.1
133
144
  requirements: []
134
145
  rubygems_version: 3.2.3
135
146
  signing_key:
@@ -1,16 +0,0 @@
1
- module Solargraph
2
- module Rails
3
- class FilesLoader
4
- def initialize(file_names)
5
- @file_names = file_names
6
- end
7
-
8
- def each(&blk)
9
- @file_names.each do |file_name|
10
- Solargraph::Logging.logger.info "loading from #{file_name}"
11
- blk.call(file_name, File.read(file_name))
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,24 +0,0 @@
1
- module MetaSource
2
- module Association
3
- class BelongsToMatcher
4
- attr_reader :name
5
-
6
- def match?(line)
7
- line =~ /belongs_to\s+:([a-z_]*)/
8
- @name = Regexp.last_match(1)
9
-
10
- return unless @name
11
-
12
- return @name unless line =~ /class_name:\s+["']([A-Za-z0-9]+)/
13
-
14
- @type = Regexp.last_match(1)
15
-
16
- @name
17
- end
18
-
19
- def type
20
- @type || name&.camelize
21
- end
22
- end
23
- end
24
- end
@@ -1,24 +0,0 @@
1
- module MetaSource
2
- module Association
3
- class HasAndBelongsToManyMatcher
4
- attr_reader :name
5
-
6
- def match?(line)
7
- line =~ /has_and_belongs_to_many\s+:([a-z_]*)/
8
- @name = Regexp.last_match(1)
9
-
10
- return unless @name
11
-
12
- if line =~ /class_name:\s+["']([A-Za-z0-9]+)/
13
- @type = Regexp.last_match(1)
14
- end
15
-
16
- @name
17
- end
18
-
19
- def type
20
- "ActiveRecord::Associations::CollectionProxy<#{@type || name.singularize.camelize}>"
21
- end
22
- end
23
- end
24
- end
@@ -1,24 +0,0 @@
1
- module MetaSource
2
- module Association
3
- class HasManyMatcher
4
- attr_reader :name
5
-
6
- def match?(line)
7
- line =~ /has_many\s+:([a-z_]*)/
8
- @name = Regexp.last_match(1)
9
-
10
- return unless @name
11
-
12
- if line =~ /class_name:\s+["']([A-Za-z0-9]+)/
13
- @type = Regexp.last_match(1)
14
- end
15
-
16
- @name
17
- end
18
-
19
- def type
20
- "ActiveRecord::Associations::CollectionProxy<#{@type || name.singularize.camelize}>"
21
- end
22
- end
23
- end
24
- end
@@ -1,24 +0,0 @@
1
- module MetaSource
2
- module Association
3
- class HasOneMatcher
4
- attr_reader :name
5
-
6
- def match?(line)
7
- line =~ /has_one\s+:([a-z_]*)/
8
- @name = Regexp.last_match(1)
9
-
10
- return unless @name
11
-
12
- if line =~ /class_name:\s+["']([A-Za-z0-9]+)/
13
- @type = Regexp.last_match(1)
14
- end
15
-
16
- @name
17
- end
18
-
19
- def type
20
- @type || name.camelize
21
- end
22
- end
23
- end
24
- end
@@ -1,118 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'active_support/core_ext/string/inflections'
4
-
5
- module Solargraph
6
- module Rails
7
- class PinCreator
8
- attr_reader :contents, :path
9
-
10
- def initialize(path, contents)
11
- @path = path
12
- @contents = contents
13
- end
14
-
15
- def create_pins
16
- model_attrs = []
17
- model_name = nil
18
- module_names = []
19
- parser = RubyParser.new(file_contents: contents)
20
-
21
- parser.on_comment do |comment|
22
- Solargraph::Logging.logger.info "found comment #{comment}"
23
- col_name, col_type = col_with_type(comment)
24
- if type_translation.keys.include?(col_type)
25
- loc = Solargraph::Location.new(
26
- path,
27
- Solargraph::Range.from_to(
28
- parser.current_line_number,
29
- 0,
30
- parser.current_line_number,
31
- parser.current_line_length - 1
32
- )
33
- )
34
- model_attrs << { name: col_name, type: col_type, location: loc }
35
- else
36
- Solargraph::Logging.logger.info 'could not find annotation in comment'
37
- end
38
- end
39
-
40
- parser.on_module do |mod_name|
41
- Solargraph::Logging.logger.info "found module #{mod_name}"
42
- module_names << mod_name
43
- end
44
-
45
- parser.on_class do |klass, superklass|
46
- Solargraph::Logging.logger.info "found class: #{klass} < #{superklass}"
47
- if ['ActiveRecord::Base', 'ApplicationRecord'].include?(superklass)
48
- model_name = klass
49
- else
50
- Solargraph::Logging.logger.info "Unable to find ActiveRecord model from #{klass} #{superklass}"
51
- model_attrs = [] # don't include anything from this file
52
- end
53
- end
54
-
55
- parser.on_ruby_line do |line|
56
- matcher = ruby_matchers.find do |m|
57
- m.match?(line)
58
- end
59
-
60
- if matcher
61
- loc = Solargraph::Location.new(
62
- path,
63
- Solargraph::Range.from_to(
64
- parser.current_line_number,
65
- 0,
66
- parser.current_line_number,
67
- parser.current_line_length - 1
68
- )
69
- )
70
- model_attrs << { name: matcher.name, type: matcher.type, location: loc }
71
- end
72
- end
73
-
74
- parser.parse
75
-
76
- Solargraph::Logging.logger.info "Adding #{model_attrs.count} attributes as pins"
77
- model_attrs.map do |attr|
78
- Solargraph::Pin::Method.new(
79
- name: attr[:name],
80
- comments: "@return [#{type_translation.fetch(attr[:type], attr[:type])}]",
81
- location: attr[:location],
82
- closure: Solargraph::Pin::Namespace.new(name: module_names.join('::') + "::#{model_name}"),
83
- scope: :instance,
84
- attribute: true
85
- )
86
- end
87
- end
88
-
89
- def ruby_matchers
90
- [
91
- MetaSource::Association::BelongsToMatcher.new,
92
- MetaSource::Association::HasManyMatcher.new,
93
- MetaSource::Association::HasOneMatcher.new,
94
- MetaSource::Association::HasAndBelongsToManyMatcher.new
95
- ]
96
- end
97
- def col_with_type(line)
98
- line
99
- .gsub(/[\(\),:\d]/, '')
100
- .split
101
- .first(2)
102
- end
103
-
104
- def type_translation
105
- {
106
- 'decimal' => 'BigDecimal',
107
- 'integer' => 'Integer',
108
- 'date' => 'Date',
109
- 'datetime' => 'ActiveSupport::TimeWithZone',
110
- 'string' => 'String',
111
- 'boolean' => 'Boolean',
112
- 'float' => 'Float',
113
- 'text' => 'String'
114
- }
115
- end
116
- end
117
- end
118
- end
@@ -1,77 +0,0 @@
1
- module Solargraph
2
- module Rails
3
- class RubyParser
4
- attr_reader :current_line_number, :current_line_length
5
-
6
- def initialize(file_contents: '')
7
- @lines = file_contents.lines
8
- @comment_handlers = []
9
- @non_comment_handlers = []
10
- @class_handlers = []
11
- @module_handlers = []
12
- end
13
-
14
- def on_comment(&blk)
15
- @comment_handlers << blk
16
- end
17
-
18
- def on_class(&blk)
19
- @class_handlers << blk
20
- end
21
-
22
- def on_module(&blk)
23
- @module_handlers << blk
24
- end
25
-
26
- def on_ruby_line(&blk)
27
- @non_comment_handlers << blk
28
- end
29
-
30
- def parse
31
- @lines
32
- .map(&:rstrip)
33
- .each_with_index do |line, i|
34
- @current_line_number = i
35
- @current_line_length = line.length
36
-
37
- if is_comment?(line)
38
- comment_content = line.gsub(/#\s*/, '')
39
- @comment_handlers.each { |handler| handler.call(comment_content) }
40
- else
41
- @non_comment_handlers.each { |handler| handler.call(line) }
42
- end
43
-
44
- if is_class?(line)
45
- line.scan(/(?:(?<!<\s)(?:(\b\w+\b)\:\:))/).flatten.each do |inline_module_name|
46
- @module_handlers.each { | handler| handler.call(inline_module_name) }
47
- end
48
- line.match(/class\s+(?:\w*?(?:\:\:))*([A-Z]\w*)/)
49
- klass_name = $1
50
- line.match(/(?:<\s+)((?:[A-Z]\w*(?:\:\:)?)*)/)
51
- superklass_name = $1
52
- @class_handlers.each { |handler| handler.call(klass_name, superklass_name) }
53
- end
54
-
55
- if is_module?(line)
56
- module_name = line.match(/^\s*module\s*?([A-Z]\w+)/)[1]
57
- @module_handlers.each { |handler| handler.call(module_name) }
58
- end
59
- end
60
- end
61
-
62
- private
63
-
64
- def is_comment?(line)
65
- line =~ (/^\s*#/)
66
- end
67
-
68
- def is_class?(line)
69
- line =~ /^[^#]?.*?class\s+?[A-Z]/
70
- end
71
-
72
- def is_module?(line)
73
- line =~ (/^\s*module\s*?([A-Z]\w+)/)
74
- end
75
- end
76
- end
77
- end