ruby_language_server 0.3.8 → 0.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.txt +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/ruby_language_server/completion.rb +23 -23
- data/lib/ruby_language_server/project_manager.rb +3 -6
- data/lib/ruby_language_server/scope_data/scope.rb +5 -0
- data/lib/ruby_language_server/scope_data/variable.rb +2 -0
- data/lib/ruby_language_server/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7f8d3e239241819fab0206c27fa63422d46001a58048b52355e3817243b8239
|
4
|
+
data.tar.gz: 8c43b621ee0d3124fb122f725828426d9a9c88dc2a8217a74725c0868dabb4bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a90bef1450867b3816a091175a7d2a51e25f05972fdce4460c0f0da472e9ba2ae09af7aa23a48a290e5fa53925619af942752e34af390b436fa79256c0198108
|
7
|
+
data.tar.gz: e6d05f5fce1ee700e55e0e863f1731481848cba12ab6e2f6064270e67ae5711da43ea5da1896608389e052b474fd11394fd5ec458288e9b5ad665119ceef39e6
|
data/CHANGELOG.txt
CHANGED
data/Gemfile.lock
CHANGED
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,
|
28
|
-
RubyLanguageServer.logger.debug("completion(#{context}, #{
|
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,
|
31
|
+
scope_completions(context.first, position_scopes)
|
32
32
|
else
|
33
|
-
scope_completions_in_target_context(context, context_scope,
|
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 =
|
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
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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.
|
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
|
-
|
100
|
-
|
101
|
-
|
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
|
|
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.
|
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-
|
11
|
+
date: 2020-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|