solargraph-rails 0.2.0.pre → 0.2.2.pre.3

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: 10a5f0ba2496f8b79f4e008ae3ca68f4cb193c31fdbdf95d18b65fc3850e703e
4
- data.tar.gz: e21cff4b322b4b8547b9b06709f30fbd883108983570dfb3d44c50e83f335ecf
3
+ metadata.gz: f2ceb38938b95c2d2772c9b863053613a30f91fb6bfdcf3a8373de01b8c95484
4
+ data.tar.gz: f385b1fd2a0839ba5f8fd9c5476b068c56ddcac510382cd453c3524ce6f50d82
5
5
  SHA512:
6
- metadata.gz: 6be898e5f949bb5e683dd5057bd85ae88ebdf19a8d5662b3d107c444ec54b24c71f6026c0877bcf0e1c59e6f7aa2ae21713c6067e0f1c9d2f8f3bb93e60813b6
7
- data.tar.gz: a26cbfc730799c6308773ee01a900356227d624d3b0090992ae21a915f01f42964fba3a53ba6fd29ee19c49bad4ef4f45a81592de999b3f48cd82c23519df954
6
+ metadata.gz: 11d1095b3e45568950dff2ed39272e282507f093e9021143b0108242b01d4ccd568ec3932f9fdb68f2b7aeea6c95f359fbdb464630238c01e7a92fbcf434fa1e
7
+ data.tar.gz: 420248dfa30f8da3e279a0e0f77fd48f6e1057ddaa5ab97aeaef96e76aa738cdb64ddb7ef3974594f4edf7cacce912820e0ec260286826808928527f73ab06be
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 CHANGED
@@ -4,6 +4,7 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  group :development, :test do
6
6
  gem 'byebug'
7
+ gem 'bundler-audit'
7
8
  end
8
9
  # Specify your gem's dependencies in solargraph_rails.gemspec
9
10
  gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,109 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ solargraph-rails (0.2.2.pre.3)
5
+ activesupport (~> 6.1.3)
6
+ solargraph (~> 0.42.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.2.0)
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.7)
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.17.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.42.3)
75
+ backport (~> 1.2)
76
+ benchmark
77
+ bundler (>= 1.17.2)
78
+ diff-lcs (~> 1.4)
79
+ e2mmap
80
+ jaro_winkler (~> 1.5)
81
+ kramdown (~> 2.3)
82
+ kramdown-parser-gfm (~> 1.1)
83
+ parser (~> 3.0)
84
+ reverse_markdown (>= 1.0.5, < 3)
85
+ rubocop (>= 0.52)
86
+ thor (~> 1.0)
87
+ tilt (~> 2.0)
88
+ yard (~> 0.9, >= 0.9.24)
89
+ thor (1.1.0)
90
+ tilt (2.0.10)
91
+ tzinfo (2.0.4)
92
+ concurrent-ruby (~> 1.0)
93
+ unicode-display_width (2.0.0)
94
+ yard (0.9.26)
95
+ zeitwerk (2.4.2)
96
+
97
+ PLATFORMS
98
+ ruby
99
+
100
+ DEPENDENCIES
101
+ bundler (~> 2.2.10)
102
+ bundler-audit
103
+ byebug
104
+ rake (~> 12.3.3)
105
+ rspec (~> 3.0)
106
+ solargraph-rails!
107
+
108
+ BUNDLED WITH
109
+ 2.2.16
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. Don't use it if you're not willing to do things like build gems from source and install them locally. 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.
@@ -61,26 +63,20 @@ This project is being used to write production code by the maintainer, but it is
61
63
 
62
64
  ### Install `solargraph` v0.40+ and `solargraph_rails` locally
63
65
 
64
- SG v0.40 and solargraph_rails are unreleased at time of writing. You'll need to install both locally:
65
-
66
- 1. Clone solargraph and update version.rb to 0.40.0
67
- 2. Run `gem build` in the root of your clone to create `solargraph-0.40.0.gem`
68
- 3. Clone solargraph_rails
69
- 4. Run `gem build` in the root of your clone to create `solargraph_rails-0.1.1.gem`
70
- 5. From the root of your Rails app, install solargraph locally: `gem install --local /path/to/solargraph-0.40.0.gem`
71
- 6. From the root of your Rails app, install solargraph_rails locally: `gem install --local /path/to/solargraph_rails-0.1.1.gem`
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`.
72
67
 
73
- ### Install gems outside of bundler
74
- This is the path described above. 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`.
68
+ `gem install solargraph-rails`
75
69
 
76
70
  #### Alternative: using bundler
77
- If you do want to use bundler, add `gem "solargraph", path: "/path/to/my_solargraph"` and `gem "solargraph_rails", path: "/path/to/my_solargraph_rails"` instead of steps 5 & 6 above.
71
+ If you do want to use bundler, add `gem 'solargraph-rails', '~> 0.2.0'`
72
+
73
+ ### Add `solargraph-rails` to your `.solargraph.yml`
78
74
 
79
- ### Add `solargraph_rails` to your `.solargraph.yml`
75
+ (if you don't have a `.solargraph.yml` in your project root, you can run `solargraph config` to add one)
80
76
 
81
77
  ```
82
78
  plugins:
83
- - solargraph_rails
79
+ - solargraph-rails
84
80
  ```
85
81
 
86
82
  ### Add annotate
@@ -92,9 +88,9 @@ Fork the project, start hacking, put up a PR :).
92
88
 
93
89
  When you make changes, you probably need to shut down solargraph and restart it (maybe that requires you to shut down your whole editor?). You can speed up the feedback loop by running
94
90
 
95
- `api_map = Solargraph::ApiMap.load(Rails.root)`
91
+ `api_map = Solargraph::ApiMap.load(Rails.root.to_s)`
96
92
 
97
- in the console of the Rails project where solargraph_rails is installed. This may require restarting the rails console each time, and possibly killing Spring.
93
+ in the console of the Rails project where solargraph-rails is installed. This may require restarting the rails console each time, and possibly killing Spring.
98
94
 
99
95
  Once you have an instance of `Solargraph::ApiMap`, you can interrogate it with Solargraph code like:
100
96
 
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.pre'
3
+ VERSION = '0.2.2.pre.3'
4
4
  end
5
5
  end
@@ -21,9 +21,10 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_development_dependency "bundler", "~> 2.1.4"
24
+ spec.add_development_dependency "bundler", "~> 2.2.10"
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.42.1"
29
+ spec.add_runtime_dependency "activesupport", "~> 6.1.3"
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.pre
4
+ version: 0.2.2.pre.3
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-01-09 00:00:00.000000000 Z
11
+ date: 2021-06-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.1.4
19
+ version: 2.2.10
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.1.4
26
+ version: 2.2.10
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +58,28 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.40.0
61
+ version: 0.42.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.42.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: 6.1.3
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 6.1.3
69
83
  description: Add reflection on ActiveModel dynamic attributes that will be created
70
84
  at runtime
71
85
  email:
@@ -77,17 +91,24 @@ files:
77
91
  - ".gitignore"
78
92
  - ".rspec"
79
93
  - ".travis.yml"
94
+ - CHANGELOG.md
80
95
  - Gemfile
96
+ - Gemfile.lock
81
97
  - LICENSE.txt
82
98
  - README.md
83
99
  - Rakefile
84
100
  - assets/peek.png
101
+ - assets/solar_rails_associations.gif
85
102
  - assets/solar_rails_autocomplete.gif
86
103
  - assets/solar_rails_goto.gif
87
104
  - bin/console
88
105
  - bin/setup
89
106
  - lib/solargraph-rails.rb
90
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
91
112
  - lib/solargraph/rails/pin_creator.rb
92
113
  - lib/solargraph/rails/ruby_parser.rb
93
114
  - lib/solargraph/rails/version.rb
@@ -111,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
132
  - !ruby/object:Gem::Version
112
133
  version: 1.3.1
113
134
  requirements: []
114
- rubygems_version: 3.1.4
135
+ rubygems_version: 3.2.3
115
136
  signing_key:
116
137
  specification_version: 4
117
138
  summary: Solargraph plugin that adds Rails-specific code through a Convention