solargraph-rails 0.2.2.pre.1 → 0.2.2.pre.2

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: 42b094ca4d96b63dd47297f752e821904875c11eda1f2a367ab84da2862b5ff6
4
- data.tar.gz: 60200f07c8ff06a580cd4f44aba81fe2313c12364bf23b9637c8a874b2769c2e
3
+ metadata.gz: 7550cc551e9ee58ed7e88b5cac988326729410700f4833735c63e25423def03e
4
+ data.tar.gz: 50b16e19c7843b9e30956e68c14164763c130c1aceafb9c93fa25286c1f5d17c
5
5
  SHA512:
6
- metadata.gz: 55fb5b511f8ff2dc298d47063e4a602154cee613852a750ecc7fe77acdf1a9aa0686fbed86435180cf4c88dcb1038b7510b6ef9b1b58f4ff636d7f17cf34a475
7
- data.tar.gz: b33e682d6b94cb029d741495c0e14719ffbc643273d8fbe96b88725cbcc085425710e6d95683646f107bc5d874dc2ed00b96e89149fe881d2b6113bba95c3eda
6
+ metadata.gz: 9d90365c3d92aa903a50d5210f09d5bab8f0326bb29b42216cc8def98df66e6dfc14e31e93c44ab025d58ca8c320425e0590f21b02c9f0c95a09c47098aeca44
7
+ data.tar.gz: 4e3ce253f78282b89c15eeb14b8ed2d7cd026bb12141fcefad04d5264321673b9a8b6af464913330f1f773ed11e96b91883bfef9a08df302290f8bc06fcb4dcc
data/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # solargraph-rails changelog
2
+
3
+ ## Changes
4
+
5
+ ### v0.2.2.pre
6
+
7
+ * Simplistic support for associations
8
+ * Added dependency on ActiveSupport 6.1 for helpful String methods like `.camelize` and `.singularize`
9
+
10
+ ### v0.2.1
11
+
12
+ * Update Solargraph to 0.41
13
+
14
+ ### v0.2.0
15
+ First released version with no need to use --pre!
16
+
17
+ * Updated dependencies with security warnings
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- solargraph-rails (0.2.1)
5
- activesupport
6
- solargraph (~> 0.41.1)
4
+ solargraph-rails (0.2.2.pre.2)
5
+ activesupport (~> 6.1.3)
6
+ solargraph (~> 0.42.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
@@ -33,7 +33,7 @@ GEM
33
33
  kramdown (~> 2.0)
34
34
  mini_portile2 (2.5.3)
35
35
  minitest (5.14.4)
36
- nokogiri (1.11.6)
36
+ nokogiri (1.11.7)
37
37
  mini_portile2 (~> 2.5.0)
38
38
  racc (~> 1.4)
39
39
  parallel (1.20.1)
@@ -59,7 +59,7 @@ GEM
59
59
  diff-lcs (>= 1.2.0, < 2.0)
60
60
  rspec-support (~> 3.10.0)
61
61
  rspec-support (3.10.0)
62
- rubocop (1.16.0)
62
+ rubocop (1.16.1)
63
63
  parallel (~> 1.10)
64
64
  parser (>= 3.0.0.0)
65
65
  rainbow (>= 2.2.2, < 4.0)
@@ -71,10 +71,11 @@ GEM
71
71
  rubocop-ast (1.7.0)
72
72
  parser (>= 3.0.1.1)
73
73
  ruby-progressbar (1.11.0)
74
- solargraph (0.41.1)
74
+ solargraph (0.42.1)
75
75
  backport (~> 1.1)
76
76
  benchmark
77
77
  bundler (>= 1.17.2)
78
+ diff-lcs (~> 1.4)
78
79
  e2mmap
79
80
  jaro_winkler (~> 1.5)
80
81
  kramdown (~> 2.3)
data/README.md CHANGED
@@ -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.
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,16 @@
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
+ end
10
+
11
+ def type
12
+ name&.camelize
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
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
+ end
10
+
11
+ def type
12
+ "Array<#{name.singularize.camelize}>"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
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
+ end
10
+
11
+ def type
12
+ "Array<#{name.singularize.camelize}>"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
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
+ end
10
+
11
+ def type
12
+ name.camelize
13
+ end
14
+ end
15
+ end
16
+ end
@@ -53,22 +53,11 @@ module Solargraph
53
53
  end
54
54
 
55
55
  parser.on_ruby_line do |line|
56
- if line =~ /belongs_to\s+:([a-z_]*)/
57
- belongs_to_reader = Regexp.last_match(1)
58
-
59
- loc = Solargraph::Location.new(
60
- path,
61
- Solargraph::Range.from_to(
62
- parser.current_line_number,
63
- 0,
64
- parser.current_line_number,
65
- parser.current_line_length - 1
66
- )
67
- )
68
- model_attrs << { name: belongs_to_reader, type: belongs_to_reader.camelize, location: loc }
69
- elsif line =~ /has_many\s+:([a-z_]*)/
70
- has_many_reader = Regexp.last_match(1)
56
+ matcher = ruby_matchers.find do |m|
57
+ m.match?(line)
58
+ end
71
59
 
60
+ if matcher
72
61
  loc = Solargraph::Location.new(
73
62
  path,
74
63
  Solargraph::Range.from_to(
@@ -78,11 +67,7 @@ module Solargraph
78
67
  parser.current_line_length - 1
79
68
  )
80
69
  )
81
- model_attrs << {
82
- name: has_many_reader,
83
- type: "Array<#{has_many_reader.singularize.camelize}>",
84
- location: loc
85
- }
70
+ model_attrs << { name: matcher.name, type: matcher.type, location: loc }
86
71
  end
87
72
  end
88
73
 
@@ -101,6 +86,14 @@ module Solargraph
101
86
  end
102
87
  end
103
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
104
97
  def col_with_type(line)
105
98
  line
106
99
  .gsub(/[\(\),:\d]/, '')
@@ -1,5 +1,5 @@
1
1
  module Solargraph
2
2
  module Rails
3
- VERSION = '0.2.2.pre.1'
3
+ VERSION = '0.2.2.pre.2'
4
4
  end
5
5
  end
@@ -25,6 +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.41.1"
28
+ spec.add_runtime_dependency "solargraph", "~> 0.42.0"
29
29
  spec.add_runtime_dependency "activesupport", "~> 6.1.3"
30
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.2.pre.1
4
+ version: 0.2.2.pre.2
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-06-05 00:00:00.000000000 Z
11
+ date: 2021-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.41.1
61
+ version: 0.42.0
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.42.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activesupport
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -91,18 +91,24 @@ files:
91
91
  - ".gitignore"
92
92
  - ".rspec"
93
93
  - ".travis.yml"
94
+ - CHANGELOG.md
94
95
  - Gemfile
95
96
  - Gemfile.lock
96
97
  - LICENSE.txt
97
98
  - README.md
98
99
  - Rakefile
99
100
  - assets/peek.png
101
+ - assets/solar_rails_associations.gif
100
102
  - assets/solar_rails_autocomplete.gif
101
103
  - assets/solar_rails_goto.gif
102
104
  - bin/console
103
105
  - bin/setup
104
106
  - lib/solargraph-rails.rb
105
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
106
112
  - lib/solargraph/rails/pin_creator.rb
107
113
  - lib/solargraph/rails/ruby_parser.rb
108
114
  - lib/solargraph/rails/version.rb