ruby_language_server 0.3.8 → 0.3.9

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: 87d63dcf81f034409b543e9a35073344a614e28aaa6c33ed9803f9fc130e192e
4
- data.tar.gz: ab52a3ade63649d48adbbdcc3f03496762d514f5d6ca48b872f5272272ab80bd
3
+ metadata.gz: b7f8d3e239241819fab0206c27fa63422d46001a58048b52355e3817243b8239
4
+ data.tar.gz: 8c43b621ee0d3124fb122f725828426d9a9c88dc2a8217a74725c0868dabb4bc
5
5
  SHA512:
6
- metadata.gz: c36791fa58a5f236d6be05e9600538065ceec7c53efb6bc2375d41120965863fcf739beada15d90ac27633b2a3859afc39a072d0bc96dc94cf5274646cdb0192
7
- data.tar.gz: accecbb489f8f461b0c4c1d42d504f6a5339bc8af533522b02ffa6717e9e22367f05f1b42d2bd7ec23ad17f5bf800fd4f56baba1c59f2afec9db74d2fa4075ac
6
+ metadata.gz: a90bef1450867b3816a091175a7d2a51e25f05972fdce4460c0f0da472e9ba2ae09af7aa23a48a290e5fa53925619af942752e34af390b436fa79256c0198108
7
+ data.tar.gz: e6d05f5fce1ee700e55e0e863f1731481848cba12ab6e2f6064270e67ae5711da43ea5da1896608389e052b474fd11394fd5ec458288e9b5ad665119ceef39e6
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ #### 0.3.9 Fri Jan 24 00:19:14 PST 2020
4
+
5
+ * #55 Some problem with completion
6
+
3
7
  #### 0.3.8 Wed Jan 22 22:22:35 PST 2020
4
8
 
5
9
  * #54 fix lookup for "something.is_method?" dropping the ?
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby_language_server (0.3.8)
4
+ ruby_language_server (0.3.9)
5
5
  activerecord (~> 5.2)
6
6
  amatch
7
7
  bundler
data/README.md CHANGED
@@ -34,7 +34,7 @@ Clone. I love git [HubFlow](https://datasift.github.io/gitflow/).
34
34
  Check out the [Makefile](Makefile). You are going to want to do
35
35
  `make guard` in one window and `make continuous_development` in another.
36
36
 
37
- * In Atom: install the ide-ruby.
37
+ * In Atom: install the ide-ruby.
38
38
  * Settings > Packages > ide-ruby > Image Name > local_ruby_language_server
39
39
  * CMD-ALT-CTRL-l (that's an L) will reload the window
40
40
  * CMD-ALT-i will show debugging info
@@ -24,13 +24,13 @@ module RubyLanguageServer
24
24
  }.freeze
25
25
 
26
26
  class << self
27
- def completion(context, context_scope, scopes)
28
- RubyLanguageServer.logger.debug("completion(#{context}, #{scopes.map(&:name)})")
27
+ def completion(context, context_scope, position_scopes)
28
+ RubyLanguageServer.logger.debug("completion(#{context}, #{position_scopes.map(&:name)})")
29
29
  completions =
30
30
  if context.length < 2
31
- scope_completions(context.first, scopes)
31
+ scope_completions(context.first, position_scopes)
32
32
  else
33
- scope_completions_in_target_context(context, context_scope, scopes)
33
+ scope_completions_in_target_context(context, context_scope, position_scopes)
34
34
  end
35
35
  RubyLanguageServer.logger.debug("completions: #{completions.as_json}")
36
36
  {
@@ -55,31 +55,31 @@ module RubyLanguageServer
55
55
  def scope_completions_in_target_context(context, context_scope, scopes)
56
56
  context_word = context[-2]
57
57
  context_word = context_word.split(/_/).map(&:capitalize).join('') unless context_word.match?(/^[A-Z]/)
58
- context_scopes = scopes_with_name(context_word, scopes)
58
+ context_scopes = RubyLanguageServer::ScopeData::Scope.where(name: context_word)
59
59
  context_scopes ||= context_scope
60
60
  RubyLanguageServer.logger.debug("context_scopes: #{context_scopes.to_json}")
61
- scope_completions(context.last, Array(context_scopes) + scopes.includes(:variables))
61
+ # scope_completions(context.last, Array(context_scopes) + scopes.includes(:variables))
62
+ (scope_completions(context.last, Array(context_scopes)).to_a + scope_completions(context.last, scopes.includes(:variables)).to_a).uniq.to_h
63
+ end
64
+
65
+ def module_completions(word)
66
+ class_and_module_types = [RubyLanguageServer::ScopeData::Base::TYPE_CLASS, RubyLanguageServer::ScopeData::Base::TYPE_MODULE]
67
+ scope_words = RubyLanguageServer::ScopeData::Scope.where(class_type: class_and_module_types).sort_by(&:depth).map { |scope| [scope.name, scope] }
68
+ words = scope_words.to_h
69
+ good_words = FuzzyMatch.new(words.keys, threshold: 0.01).find_all(word).slice(0..10) || []
70
+ words = good_words.each_with_object({}) { |w, hash| hash[w] = {depth: words[w].depth, type: words[w].class_type} }.to_h
62
71
  end
63
72
 
64
73
  def scope_completions(word, scopes)
65
- words = {}
66
- scopes.each_with_object(words) do |scope, words_hash|
67
- scope.children.method_scopes.each do |method_scope|
68
- words_hash[method_scope.name] ||= {
69
- depth: scope.depth,
70
- type: method_scope.class_type
71
- }
72
- end
73
- scope.variables.each do |variable|
74
- words_hash[variable.name] ||= {
75
- depth: scope.depth,
76
- type: variable.variable_type
77
- }
78
- end
79
- end
80
- words = words.sort_by { |_word, hash| hash[:depth] }.to_h
74
+ return module_completions(word) if word.match?(/\A[A-Z][a-z]/)
75
+
76
+ scope_ids = scopes.map(&:id)
77
+ word_scopes = scopes.to_a + RubyLanguageServer::ScopeData::Scope.where(parent_id: scope_ids)
78
+ scope_words = word_scopes.select(&:named_scope?).sort_by(&:depth).map { |scope| [scope.name, scope] }
79
+ variable_words = RubyLanguageServer::ScopeData::Variable.where(scope_id: scope_ids).map { |variable| [variable.name, variable.scope] }
80
+ words = (scope_words + variable_words).to_h
81
81
  good_words = FuzzyMatch.new(words.keys, threshold: 0.01).find_all(word).slice(0..10) || []
82
- words = good_words.map { |w| [w, words[w]] }.to_h
82
+ words = good_words.each_with_object({}) { |w, hash| hash[w] = {depth: words[w].depth, type: words[w].class_type} }.to_h
83
83
  end
84
84
  end
85
85
  end
@@ -96,15 +96,12 @@ module RubyLanguageServer
96
96
  end
97
97
 
98
98
  def completion_at(uri, position)
99
- relative_position = position.dup
100
- relative_position.character = relative_position.character # To get before the . or ::
101
- # RubyLanguageServer.logger.debug("relative_position #{relative_position}")
99
+ context = context_at_location(uri, position)
100
+ return {} if context.blank?
101
+
102
102
  RubyLanguageServer.logger.debug("scopes_at(uri, position) #{scopes_at(uri, position).map(&:name)}")
103
103
  position_scopes = scopes_at(uri, position) || RubyLanguageServer::ScopeData::Scope.where(id: root_scope_for(uri).id)
104
104
  context_scope = position_scopes.first
105
- context = context_at_location(uri, relative_position)
106
- return {} if context.nil? || context == ''
107
-
108
105
  RubyLanguageServer::Completion.completion(context, context_scope, position_scopes)
109
106
  end
110
107
 
@@ -72,6 +72,11 @@ module RubyLanguageServer
72
72
  class_type == TYPE_BLOCK
73
73
  end
74
74
 
75
+ # Not a block or root
76
+ def named_scope?
77
+ [TYPE_MODULE, TYPE_CLASS, TYPE_METHOD, TYPE_VARIABLE].include?(class_type)
78
+ end
79
+
75
80
  private
76
81
 
77
82
  def scope_parts
@@ -10,6 +10,8 @@ module RubyLanguageServer
10
10
 
11
11
  scope :constant_variables, -> { where("SUBSTR(name, 1, 1) between ('A') and ('Z')") }
12
12
 
13
+ delegate :depth, to: :scope
14
+
13
15
  # attr_accessor :line # line
14
16
  # attr_accessor :column # column
15
17
  # attr_accessor :name # name
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyLanguageServer
4
- VERSION = '0.3.8'
4
+ VERSION = '0.3.9'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_language_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kurt Werle
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-23 00:00:00.000000000 Z
11
+ date: 2020-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler