openvox-editor-services 3.1.1 → 4.0.0

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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +46 -12
  3. data/Gemfile +16 -13
  4. data/README.md +147 -165
  5. data/RELEASE.md +1 -1
  6. data/lib/dsp/dsp_base.rb +2 -1
  7. data/lib/lsp/lsp_base.rb +2 -1
  8. data/lib/openvox_agent_rubygems.rb +2 -1
  9. data/lib/openvox_runtime.rb +5 -1
  10. data/lib/puppet-debugserver/debug_session/break_points.rb +1 -1
  11. data/lib/puppet-debugserver/debug_session/hook_handlers.rb +1 -1
  12. data/lib/puppet-languageserver/global_queues/single_instance_queue.rb +3 -0
  13. data/lib/puppet-languageserver/manifest/completion_provider.rb +1 -1
  14. data/lib/puppet-languageserver/manifest/format_on_type_provider.rb +3 -2
  15. data/lib/puppet-languageserver/manifest/hover_provider.rb +1 -1
  16. data/lib/puppet-languageserver/manifest/signature_provider.rb +3 -3
  17. data/lib/puppet-languageserver/manifest/validation_provider.rb +15 -3
  18. data/lib/puppet-languageserver/message_handler.rb +1 -1
  19. data/lib/puppet-languageserver/puppet_parser_helper.rb +9 -9
  20. data/lib/puppet-languageserver/puppetfile/validation_provider.rb +1 -1
  21. data/lib/puppet-languageserver/session_state/document_store.rb +5 -5
  22. data/lib/puppet-languageserver/session_state/language_client.rb +11 -11
  23. data/lib/puppet-languageserver/sidecar_protocol.rb +20 -11
  24. data/lib/puppet-languageserver-sidecar/cache/filesystem.rb +2 -2
  25. data/lib/puppet-languageserver-sidecar/puppet_helper.rb +5 -6
  26. data/lib/puppet-languageserver-sidecar/puppet_parser_helper.rb +4 -4
  27. data/lib/puppet-languageserver-sidecar/puppet_strings_helper.rb +2 -1
  28. data/lib/puppet-languageserver-sidecar/workspace.rb +2 -2
  29. data/lib/puppet_editor_services/handler/json_rpc.rb +3 -3
  30. data/lib/puppet_editor_services/protocol/debug_adapter_messages.rb +2 -1
  31. data/lib/puppet_editor_services/protocol/json_rpc_messages.rb +2 -1
  32. data/lib/puppet_editor_services/server/stdio.rb +2 -2
  33. data/lib/puppet_editor_services/server/tcp.rb +1 -4
  34. data/lib/puppet_editor_services/version.rb +1 -1
  35. data/lib/puppet_languageserver.rb +2 -0
  36. metadata +4 -4
data/lib/lsp/lsp_base.rb CHANGED
@@ -30,7 +30,8 @@ module LSP
30
30
  def from_h!(value); end
31
31
 
32
32
  def to_json(*options)
33
- to_h.to_json(options)
33
+ # JSON 2.21 requires an options hash, so expand the captured arguments instead of passing their array.
34
+ to_h.to_json(*options)
34
35
  end
35
36
 
36
37
  private
@@ -54,7 +54,8 @@ module OpenVoxAgentRubygems
54
54
 
55
55
  def self.packaged_agent_ruby?
56
56
  [RbConfig::CONFIG['prefix'], Gem.default_dir].compact.any? do |path|
57
- normalized_path(path).include?('/puppetlabs/puppet')
57
+ normalized = normalized_path(path)
58
+ normalized.include?('/puppetlabs/puppet') || normalized.include?('/puppet labs/puppet')
58
59
  end
59
60
  end
60
61
  private_class_method :packaged_agent_ruby?
@@ -8,7 +8,11 @@ module OpenVoxRuntime
8
8
  def self.activate!(version = nil)
9
9
  OpenVoxAgentRubygems.activate!
10
10
  specification = select_specification(version)
11
- raise Gem::LoadError, "Unable to find the #{GEM_NAME} gem#{version.nil? ? '' : " version #{version}"}" if specification.nil?
11
+ if specification.nil?
12
+ message = "Unable to find the #{GEM_NAME} gem"
13
+ message << " version #{version}" unless version.nil?
14
+ raise Gem::LoadError, message
15
+ end
12
16
 
13
17
  if Gem::Specification.find_all_by_name(GEM_NAME).include?(specification)
14
18
  version.nil? || version.empty? ? gem(GEM_NAME) : gem(GEM_NAME, version)
@@ -29,7 +29,7 @@ module PuppetDebugServer
29
29
 
30
30
  begin
31
31
  # TODO: This could be slow on big files....
32
- IO.foreach(file_path, mode: 'rb', encoding: 'UTF-8').each_with_index do |item, index|
32
+ File.foreach(file_path, mode: 'rb', encoding: 'UTF-8').each_with_index do |item, index|
33
33
  # index here zero-based whereas we want one-based indexing
34
34
  file_contents[index + 1] = item if line_list.include?(index + 1)
35
35
  end
@@ -133,7 +133,7 @@ module PuppetDebugServer
133
133
  target_end_line = @debug_session.line_for_offset(target, target_loc.offset + target_loc.length)
134
134
 
135
135
  # TODO: What about Hit and Conditional BreakPoints?
136
- bp = line_breakpoints.find_index { |bp_line| bp_line >= target_start_line && bp_line <= target_end_line }
136
+ bp = line_breakpoints.find_index { |bp_line| bp_line.between?(target_start_line, target_end_line) }
137
137
  unless bp.nil?
138
138
  # Re-raise the hook as a breakpoint
139
139
  @debug_session.execute_hook(:hook_breakpoint, [ast_classname, ''] + args)
@@ -115,6 +115,9 @@ module PuppetLanguageServer
115
115
  begin
116
116
  # When running async (i.e. from a thread swallow any output)
117
117
  _result = execute_job(work_item)
118
+ rescue SystemExit => e
119
+ PuppetLanguageServer.log_message(:error, "#{self.class} Thread: Job #{work_item.key} attempted to exit. #{e}")
120
+ nil
118
121
  rescue StandardError => e
119
122
  PuppetLanguageServer.log_message(:error, "#{self.class} Thread: Error running job #{work_item.key}. #{e}\n#{e.backtrace}")
120
123
  nil
@@ -247,7 +247,7 @@ module PuppetLanguageServer
247
247
  return result if item_type.nil?
248
248
 
249
249
  result.documentation = item_type.doc unless item_type.doc.nil?
250
- unless item_type.nil? || item_type.signatures.count.zero?
250
+ unless item_type.nil? || item_type.signatures.none?
251
251
  result.detail = item_type.signatures.map(&:key).join("\n\n")
252
252
  # The signature provider should handle suggestions after this, so just place the cursor ready for an opening bracket
253
253
  result.insertText = data['name'].to_s
@@ -87,9 +87,10 @@ module PuppetLanguageServer
87
87
  result
88
88
  end
89
89
 
90
- private
91
-
92
90
  VALID_TOKEN_TYPES = %i[NAME STRING SSTRING].freeze
91
+ private_constant :VALID_TOKEN_TYPES
92
+
93
+ private
93
94
 
94
95
  def find_token_by_location(tokens, line, character)
95
96
  return nil if tokens.empty?
@@ -194,7 +194,7 @@ module PuppetLanguageServer
194
194
  def self.get_puppet_class_content(item_class)
195
195
  content = "**#{item_class.key}** Resource"
196
196
  content += "\n\n#{item_class.doc}" unless item_class.doc.nil?
197
- unless item_class.parameters.count.zero?
197
+ unless item_class.parameters.none?
198
198
  content += "\n\n---\n"
199
199
  item_class.parameters.sort.each do |name, _param|
200
200
  content += "* #{name}\n"
@@ -78,7 +78,7 @@ module PuppetLanguageServer
78
78
  signature_number = func_info.signatures.find_index { |sig| sig.parameters.count >= func_arg_count }
79
79
 
80
80
  # If we still don't know the signature number then assume it's the first one
81
- signature_number = 0 if signature_number.nil? && func_info.signatures.count > 0
81
+ signature_number = 0 if signature_number.nil? && func_info.signatures.any?
82
82
 
83
83
  response.activeSignature = signature_number unless signature_number.nil?
84
84
  response.activeParameter = param_number
@@ -110,10 +110,10 @@ module PuppetLanguageServer
110
110
  # Is the cursor on or beyond the closing bracket? then we are not in any parameters
111
111
  return nil if char_offset >= function_offset + function_length
112
112
  # Does the function even have arguments? then the cursor HAS to be in the first parameter
113
- return 0 if function_ast_object.arguments.count.zero?
113
+ return 0 if function_ast_object.arguments.none?
114
114
 
115
115
  # Is the cursor within any of the function argument locations? if so, return the parameter number we're in
116
- param_number = function_ast_object.arguments.find_index { |arg| char_offset >= arg.offset && char_offset <= arg.offset + arg.length }
116
+ param_number = function_ast_object.arguments.find_index { |arg| char_offset.between?(arg.offset, arg.offset + arg.length) }
117
117
  return param_number unless param_number.nil?
118
118
 
119
119
  # So now we know the char_offset exists outside any of the locators. Check the extremities
@@ -18,10 +18,17 @@ module PuppetLanguageServer
18
18
  init_puppet_lint(session_state.documents.store_root_path, ['--fix', '--relative'])
19
19
 
20
20
  linter = PuppetLint::Checks.new
21
- problems = linter.run(lint_filename(document_uri), content)
21
+ lint_aborted = false
22
+ problems = begin
23
+ linter.run(lint_filename(document_uri), content)
24
+ rescue SystemExit
25
+ PuppetLanguageServer.log_message(:error, '(fix_validate_errors) puppet-lint aborted')
26
+ lint_aborted = true
27
+ nil
28
+ end
22
29
  problems_fixed = problems.nil? ? 0 : problems.count { |item| item[:kind] == :fixed }
23
30
 
24
- [problems_fixed, linter.manifest]
31
+ [problems_fixed, lint_aborted ? content : linter.manifest]
25
32
  end
26
33
 
27
34
  def self.validate(session_state, content, options = {})
@@ -38,7 +45,12 @@ module PuppetLanguageServer
38
45
 
39
46
  begin
40
47
  linter = PuppetLint::Checks.new
41
- problems = linter.run(lint_filename(options[:document_uri]), content)
48
+ problems = begin
49
+ linter.run(lint_filename(options[:document_uri]), content)
50
+ rescue SystemExit
51
+ PuppetLanguageServer.log_message(:error, '(textDocument/validation) puppet-lint aborted')
52
+ nil
53
+ end
42
54
  unless problems.nil?
43
55
  problems.each do |problem|
44
56
  # Syntax errors are better handled by the puppet parser, not puppet lint
@@ -178,7 +178,7 @@ module PuppetLanguageServer
178
178
  file_uri = json_rpc_message.params['textDocument']['uri']
179
179
  case documents.document_type(file_uri)
180
180
  when :manifest
181
- PuppetLanguageServer::Manifest::FoldingProvider.instance.folding_ranges(documents.document_tokens(file_uri))
181
+ PuppetLanguageServer::Manifest::FoldingProvider.instance.folding_ranges(documents.document_tokens(file_uri), language_client.folding_range_show_last_line)
182
182
  else
183
183
  raise "Unable to provide folding ranages on #{file_uri}"
184
184
  end
@@ -6,8 +6,13 @@ module PuppetLanguageServer
6
6
  line_offset = line_offsets[line_num]
7
7
  raise if line_offset.nil?
8
8
 
9
+ start_offset = line_offset + char_num
10
+ # Never remove more characters than exist before the removal point, as a
11
+ # negative slice length would return nil and break string concatenation.
12
+ num_chars_to_remove = num_chars_to_remove.clamp(0, start_offset)
13
+
9
14
  # Remove the offending character
10
- content.slice(0, line_offset + char_num - num_chars_to_remove) + content.slice(line_offset + char_num, content.length - num_chars_to_remove)
15
+ content.slice(0, start_offset - num_chars_to_remove) + content.slice(start_offset, content.length - num_chars_to_remove)
11
16
  end
12
17
 
13
18
  def self.remove_char_at(content, line_offsets, line_num, char_num)
@@ -86,15 +91,10 @@ module PuppetLanguageServer
86
91
  when :remove_word
87
92
  next if line_num.zero? && char_num.zero?
88
93
 
89
- next_char = get_char_at(content, line_offsets, line_num, char_num)
90
-
91
- while /[[:word:]]/ =~ next_char
92
- move_offset -= 1
93
- next_char = get_char_at(content, line_offsets, line_num, char_num + move_offset)
94
-
95
- break if char_num + move_offset < 0
96
- end
94
+ start_char = char_num
95
+ start_char -= 1 while start_char.positive? && /[[:word:]]/ =~ get_char_at(content, line_offsets, line_num, start_char)
97
96
 
97
+ move_offset = start_char - char_num
98
98
  new_content = remove_chars_starting_at(content, line_offsets, line_num, char_num, -move_offset)
99
99
  when :try_quotes
100
100
  # Perhaps try inserting double quotes. Useful in empty arrays or during variable assignment
@@ -143,7 +143,7 @@ module PuppetLanguageServer
143
143
  private_class_method :resolver_cache
144
144
 
145
145
  def self.document_error_to_diagnostic(document_uri, error)
146
- if error.puppetfile_modules.count.zero?
146
+ if error.puppetfile_modules.none?
147
147
  return LSP::Diagnostic.new(
148
148
  'severity' => LSP::DiagnosticSeverity::ERROR,
149
149
  'range' => LSP.create_range(0, 0, 0, max_line_length),
@@ -149,17 +149,17 @@ module PuppetLanguageServer
149
149
  end
150
150
 
151
151
  # Workspace management
152
- WORKSPACE_CACHE_TTL_SECONDS ||= 60
152
+ WORKSPACE_CACHE_TTL_SECONDS = 60
153
153
  def initialize_store(options = {})
154
154
  @workspace_path = options[:workspace]
155
155
  @workspace_info_cache = {
156
- expires: Time.new - 120
156
+ expires: Time.now - 120
157
157
  }
158
158
  end
159
159
 
160
160
  def expire_store_information
161
161
  @doc_mutex.synchronize do
162
- @workspace_info_cache[:expires] = Time.new - 120
162
+ @workspace_info_cache[:expires] = Time.now - 120
163
163
  end
164
164
  end
165
165
 
@@ -208,7 +208,7 @@ module PuppetLanguageServer
208
208
  end
209
209
 
210
210
  def store_details
211
- return @workspace_info_cache unless @workspace_info_cache[:never_expires] || @workspace_info_cache[:expires] < Time.new
211
+ return @workspace_info_cache unless @workspace_info_cache[:never_expires] || @workspace_info_cache[:expires] < Time.now
212
212
 
213
213
  # TTL has expired, time to calculate the document store details
214
214
 
@@ -232,7 +232,7 @@ module PuppetLanguageServer
232
232
  new_cache[:has_environmentconf] = file_exist?(File.join(root_path, 'environment.conf'))
233
233
  end
234
234
  end
235
- new_cache[:expires] = Time.new + WORKSPACE_CACHE_TTL_SECONDS
235
+ new_cache[:expires] = Time.now + WORKSPACE_CACHE_TTL_SECONDS
236
236
 
237
237
  @doc_mutex.synchronize do
238
238
  @workspace_info_cache = new_cache
@@ -8,8 +8,8 @@ module PuppetLanguageServer
8
8
  # Client settings
9
9
  attr_reader :format_on_type
10
10
 
11
- DEFAULT_FORMAT_ON_TYPE_ENABLE = false
12
- DEFAULT_FORMAT_ON_TYPE_FILESIZE_LIMIT = 4096
11
+ DEFAULT_FORMAT_ON_TYPE_ENABLE = true
12
+ DEFAULT_FORMAT_ON_TYPE_FILESIZE_LIMIT = 16_384
13
13
  DEFAULT_FOLDING_RANGE_ENABLE = true # Default is true as per VS Code
14
14
  DEFAULT_FOLDING_RANGE_SHOW_LAST_LINE = true # Default is true as per VS Code
15
15
  DEFAULT_VALIDATE_RESOLVE_PUPPETFILES = true
@@ -42,7 +42,7 @@ module PuppetLanguageServer
42
42
 
43
43
  def send_configuration_request
44
44
  params = LSP::ConfigurationParams.new.from_h!('items' => [])
45
- params.items << LSP::ConfigurationItem.new.from_h!('section' => 'puppet')
45
+ params.items << LSP::ConfigurationItem.new.from_h!('section' => 'openvox')
46
46
 
47
47
  message_handler.protocol.send_client_request('workspace/configuration', params)
48
48
  true
@@ -54,7 +54,7 @@ module PuppetLanguageServer
54
54
 
55
55
  def parse_lsp_configuration_settings!(settings = {})
56
56
  # format on type enabled
57
- value = to_boolean(safe_hash_traverse(settings, 'puppet', 'editorService', 'formatOnType', 'enable'), DEFAULT_FORMAT_ON_TYPE_ENABLE)
57
+ value = to_boolean(safe_hash_traverse(settings, 'openvox', 'editorService', 'formatOnType', 'enable'), DEFAULT_FORMAT_ON_TYPE_ENABLE)
58
58
  unless value == @format_on_type # Ummm no.
59
59
  # Is dynamic registration available?
60
60
  if client_capability('textDocument', 'onTypeFormatting', 'dynamicRegistration') == true
@@ -67,18 +67,18 @@ module PuppetLanguageServer
67
67
  @format_on_type = value
68
68
  end
69
69
  # format on type file size
70
- @format_on_type_filesize_limit = to_integer(safe_hash_traverse(settings, 'puppet', 'editorService', 'formatOnType', 'maxFileSize'), DEFAULT_FORMAT_ON_TYPE_FILESIZE_LIMIT, 0)
70
+ @format_on_type_filesize_limit = to_integer(safe_hash_traverse(settings, 'openvox', 'editorService', 'formatOnType', 'maxFileSize'), DEFAULT_FORMAT_ON_TYPE_FILESIZE_LIMIT, 0)
71
71
 
72
72
  # use puppetfile resolver
73
- @use_puppetfile_resolver = to_boolean(safe_hash_traverse(settings, 'puppet', 'validate', 'resolvePuppetfiles'), DEFAULT_VALIDATE_RESOLVE_PUPPETFILES)
73
+ @use_puppetfile_resolver = to_boolean(safe_hash_traverse(settings, 'openvox', 'validate', 'resolvePuppetfiles'), DEFAULT_VALIDATE_RESOLVE_PUPPETFILES)
74
74
 
75
75
  # folding range enabled
76
- value = to_boolean(safe_hash_traverse(settings, 'puppet', 'editorService', 'foldingRange', 'enable'), DEFAULT_FOLDING_RANGE_ENABLE) && PuppetLanguageServer::ServerCapabilites.folding_provider_supported?
76
+ value = to_boolean(safe_hash_traverse(settings, 'openvox', 'editorService', 'foldingRange', 'enable'), DEFAULT_FOLDING_RANGE_ENABLE) && PuppetLanguageServer::ServerCapabilites.folding_provider_supported?
77
77
  unless value == @folding_range # Ummm no.
78
78
  # Is dynamic registration available?
79
79
  if client_capability('textDocument', 'foldingRange', 'dynamicRegistration') == true
80
80
  if value
81
- register_capability('textDocument/foldingRange', PuppetLanguageServer::ServerCapabilites.document_on_type_formatting_options)
81
+ register_capability('textDocument/foldingRange', PuppetLanguageServer::ServerCapabilites.folding_range_provider_options)
82
82
  else
83
83
  unregister_capability('textDocument/foldingRange')
84
84
  end
@@ -86,7 +86,7 @@ module PuppetLanguageServer
86
86
  @folding_range = value
87
87
  end
88
88
  # folding range last line display
89
- @folding_range_show_last_line = to_boolean(safe_hash_traverse(settings, 'puppet', 'editorService', 'foldingRange', 'showLastLine'), DEFAULT_FOLDING_RANGE_SHOW_LAST_LINE)
89
+ @folding_range_show_last_line = to_boolean(safe_hash_traverse(settings, 'openvox', 'editorService', 'foldingRange', 'showLastLine'), DEFAULT_FOLDING_RANGE_SHOW_LAST_LINE)
90
90
  end
91
91
 
92
92
  def capability_registrations(method)
@@ -100,7 +100,7 @@ module PuppetLanguageServer
100
100
 
101
101
  PuppetLanguageServer.log_message(:info, "Attempting to dynamically register the #{method} method with id #{id}")
102
102
 
103
- if @registrations[method] && @registrations[method].select { |i| i[:state] == :pending }.count > 0
103
+ if @registrations[method]&.any? { |registration| registration[:state] == :pending }
104
104
  # The protocol doesn't specify whether this is allowed and is probably per client specific. For the moment we will allow
105
105
  # the registration to be sent but log a message that something may be wrong.
106
106
  PuppetLanguageServer.log_message(:warn, "A dynamic registration/deregistration for the #{method} method is already in progress")
@@ -135,7 +135,7 @@ module PuppetLanguageServer
135
135
  reg[:state] = :pending
136
136
  end
137
137
 
138
- if params.unregisterations.count.zero?
138
+ if params.unregisterations.none?
139
139
  PuppetLanguageServer.log_message(:debug, "Nothing to deregister for the #{method} method")
140
140
  return true
141
141
  end
@@ -17,7 +17,8 @@ module PuppetLanguageServer
17
17
  include Base
18
18
 
19
19
  def to_json(*options)
20
- ::JSON.generate(to_h, options)
20
+ # JSON 2.21 requires an options hash, so expand the captured arguments instead of passing their array.
21
+ ::JSON.generate(to_h, *options)
21
22
  end
22
23
 
23
24
  def from_json!(json_string)
@@ -32,8 +33,11 @@ module PuppetLanguageServer
32
33
  class BaseClass
33
34
  include Base
34
35
 
36
+ IGNORED_INSTANCE_METHODS = %i[to_h to_json].freeze
37
+
35
38
  def to_json(*options)
36
- to_h.to_json(options)
39
+ # JSON 2.21 requires an options hash, so expand the captured arguments instead of passing their array.
40
+ to_h.to_json(*options)
37
41
  end
38
42
 
39
43
  def from_json!(json_string)
@@ -46,7 +50,7 @@ module PuppetLanguageServer
46
50
  self.class
47
51
  .instance_methods(false)
48
52
  .reject { |name| name.to_s.end_with?('=', '!') }
49
- .reject { |name| %i[to_h to_json].include?(name) }
53
+ .reject { |name| IGNORED_INSTANCE_METHODS.include?(name) }
50
54
  .each do |method_name|
51
55
  return false unless send(method_name) == other.send(method_name)
52
56
  end
@@ -59,7 +63,7 @@ module PuppetLanguageServer
59
63
  self.class
60
64
  .instance_methods(false)
61
65
  .reject { |name| name.to_s.end_with?('=', '!') }
62
- .reject { |name| %i[to_h to_json].include?(name) }
66
+ .reject { |name| IGNORED_INSTANCE_METHODS.include?(name) }
63
67
  .each do |method_name|
64
68
  return false unless send(method_name).eql?(other.send(method_name))
65
69
  end
@@ -70,7 +74,7 @@ module PuppetLanguageServer
70
74
  props = self.class
71
75
  .instance_methods(false)
72
76
  .reject { |name| name.to_s.end_with?('=', '!') }
73
- .reject { |name| %i[to_h to_json].include?(name) }
77
+ .reject { |name| IGNORED_INSTANCE_METHODS.include?(name) }
74
78
  .map do |method_name|
75
79
  send(method_name).hash
76
80
  end
@@ -120,7 +124,8 @@ module PuppetLanguageServer
120
124
  include Base
121
125
 
122
126
  def to_json(*options)
123
- "[#{map { |item| item.to_json(options) }.join(',')}]"
127
+ # JSON 2.21 requires an options hash, so expand the captured arguments instead of passing their array.
128
+ "[#{map { |item| item.to_json(*options) }.join(',')}]"
124
129
  end
125
130
 
126
131
  def from_json!(json_string)
@@ -141,11 +146,12 @@ module PuppetLanguageServer
141
146
  attr_accessor :vertices, :edges, :error_content
142
147
 
143
148
  def to_json(*options)
149
+ # JSON 2.21 requires an options hash, so expand the captured arguments instead of passing their array.
144
150
  {
145
151
  'vertices' => vertices,
146
152
  'edges' => edges,
147
153
  'error_content' => error_content
148
- }.to_json(options)
154
+ }.to_json(*options)
149
155
  end
150
156
 
151
157
  def from_json!(json_string)
@@ -398,7 +404,8 @@ module PuppetLanguageServer
398
404
  end
399
405
 
400
406
  def to_json(*options)
401
- to_h.to_json(options)
407
+ # JSON 2.21 requires an options hash, so expand the captured arguments instead of passing their array.
408
+ to_h.to_json(*options)
402
409
  end
403
410
 
404
411
  def from_json!(json_string)
@@ -448,7 +455,8 @@ module PuppetLanguageServer
448
455
  end
449
456
 
450
457
  def to_json(*options)
451
- @aggregate.to_json(options)
458
+ # JSON 2.21 requires an options hash, so expand the captured arguments instead of passing their array.
459
+ @aggregate.to_json(*options)
452
460
  end
453
461
 
454
462
  def from_json!(json_string)
@@ -469,8 +477,6 @@ module PuppetLanguageServer
469
477
  @aggregate.each(&block)
470
478
  end
471
479
 
472
- private
473
-
474
480
  # When adding a new metadata item:
475
481
  # - Add to the information to this hash
476
482
  # - Add a method to access the aggregate
@@ -492,6 +498,9 @@ module PuppetLanguageServer
492
498
  list_class: PuppetTypeList
493
499
  }
494
500
  }.freeze
501
+ private_constant :METADATA_LIST
502
+
503
+ private
495
504
 
496
505
  def list_for_object_class(klass)
497
506
  METADATA_LIST.each do |name, info|
@@ -13,8 +13,8 @@ module PuppetLanguageServerSidecar
13
13
 
14
14
  @cache_dir = File.join(Dir.tmpdir, 'puppet-vscode-cache')
15
15
  begin
16
- Dir.mkdir(@cache_dir) unless Dir.exist?(@cache_dir)
17
- rescue Errno::ENOENT => e
16
+ FileUtils.mkdir_p(@cache_dir)
17
+ rescue SystemCallError => e
18
18
  PuppetLanguageServerSidecar.log_message(:error, "[PuppetLanguageServerSidecar::Cache::FileSystem] An error occured while creating file cache. Disabling cache: #{e}")
19
19
  @cache_dir = nil
20
20
  end
@@ -12,6 +12,7 @@ module PuppetLanguageServerSidecar
12
12
  # Object - While useful, typically only needed when extended the type system as opposed to general use
13
13
  # TypeSet - While useful, typically only needed when extended the type system as opposed to general use
14
14
  IGNORE_DATATYPE_NAMES = %w[TypeReference TypeAlias Object TypeSet ObjectTypeExten Iterable AbstractTimeData TypeWithContained].freeze
15
+ IGNORE_TYPE_NAMES = %w[whit component].freeze
15
16
 
16
17
  # Resource Face
17
18
  def self.get_puppet_resource(typename, title = nil)
@@ -107,7 +108,7 @@ module PuppetLanguageServerSidecar
107
108
  next unless object_types.include?(:type)
108
109
 
109
110
  file_doc.types.each do |item|
110
- result.append!(item) unless %w[whit component].include?(name)
111
+ result.append!(item) unless IGNORE_TYPE_NAMES.include?(name)
111
112
  finder.temp_file.unlink if item.key == 'file' && File.exist?(finder.temp_file.path) # Remove the temp_file.rb if it exists
112
113
  end
113
114
  end
@@ -163,9 +164,7 @@ module PuppetLanguageServerSidecar
163
164
  # Path to the environment
164
165
  @env_path = puppet_env.configuration.path_to_env
165
166
  # Path to the puppet installation
166
- @puppet_path = if puppet_env.loaders.nil? # No loaders have been created yet
167
- nil
168
- elsif puppet_env.loaders.puppet_system_loader.nil?
167
+ @puppet_path = if puppet_env.loaders.nil? || puppet_env.loaders.puppet_system_loader.nil? # No loaders have been created yet
169
168
  nil
170
169
  elsif puppet_env.loaders.puppet_system_loader.lib_root?
171
170
  File.join(puppet_env.loaders.puppet_system_loader.path, '..')
@@ -260,7 +259,7 @@ module PuppetLanguageServerSidecar
260
259
  def all_object_info
261
260
  {
262
261
  class: [
263
- { relative_dir: 'manifests', glob: '/**/*.pp' } # Pretty much everything in most modules
262
+ { relative_dir: 'manifests', glob: '/**/*.pp' } # Pretty much everything in most modules
264
263
  ],
265
264
  datatype: [
266
265
  { relative_dir: 'lib/puppet/datatypes', glob: '/**/*.rb' }, # Custom Data Types
@@ -272,7 +271,7 @@ module PuppetLanguageServerSidecar
272
271
  { relative_dir: 'lib/puppet/parser/functions', glob: '/**/*.rb' } # Contains functions written in Ruby for the legacy Puppet::Parser::Functions API
273
272
  ],
274
273
  type: [
275
- { relative_dir: 'lib/puppet/type', glob: '/{,file/}*.rb' } # Contains Puppet resource types. Resource types like `file` can live in subdirs, hence the glob
274
+ { relative_dir: 'lib/puppet/type', glob: '/{,file/}*.rb' } # Contains Puppet resource types. Resource types like `file` can live in subdirs, hence the glob
276
275
  ]
277
276
  }
278
277
  end
@@ -7,7 +7,7 @@ module PuppetLanguageServerSidecar
7
7
 
8
8
  begin
9
9
  node_graph = compile_to_pretty_relationship_graph(content)
10
- if node_graph.vertices.count.zero?
10
+ if node_graph.vertices.none?
11
11
  result.set_error('There were no resources created in the node graph. Is there an include statement missing?')
12
12
  return result
13
13
  end
@@ -60,15 +60,15 @@ module PuppetLanguageServerSidecar
60
60
  # Remove vertexes which just clutter the graph
61
61
 
62
62
  # Remove all of the Puppet::Type::Whit nodes. This is an internal only class
63
- list = graph.vertices.select { |node| node.is_a?(Puppet::Type::Whit) }
63
+ list = graph.vertices.grep(Puppet::Type::Whit)
64
64
  list.each { |node| graph.remove_vertex!(node) }
65
65
 
66
66
  # Remove all of the Puppet::Type::Schedule nodes
67
- list = graph.vertices.select { |node| node.is_a?(Puppet::Type::Schedule) }
67
+ list = graph.vertices.grep(Puppet::Type::Schedule)
68
68
  list.each { |node| graph.remove_vertex!(node) }
69
69
 
70
70
  # Remove all of the Puppet::Type::Filebucket nodes
71
- list = graph.vertices.select { |node| node.is_a?(Puppet::Type::Filebucket) }
71
+ list = graph.vertices.grep(Puppet::Type::Filebucket)
72
72
  list.each { |node| graph.remove_vertex!(node) }
73
73
 
74
74
  graph
@@ -370,7 +370,8 @@ module PuppetLanguageServerSidecar
370
370
  end
371
371
 
372
372
  def to_json(*options)
373
- JSON.generate(to_h, options)
373
+ # JSON 2.21 requires an options hash, so expand the captured arguments instead of passing their array.
374
+ JSON.generate(to_h, *options)
374
375
  end
375
376
 
376
377
  # Deserialisation
@@ -17,11 +17,11 @@ module PuppetLanguageServerSidecar
17
17
  @root_path
18
18
  end
19
19
 
20
- def self.has_module_metadata? # rubocop:disable Naming/PredicateName
20
+ def self.has_module_metadata? # rubocop:disable Naming/PredicatePrefix
21
21
  @has_module_metadata
22
22
  end
23
23
 
24
- def self.has_environmentconf? # rubocop:disable Naming/PredicateName
24
+ def self.has_environmentconf? # rubocop:disable Naming/PredicatePrefix
25
25
  @has_environmentconf
26
26
  end
27
27
 
@@ -65,7 +65,7 @@ module PuppetEditorServices
65
65
  request_message, send(method_name, protocol.connection.id, request_message)
66
66
  )
67
67
  )
68
- rescue StandardError => e
68
+ rescue StandardError, SystemExit => e
69
69
  unhandled_exception(e, source: :request, message: request_message)
70
70
  end
71
71
  return true
@@ -87,7 +87,7 @@ module PuppetEditorServices
87
87
  if respond_to?(method_name.intern)
88
88
  begin
89
89
  send(method_name, protocol.connection.id, notification_message)
90
- rescue StandardError => e
90
+ rescue StandardError, SystemExit => e
91
91
  unhandled_exception(e, source: :notification, message: notification_message)
92
92
  end
93
93
  return true
@@ -114,7 +114,7 @@ module PuppetEditorServices
114
114
  if respond_to?(method_name.intern)
115
115
  begin
116
116
  send(method_name, protocol.connection.id, response_message, original_request)
117
- rescue StandardError => e
117
+ rescue StandardError, SystemExit => e
118
118
  unhandled_exception(e, source: :response, message: response_message)
119
119
  end
120
120
  return true
@@ -20,7 +20,8 @@ module PuppetEditorServices
20
20
  end
21
21
 
22
22
  def to_json(*options)
23
- to_h.to_json(options)
23
+ # JSON 2.21 requires an options hash, so expand the captured arguments instead of passing their array.
24
+ to_h.to_json(*options)
24
25
  end
25
26
 
26
27
  def to_h
@@ -25,7 +25,8 @@ module PuppetEditorServices
25
25
  end
26
26
 
27
27
  def to_json(*options)
28
- to_h.to_json(options)
28
+ # JSON 2.21 requires an options hash, so expand the captured arguments instead of passing their array.
29
+ to_h.to_json(*options)
29
30
  end
30
31
 
31
32
  def to_h
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'io/wait'
3
4
  require 'puppet_editor_services/logging'
4
5
  require 'puppet_editor_services/server/base'
5
6
  require 'puppet_editor_services/connection/stdio'
@@ -59,8 +60,7 @@ module PuppetEditorServices
59
60
  end
60
61
 
61
62
  def pipe_is_readable?(stream, timeout = 0.5)
62
- read_ready = IO.select([stream], [], [], timeout)
63
- read_ready && stream == read_ready[0][0]
63
+ !stream.wait_readable(timeout).nil?
64
64
  end
65
65
 
66
66
  def read_from_pipe(pipe, timeout = 0.1, &)
@@ -3,8 +3,6 @@
3
3
  require 'socket'
4
4
  require 'openssl'
5
5
 
6
- # frozen_string_literal: true
7
-
8
6
  require 'puppet_editor_services/logging'
9
7
  require 'puppet_editor_services/server/base'
10
8
  require 'puppet_editor_services/connection/tcp'
@@ -340,9 +338,8 @@ module PuppetEditorServices
340
338
  # @api private
341
339
  def clear_connections
342
340
  # Using a SymbolProc here does not work
343
- # rubocop:disable Style/SymbolProc
341
+ # rubocop:disable-next Style/SymbolProc
344
342
  self.class.c_locker.synchronize { self.class.io_connection_dic.delete_if { |c| c.closed? } }
345
- # rubocop:enable Style/SymbolProc
346
343
  end
347
344
  end
348
345
  end