solargraph-rails 0.2.0 → 0.2.2.pre.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df10b3b2f00a486c79433fbb7038ffbee966d3420022b3789a5fd00965769524
4
- data.tar.gz: b1fb1d828e84a1f74d0f4ab644050fef127e3a019be3f5ef3592d0cb9893b0ac
3
+ metadata.gz: 7b1512086d26a2b7a883013b14d919163ea9f3155b67f6cf87ad956c46319857
4
+ data.tar.gz: f88b8cd47da267a95cb418d339e37ad0e25b975e5952eb19d7b6fb9c1d353d42
5
5
  SHA512:
6
- metadata.gz: 31be19170418090a2f09e207b9c7a3c421ce74c17138730ce1670bddefbeffdbe0775158598aefd1630346a43beba6d5f4128705a236cf89765845b7b9170976
7
- data.tar.gz: 2bfd1f0f082d1f52686ec6342ffc30fe84f374a5fe52dc5e8cad3a5995b28e7f0a9f99bf854a06b92e8926cbd5a4d3f3f5adbe498e95f726f49ee28fe74ac63d
6
+ metadata.gz: c09211c20651d6011f50b1aa6bc3b0c1ab961e868d9bfebdf25eb1c4ac2d0972c2735cddc5bbba8294726e8e63a4b3ad1c4c79db0b9c8d5d7be4aeb0c2dd5caf
7
+ data.tar.gz: 3be48e28a9eba627f15ff1543d933673f89abcf7b2ac268f1f69ab8414a21dac0cc5e6ae1b518148f165849cec1a0b224d8fa52b1dc94e50585be044ca282a32
data/CHANGELOG.md ADDED
@@ -0,0 +1,24 @@
1
+ # solargraph-rails changelog
2
+
3
+ ## Changes
4
+
5
+ ### v0.2.2.pre.4
6
+ * Loosen the dependency requirements
7
+
8
+ ### v0.2.2.pre.3
9
+ * Update to solargraph 0.42.3
10
+ * Determine return type of association using class_name argument
11
+
12
+ ### v0.2.2.pre.2
13
+
14
+ * Simplistic support for associations
15
+ * Added dependency on ActiveSupport 6.1 for helpful String methods like `.camelize` and `.singularize`
16
+
17
+ ### v0.2.1
18
+
19
+ * Update Solargraph to 0.41
20
+
21
+ ### v0.2.0
22
+ First released version with no need to use --pre!
23
+
24
+ * Updated dependencies with security warnings
data/Gemfile.lock CHANGED
@@ -1,28 +1,39 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- solargraph-rails (0.2.0.pre)
5
- solargraph (~> 0.40.0)
4
+ solargraph-rails (0.2.2.pre.4)
5
+ activesupport
6
+ solargraph (>= 0.41.1)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
11
+ activesupport (6.1.4)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ zeitwerk (~> 2.3)
10
17
  ast (2.4.2)
11
- backport (1.1.2)
18
+ backport (1.2.0)
12
19
  benchmark (0.1.1)
13
20
  bundler-audit (0.8.0)
14
21
  bundler (>= 1.2.0, < 3)
15
22
  thor (~> 1.0)
16
23
  byebug (11.1.3)
24
+ concurrent-ruby (1.1.9)
17
25
  diff-lcs (1.4.4)
18
26
  e2mmap (0.1.0)
27
+ i18n (1.8.10)
28
+ concurrent-ruby (~> 1.0)
19
29
  jaro_winkler (1.5.4)
20
30
  kramdown (2.3.1)
21
31
  rexml
22
32
  kramdown-parser-gfm (1.1.0)
23
33
  kramdown (~> 2.0)
24
- mini_portile2 (2.5.1)
25
- nokogiri (1.11.6)
34
+ mini_portile2 (2.5.3)
35
+ minitest (5.14.4)
36
+ nokogiri (1.11.7)
26
37
  mini_portile2 (~> 2.5.0)
27
38
  racc (~> 1.4)
28
39
  parallel (1.20.1)
@@ -48,22 +59,23 @@ GEM
48
59
  diff-lcs (>= 1.2.0, < 2.0)
49
60
  rspec-support (~> 3.10.0)
50
61
  rspec-support (3.10.0)
51
- rubocop (1.15.0)
62
+ rubocop (1.17.0)
52
63
  parallel (~> 1.10)
53
64
  parser (>= 3.0.0.0)
54
65
  rainbow (>= 2.2.2, < 4.0)
55
66
  regexp_parser (>= 1.8, < 3.0)
56
67
  rexml
57
- rubocop-ast (>= 1.5.0, < 2.0)
68
+ rubocop-ast (>= 1.7.0, < 2.0)
58
69
  ruby-progressbar (~> 1.7)
59
70
  unicode-display_width (>= 1.4.0, < 3.0)
60
71
  rubocop-ast (1.7.0)
61
72
  parser (>= 3.0.1.1)
62
73
  ruby-progressbar (1.11.0)
63
- solargraph (0.40.4)
64
- backport (~> 1.1)
74
+ solargraph (0.42.3)
75
+ backport (~> 1.2)
65
76
  benchmark
66
77
  bundler (>= 1.17.2)
78
+ diff-lcs (~> 1.4)
67
79
  e2mmap
68
80
  jaro_winkler (~> 1.5)
69
81
  kramdown (~> 2.3)
@@ -76,8 +88,11 @@ GEM
76
88
  yard (~> 0.9, >= 0.9.24)
77
89
  thor (1.1.0)
78
90
  tilt (2.0.10)
91
+ tzinfo (2.0.4)
92
+ concurrent-ruby (~> 1.0)
79
93
  unicode-display_width (2.0.0)
80
94
  yard (0.9.26)
95
+ zeitwerk (2.4.2)
81
96
 
82
97
  PLATFORMS
83
98
  ruby
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Solargraph::Rails - Help solargraph with Rails
2
2
 
3
3
  ## Work in progress - here be dragons
4
- There are significant rough edges to this gem still. You won't be able to use it if you're not willing to install a gem using `--pre`. See `Installation` below for more info.
4
+ There are significant rough edges to this gem still.
5
5
 
6
6
  ## Models
7
7
  Given a typical Rails model like this:
@@ -51,8 +51,10 @@ Solargraph won't know about attributes that you add during a session. Restart yo
51
51
 
52
52
  For my setup with Emacs, that means running `M-x lsp-workspace-restart`, YMMV in other editors.
53
53
 
54
- ## Associations
55
- This is coming soon.
54
+ ## Associations (experimental)
55
+ There is very hacky and simplistic support for `belongs_to` and `has_many` macros, if you are willing to use `gem install solargraph-rails --pre`:
56
+
57
+ ![Experimental autocomplete and go to definition of associations](assets/solar_rails_associations.gif)
56
58
 
57
59
  ## Known issues
58
60
  This project is being used to write production code by the maintainer, but it is still WIP. Check out the issues tab and contribute if you are interested.
@@ -63,13 +65,15 @@ This project is being used to write production code by the maintainer, but it is
63
65
 
64
66
  Typically gems like these are not installed via the Gemfile, because most projects have more than one contributor and other contributors might have different setups for their editors in mind. Instead you need to use `gem install`.
65
67
 
66
- `gem install solargraph-rails --pre`
68
+ `gem install solargraph-rails`
67
69
 
68
70
  #### Alternative: using bundler
69
- If you do want to use bundler, add `gem 'solargraph-rails', '0.2.0.pre'`
71
+ If you do want to use bundler, add `gem 'solargraph-rails', '~> 0.2.0'`
70
72
 
71
73
  ### Add `solargraph-rails` to your `.solargraph.yml`
72
74
 
75
+ (if you don't have a `.solargraph.yml` in your project root, you can run `solargraph config` to add one)
76
+
73
77
  ```
74
78
  plugins:
75
79
  - solargraph-rails
Binary file
@@ -5,6 +5,10 @@ require 'solargraph/rails/version'
5
5
  require_relative 'solargraph/rails/pin_creator'
6
6
  require_relative 'solargraph/rails/ruby_parser'
7
7
  require_relative 'solargraph/rails/files_loader'
8
+ require_relative 'solargraph/rails/meta_source/association/belongs_to_matcher'
9
+ require_relative 'solargraph/rails/meta_source/association/has_many_matcher'
10
+ require_relative 'solargraph/rails/meta_source/association/has_one_matcher'
11
+ require_relative 'solargraph/rails/meta_source/association/has_and_belongs_to_many_matcher'
8
12
 
9
13
  module Solargraph
10
14
  module Rails
@@ -0,0 +1,24 @@
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
@@ -0,0 +1,24 @@
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
@@ -0,0 +1,24 @@
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
@@ -0,0 +1,24 @@
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,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_support/core_ext/string'
4
+
3
5
  module Solargraph
4
6
  module Rails
5
7
  class PinCreator
@@ -50,13 +52,32 @@ module Solargraph
50
52
  end
51
53
  end
52
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
+
53
74
  parser.parse
54
75
 
55
76
  Solargraph::Logging.logger.info "Adding #{model_attrs.count} attributes as pins"
56
77
  model_attrs.map do |attr|
57
78
  Solargraph::Pin::Method.new(
58
79
  name: attr[:name],
59
- comments: "@return [#{type_translation[attr[:type]]}]",
80
+ comments: "@return [#{type_translation.fetch(attr[:type], attr[:type])}]",
60
81
  location: attr[:location],
61
82
  closure: Solargraph::Pin::Namespace.new(name: module_names.join('::') + "::#{model_name}"),
62
83
  scope: :instance,
@@ -65,6 +86,14 @@ module Solargraph
65
86
  end
66
87
  end
67
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
68
97
  def col_with_type(line)
69
98
  line
70
99
  .gsub(/[\(\),:\d]/, '')
@@ -6,6 +6,7 @@ module Solargraph
6
6
  def initialize(file_contents: '')
7
7
  @lines = file_contents.lines
8
8
  @comment_handlers = []
9
+ @non_comment_handlers = []
9
10
  @class_handlers = []
10
11
  @module_handlers = []
11
12
  end
@@ -22,6 +23,10 @@ module Solargraph
22
23
  @module_handlers << blk
23
24
  end
24
25
 
26
+ def on_ruby_line(&blk)
27
+ @non_comment_handlers << blk
28
+ end
29
+
25
30
  def parse
26
31
  @lines
27
32
  .map(&:rstrip)
@@ -32,6 +37,8 @@ module Solargraph
32
37
  if is_comment?(line)
33
38
  comment_content = line.gsub(/#\s*/, '')
34
39
  @comment_handlers.each { |handler| handler.call(comment_content) }
40
+ else
41
+ @non_comment_handlers.each { |handler| handler.call(line) }
35
42
  end
36
43
 
37
44
  if is_class?(line)
@@ -1,5 +1,5 @@
1
1
  module Solargraph
2
2
  module Rails
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.2.pre.4'
4
4
  end
5
5
  end
@@ -25,5 +25,6 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "rake", "~> 12.3.3"
26
26
  spec.add_development_dependency "rspec", "~> 3.0"
27
27
 
28
- spec.add_runtime_dependency "solargraph", "~> 0.40.0"
28
+ spec.add_runtime_dependency "solargraph", ">= 0.41.1"
29
+ spec.add_runtime_dependency "activesupport"
29
30
  end
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.2.0
4
+ version: 0.2.2.pre.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fritz Meissner
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-28 00:00:00.000000000 Z
11
+ date: 2021-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,16 +56,30 @@ 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.40.0
61
+ version: 0.41.1
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.40.0
68
+ version: 0.41.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: Add reflection on ActiveModel dynamic attributes that will be created
70
84
  at runtime
71
85
  email:
@@ -77,18 +91,24 @@ files:
77
91
  - ".gitignore"
78
92
  - ".rspec"
79
93
  - ".travis.yml"
94
+ - CHANGELOG.md
80
95
  - Gemfile
81
96
  - Gemfile.lock
82
97
  - LICENSE.txt
83
98
  - README.md
84
99
  - Rakefile
85
100
  - assets/peek.png
101
+ - assets/solar_rails_associations.gif
86
102
  - assets/solar_rails_autocomplete.gif
87
103
  - assets/solar_rails_goto.gif
88
104
  - bin/console
89
105
  - bin/setup
90
106
  - lib/solargraph-rails.rb
91
107
  - lib/solargraph/rails/files_loader.rb
108
+ - lib/solargraph/rails/meta_source/association/belongs_to_matcher.rb
109
+ - lib/solargraph/rails/meta_source/association/has_and_belongs_to_many_matcher.rb
110
+ - lib/solargraph/rails/meta_source/association/has_many_matcher.rb
111
+ - lib/solargraph/rails/meta_source/association/has_one_matcher.rb
92
112
  - lib/solargraph/rails/pin_creator.rb
93
113
  - lib/solargraph/rails/ruby_parser.rb
94
114
  - lib/solargraph/rails/version.rb
@@ -108,9 +128,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
128
  version: '0'
109
129
  required_rubygems_version: !ruby/object:Gem::Requirement
110
130
  requirements:
111
- - - ">="
131
+ - - ">"
112
132
  - !ruby/object:Gem::Version
113
- version: '0'
133
+ version: 1.3.1
114
134
  requirements: []
115
135
  rubygems_version: 3.2.3
116
136
  signing_key: