ruby_language_server 0.3.12 → 0.3.13

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: c3c05305f5598c756c440e7a668d1d8a7021f18b079d4ead930e3bac72c0115a
4
- data.tar.gz: 9b620bcffca253ef2a464a1be4d39e7864064ac4310acca2a49457a62ab6f33b
3
+ metadata.gz: d415a25ab3f3a2455b16a935af695c5a79ac358bc56d14a2591086d14f394c07
4
+ data.tar.gz: f48b3dc86f3e9c9aaa7b84f737e10a44957cba653a701b3a0facbcbea91f16dd
5
5
  SHA512:
6
- metadata.gz: d3cea5c0f8687fa542916a3e4478f14612d2b1d590be461518d6bcf58ca141360301a0416bd624e7298170c9fc8abda77c16dc119c5f377d550fb0b79c818e11
7
- data.tar.gz: 5bc4f5db091bb6257e8eb8b4af3c0e76900b493ec2a4a80ea261380a8a91323e2d25cfc7b6d40cbb1877e96a3b7d673efa6b8795917f6c169e975f6c3f1acf9b
6
+ metadata.gz: 4981a189d35e2d26fdd8b320077cc3b7dffbc4ad6ad338133de4fdf14a4de6917caa3cf1d3f67c46d11997454fbdcd502455c936f995006a65d37c2130c464fe
7
+ data.tar.gz: 80f0cb7b6f5b69799d390dee746cd600d5310090c705565192a78658cf071be4f4d6cd14729e77a0d2332fd75148f9088e6903da3bd746647f95374d3abdfd7d
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ #### 0.3.13 Fri Feb 14 00:55:28 PST 2020
4
+
5
+ * More stabbing at goodcop gemfile issues
6
+ * Hopefully much higher performance and better completions
7
+
3
8
  #### 0.3.12 Thu Feb 6 06:18:33 UTC 2020
4
9
 
5
10
  * #58 Change the way additional gems are installed so there are not conflicts
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby_language_server (0.3.12)
4
+ ruby_language_server (0.3.13)
5
5
  activerecord (~> 5.2)
6
6
  amatch
7
7
  bundler
@@ -8,9 +8,14 @@ ActiveRecord::Base.establish_connection(
8
8
  checkout_timeout: 30.seconds # does not seem to help
9
9
  )
10
10
 
11
+ database = ActiveRecord::Base.connection.instance_variable_get :@connection
12
+ database.enable_load_extension(1)
13
+ database.load_extension('/usr/local/lib/liblevenshtein.so.0.0.0')
14
+ database.enable_load_extension(0)
15
+
11
16
  if ENV['LOG_LEVEL'] == 'DEBUG'
12
17
  begin
13
- warn('Turning on active record logging')
18
+ warn('Turning on active record logging to active_record.log')
14
19
  ActiveRecord::Base.logger = Logger.new(File.open('active_record.log', 'w'))
15
20
  rescue Exception => e
16
21
  ActiveRecord::Base.logger = Logger.new(STDERR)
@@ -32,7 +32,7 @@ module RubyLanguageServer
32
32
  else
33
33
  scope_completions_in_target_context(context, context_scope, position_scopes)
34
34
  end
35
- RubyLanguageServer.logger.debug("completions: #{completions.as_json}")
35
+ # RubyLanguageServer.logger.debug("completions: #{completions.as_json}")
36
36
  {
37
37
  isIncomplete: true,
38
38
  items: completions.uniq.map do |word, hash|
@@ -64,19 +64,34 @@ module RubyLanguageServer
64
64
 
65
65
  def module_completions(word)
66
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
67
+
68
+ # scope_words = RubyLanguageServer::ScopeData::Scope.where(class_type: class_and_module_types).sort_by(&:depth).map { |scope| [scope.name, scope] }
69
+ # words = scope_words.to_h
70
+ # good_words = FuzzyMatch.new(words.keys, threshold: 0.01).find_all(word).slice(0..10) || []
71
+ # words = good_words.each_with_object({}) { |w, hash| hash[w] = {depth: words[w].depth, type: words[w].class_type} }.to_h
72
+
73
+ words = RubyLanguageServer::ScopeData::Scope.where(class_type: class_and_module_types).closest_to(word).limit(20)
74
+ RubyLanguageServer.logger.error("module_completions: #{words.as_json}")
75
+ # words.to_a.sort_by(&:depth).each_with_object({}){|a_word, hash| hash[a_word.name] = {depth: a_word.depth, type: a_word.class_type} }
76
+ good_words = FuzzyMatch.new(words.to_a, read: :name, threshold: 0.01).find_all(word).slice(0..10) || []
77
+ good_words.each_with_object({}) { |w, hash| hash[w.name] = {depth: w.depth, type: w.class_type} }.to_h
71
78
  end
72
79
 
73
80
  def scope_completions(word, scopes)
74
81
  return module_completions(word) if word.match?(/\A[A-Z][a-z]/)
75
82
 
83
+ # scope_ids = scopes.map(&:id)
84
+ # word_scopes = scopes.to_a + RubyLanguageServer::ScopeData::Scope.where(parent_id: scope_ids)
85
+ # scope_words = word_scopes.select(&:named_scope?).sort_by(&:depth).map { |scope| [scope.name, scope] }
86
+ # variable_words = RubyLanguageServer::ScopeData::Variable.where(scope_id: scope_ids).map { |variable| [variable.name, variable.scope] }
87
+ # words = (scope_words + variable_words).to_h
88
+ # good_words = FuzzyMatch.new(words.keys, threshold: 0.01).find_all(word).slice(0..10) || []
89
+ # words = good_words.each_with_object({}) { |w, hash| hash[w] = {depth: words[w].depth, type: words[w].class_type} }.to_h
90
+
76
91
  scope_ids = scopes.map(&:id)
77
- word_scopes = scopes.to_a + RubyLanguageServer::ScopeData::Scope.where(parent_id: scope_ids)
92
+ word_scopes = scopes.to_a + RubyLanguageServer::ScopeData::Scope.where(parent_id: scope_ids).closest_to(word).limit(5)
78
93
  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] }
94
+ variable_words = RubyLanguageServer::ScopeData::Variable.where(scope_id: scope_ids).closest_to(word).limit(5).map { |variable| [variable.name, variable.scope] }
80
95
  words = (scope_words + variable_words).to_h
81
96
  good_words = FuzzyMatch.new(words.keys, threshold: 0.01).find_all(word).slice(0..10) || []
82
97
  words = good_words.each_with_object({}) { |w, hash| hash[w] = {depth: words[w].depth, type: words[w].class_type} }.to_h
@@ -12,16 +12,18 @@ module RubyLanguageServer
12
12
  return if additional_gem_names.nil? || additional_gem_names.empty?
13
13
 
14
14
  RubyLanguageServer.logger.info("Trying to install gems #{additional_gem_names}")
15
-
15
+ gems_already_installed = []
16
16
  gemfile do
17
17
  source 'https://rubygems.org'
18
18
  # Lock all the gems we already have installed to the versions we have installed
19
19
  # For some reason, installing bundler makes it unhappy. Whatever.
20
20
  Gem::Specification.reject { |s| s.name == 'bundler' }.each do |specification|
21
- gem(specification.name, specification.version.to_s)
21
+ gem_name = specification.name
22
+ gem(gem_name, specification.version.to_s)
23
+ gems_already_installed << gem_name
22
24
  end
23
25
  additional_gem_names.each do |gem_name|
24
- gem gem_name
26
+ gem gem_name unless gems_already_installed.include?(gem_name)
25
27
  end
26
28
  end
27
29
  end
@@ -7,10 +7,10 @@ module RubyLanguageServer
7
7
  def initialize(config_path, initialization_error = nil)
8
8
  @initialization_error = initialization_error
9
9
  unless @initialization_error
10
- config_store = RuboCop::ConfigStore.new
11
- config_store.options_config = config_path
10
+ @config_store = RuboCop::ConfigStore.new
11
+ @config_store.options_config = config_path
12
12
  RubyLanguageServer.logger.debug("Rubocop config_path: #{config_path}")
13
- super({}, config_store)
13
+ super({}, @config_store)
14
14
  end
15
15
  rescue Exception => e
16
16
  RubyLanguageServer.logger.error(e)
@@ -6,9 +6,9 @@ module RubyLanguageServer
6
6
  level_name = ENV.fetch('LOG_LEVEL') { 'error' }.upcase
7
7
  # level_name = 'DEBUG'
8
8
  level = Logger::Severity.const_get(level_name)
9
+ class << self
10
+ attr_accessor :logger
11
+ end
9
12
  @logger = ::Logger.new(STDERR, level: level)
10
13
  @logger.log(level, "Logger started at level #{level_name} -> #{level}")
11
- def self.logger
12
- @logger
13
- end
14
14
  end
@@ -27,6 +27,15 @@ module RubyLanguageServer
27
27
 
28
28
  attr_accessor :type # Type of this scope (module, class, block)
29
29
 
30
+ # bar should be closer to Bar than Far. Adding the UPPER version accomplishes this.
31
+ scope :with_distance_from, lambda { |word|
32
+ sanitized_word = sanitize_sql(word)
33
+ where("LENGTH(name) >= LENGTH('#{sanitized_word}')").select("*, LEVENSHTEIN(SUBSTR(name, 1, #{word.length}), '#{sanitized_word}') + LEVENSHTEIN(SUBSTR(UPPER(name), 1, #{word.length}), UPPER('#{sanitized_word}')) as levenshtein_distance")
34
+ }
35
+ scope :closest_to, ->(word) { with_distance_from(word).order(:levenshtein_distance) }
36
+
37
+ # RubyLanguageServer::ScopeData::Scope.connection.exec_query("SELECT LEVENSHTEIN( 'This is not correct', 'This is correct' )")
38
+
30
39
  def method?
31
40
  type == TYPE_METHOD
32
41
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyLanguageServer
4
- VERSION = '0.3.12'
4
+ VERSION = '0.3.13'
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.12
4
+ version: 0.3.13
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-02-06 00:00:00.000000000 Z
11
+ date: 2020-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler