solargraph-rails 0.2.2.pre.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +28 -0
- data/README.md +4 -2
- data/assets/solar_rails_associations.gif +0 -0
- data/lib/solargraph/rails/meta_source/association/belongs_to_matcher.rb +24 -0
- data/lib/solargraph/rails/meta_source/association/has_and_belongs_to_many_matcher.rb +24 -0
- data/lib/solargraph/rails/meta_source/association/has_many_matcher.rb +24 -0
- data/lib/solargraph/rails/meta_source/association/has_one_matcher.rb +24 -0
- data/lib/solargraph/rails/pin_creator.rb +14 -21
- data/lib/solargraph/rails/version.rb +1 -1
- data/lib/solargraph-rails.rb +4 -0
- data/solargraph-rails.gemspec +2 -2
- metadata +16 -11
- data/Gemfile.lock +0 -108
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf9a813f372c7c2f1e7b26294cde25617702b4d718cbac08f37036a866a23365
|
4
|
+
data.tar.gz: af00aad628cc77acb911dcc86e8906609cd71a4b906b8eb69b0a6cae9343b409
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc552911a9121aa3a7876fabf09c7850854ba53bea4fbb8374f565017d39ccc2cb1d6c2a9db30b62a213c35577eb6d290b8037ffd140216e676fba3e2038c01a
|
7
|
+
data.tar.gz: 74d5c903fedf1d94500b7d51a94810e95af3b7b8dc04dfa8bbeba724f4f8bf4587273a8788a87580bbae01868a1a75ddccba5daf0074069d102d83c10d28ca5f
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# solargraph-rails changelog
|
2
|
+
|
3
|
+
## Changes
|
4
|
+
|
5
|
+
### v0.3.0
|
6
|
+
* Require String inflection monkeypatches directly to avoid error from ActiveSupport v7
|
7
|
+
* Remove Gemfile.lock from version control
|
8
|
+
|
9
|
+
### v0.2.2.pre.4
|
10
|
+
* Loosen the dependency requirements
|
11
|
+
|
12
|
+
### v0.2.2.pre.3
|
13
|
+
* Update to solargraph 0.42.3
|
14
|
+
* Determine return type of association using class_name argument
|
15
|
+
|
16
|
+
### v0.2.2.pre.2
|
17
|
+
|
18
|
+
* Simplistic support for associations
|
19
|
+
* Added dependency on ActiveSupport 6.1 for helpful String methods like `.camelize` and `.singularize`
|
20
|
+
|
21
|
+
### v0.2.1
|
22
|
+
|
23
|
+
* Update Solargraph to 0.41
|
24
|
+
|
25
|
+
### v0.2.0
|
26
|
+
First released version with no need to use --pre!
|
27
|
+
|
28
|
+
* Updated dependencies with security warnings
|
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
|
-
|
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
|
@@ -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,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'active_support/core_ext/string'
|
3
|
+
require 'active_support/core_ext/string/inflections'
|
4
4
|
|
5
5
|
module Solargraph
|
6
6
|
module Rails
|
@@ -53,22 +53,11 @@ module Solargraph
|
|
53
53
|
end
|
54
54
|
|
55
55
|
parser.on_ruby_line do |line|
|
56
|
-
|
57
|
-
|
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]/, '')
|
data/lib/solargraph-rails.rb
CHANGED
@@ -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
|
data/solargraph-rails.gemspec
CHANGED
@@ -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", "
|
29
|
-
spec.add_runtime_dependency "activesupport"
|
28
|
+
spec.add_runtime_dependency "solargraph", ">= 0.41.1"
|
29
|
+
spec.add_runtime_dependency "activesupport"
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fritz Meissner
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,30 +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
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
68
|
version: 0.41.1
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: activesupport
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: '0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: '0'
|
83
83
|
description: Add reflection on ActiveModel dynamic attributes that will be created
|
84
84
|
at runtime
|
85
85
|
email:
|
@@ -91,18 +91,23 @@ files:
|
|
91
91
|
- ".gitignore"
|
92
92
|
- ".rspec"
|
93
93
|
- ".travis.yml"
|
94
|
+
- CHANGELOG.md
|
94
95
|
- Gemfile
|
95
|
-
- Gemfile.lock
|
96
96
|
- LICENSE.txt
|
97
97
|
- README.md
|
98
98
|
- Rakefile
|
99
99
|
- assets/peek.png
|
100
|
+
- assets/solar_rails_associations.gif
|
100
101
|
- assets/solar_rails_autocomplete.gif
|
101
102
|
- assets/solar_rails_goto.gif
|
102
103
|
- bin/console
|
103
104
|
- bin/setup
|
104
105
|
- lib/solargraph-rails.rb
|
105
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
|
106
111
|
- lib/solargraph/rails/pin_creator.rb
|
107
112
|
- lib/solargraph/rails/ruby_parser.rb
|
108
113
|
- lib/solargraph/rails/version.rb
|
@@ -122,9 +127,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
122
127
|
version: '0'
|
123
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
129
|
requirements:
|
125
|
-
- - "
|
130
|
+
- - ">="
|
126
131
|
- !ruby/object:Gem::Version
|
127
|
-
version:
|
132
|
+
version: '0'
|
128
133
|
requirements: []
|
129
134
|
rubygems_version: 3.2.3
|
130
135
|
signing_key:
|
data/Gemfile.lock
DELETED
@@ -1,108 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
solargraph-rails (0.2.1)
|
5
|
-
activesupport
|
6
|
-
solargraph (~> 0.41.1)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
activesupport (6.1.3.2)
|
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)
|
17
|
-
ast (2.4.2)
|
18
|
-
backport (1.1.2)
|
19
|
-
benchmark (0.1.1)
|
20
|
-
bundler-audit (0.8.0)
|
21
|
-
bundler (>= 1.2.0, < 3)
|
22
|
-
thor (~> 1.0)
|
23
|
-
byebug (11.1.3)
|
24
|
-
concurrent-ruby (1.1.9)
|
25
|
-
diff-lcs (1.4.4)
|
26
|
-
e2mmap (0.1.0)
|
27
|
-
i18n (1.8.10)
|
28
|
-
concurrent-ruby (~> 1.0)
|
29
|
-
jaro_winkler (1.5.4)
|
30
|
-
kramdown (2.3.1)
|
31
|
-
rexml
|
32
|
-
kramdown-parser-gfm (1.1.0)
|
33
|
-
kramdown (~> 2.0)
|
34
|
-
mini_portile2 (2.5.3)
|
35
|
-
minitest (5.14.4)
|
36
|
-
nokogiri (1.11.6)
|
37
|
-
mini_portile2 (~> 2.5.0)
|
38
|
-
racc (~> 1.4)
|
39
|
-
parallel (1.20.1)
|
40
|
-
parser (3.0.1.1)
|
41
|
-
ast (~> 2.4.1)
|
42
|
-
racc (1.5.2)
|
43
|
-
rainbow (3.0.0)
|
44
|
-
rake (12.3.3)
|
45
|
-
regexp_parser (2.1.1)
|
46
|
-
reverse_markdown (2.0.0)
|
47
|
-
nokogiri
|
48
|
-
rexml (3.2.5)
|
49
|
-
rspec (3.10.0)
|
50
|
-
rspec-core (~> 3.10.0)
|
51
|
-
rspec-expectations (~> 3.10.0)
|
52
|
-
rspec-mocks (~> 3.10.0)
|
53
|
-
rspec-core (3.10.0)
|
54
|
-
rspec-support (~> 3.10.0)
|
55
|
-
rspec-expectations (3.10.0)
|
56
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
57
|
-
rspec-support (~> 3.10.0)
|
58
|
-
rspec-mocks (3.10.0)
|
59
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
60
|
-
rspec-support (~> 3.10.0)
|
61
|
-
rspec-support (3.10.0)
|
62
|
-
rubocop (1.16.0)
|
63
|
-
parallel (~> 1.10)
|
64
|
-
parser (>= 3.0.0.0)
|
65
|
-
rainbow (>= 2.2.2, < 4.0)
|
66
|
-
regexp_parser (>= 1.8, < 3.0)
|
67
|
-
rexml
|
68
|
-
rubocop-ast (>= 1.7.0, < 2.0)
|
69
|
-
ruby-progressbar (~> 1.7)
|
70
|
-
unicode-display_width (>= 1.4.0, < 3.0)
|
71
|
-
rubocop-ast (1.7.0)
|
72
|
-
parser (>= 3.0.1.1)
|
73
|
-
ruby-progressbar (1.11.0)
|
74
|
-
solargraph (0.41.1)
|
75
|
-
backport (~> 1.1)
|
76
|
-
benchmark
|
77
|
-
bundler (>= 1.17.2)
|
78
|
-
e2mmap
|
79
|
-
jaro_winkler (~> 1.5)
|
80
|
-
kramdown (~> 2.3)
|
81
|
-
kramdown-parser-gfm (~> 1.1)
|
82
|
-
parser (~> 3.0)
|
83
|
-
reverse_markdown (>= 1.0.5, < 3)
|
84
|
-
rubocop (>= 0.52)
|
85
|
-
thor (~> 1.0)
|
86
|
-
tilt (~> 2.0)
|
87
|
-
yard (~> 0.9, >= 0.9.24)
|
88
|
-
thor (1.1.0)
|
89
|
-
tilt (2.0.10)
|
90
|
-
tzinfo (2.0.4)
|
91
|
-
concurrent-ruby (~> 1.0)
|
92
|
-
unicode-display_width (2.0.0)
|
93
|
-
yard (0.9.26)
|
94
|
-
zeitwerk (2.4.2)
|
95
|
-
|
96
|
-
PLATFORMS
|
97
|
-
ruby
|
98
|
-
|
99
|
-
DEPENDENCIES
|
100
|
-
bundler (~> 2.2.10)
|
101
|
-
bundler-audit
|
102
|
-
byebug
|
103
|
-
rake (~> 12.3.3)
|
104
|
-
rspec (~> 3.0)
|
105
|
-
solargraph-rails!
|
106
|
-
|
107
|
-
BUNDLED WITH
|
108
|
-
2.2.16
|