Skip to content

Commit

Permalink
Merge pull request #376 from puppetlabs/CAT-1670-fix_allignment
Browse files Browse the repository at this point in the history
CAT-1670 - Fix onTypeFormatting due to undefined variable json_rpc_handler
  • Loading branch information
david22swan authored Apr 24, 2024
2 parents f36499a + 2126f5e commit 3b7fecb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
13 changes: 2 additions & 11 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-01-23 14:26:06 UTC using RuboCop version 1.50.2.
# on 2024-04-24 11:01:50 UTC using RuboCop version 1.50.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -50,7 +50,7 @@ Metrics/BlockLength:
# Offense count: 12
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 330
Max: 333

# Offense count: 53
# Configuration parameters: AllowedMethods, AllowedPatterns.
Expand Down Expand Up @@ -103,15 +103,6 @@ Security/IoMethods:
Exclude:
- 'lib/puppet-debugserver/debug_session/break_points.rb'

# Offense count: 5
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowedMethods, AllowedPatterns.
# AllowedMethods: ==, equal?, eql?
# Style/ClassEqualityComparison:
# Exclude:
# - 'lib/puppet-languageserver/manifest/definition_provider.rb'
# - 'lib/puppet-languageserver/manifest/signature_provider.rb'

# Offense count: 104
# Configuration parameters: AllowedConstants.
Style/Documentation:
Expand Down
9 changes: 6 additions & 3 deletions lib/puppet-languageserver/message_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,12 @@ def notification_initialized(_, _json_rpc_message)
# Raise a warning if the Puppet version is mismatched
server_options = protocol.connection.server.server_options
unless server_options[:puppet_version].nil? || server_options[:puppet_version] == Puppet.version
json_rpc_handler.send_show_message_notification(
LSP::MessageType::WARNING,
"Unable to use Puppet version '#{server_options[:puppet_version]}' as it is not available. Using version '#{Puppet.version}' instead."
protocol.encode_and_send(
::PuppetEditorServices::Protocol::JsonRPCMessages.new_notification(
'window/showMessage',
'type' => LSP::MessageType::WARNING,
'message' => "Unable to use Puppet version '#{server_options[:puppet_version]}' as it is not available. Using version '#{Puppet.version}' instead."
)
)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,40 @@ def client_cap_hash(client_cap_string, dynamic_reg)
)
end

describe 'PuppetLanguageServer::MessageHandler' do
let(:server_options) { { puppet_version: '5.5.1' } }
let(:server) { double('PuppetEditorServices::Server') }
let(:connection) { double('PuppetEditorServices::Protocol::Connection', id: 'some_id') }
let(:protocol) { double('PuppetEditorServices::Protocol::JsonRPC') }
let(:handler_object) { PuppetLanguageServer::MessageHandler.new(protocol) }

before do
allow(server).to receive(:server_options).and_return(server_options)
allow(connection).to receive(:server).and_return(server)
allow(protocol).to receive(:connection).and_return(connection)
end

context 'When receiving a notification' do
context '.notification_initialized' do
it 'sends a warning message when Puppet versions are mismatched' do
allow(Puppet).to receive(:version).and_return('6.0.0')

expected_message = {
'type' => LSP::MessageType::WARNING,
'message' => "Unable to use Puppet version '#{server_options[:puppet_version]}' as it is not available. Using version '#{Puppet.version}' instead."
}

expect(protocol).to receive(:encode_and_send) do |arg|
expect(arg).to be_a(PuppetEditorServices::Protocol::JsonRPCMessages::NotificationMessage)
expect(arg.params).to eq(expected_message)
end

handler_object.notification_initialized(nil, nil)
end
end
end
end

# initialized - https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#initialized
describe '.notification_initialized' do
let(:notification_method) { 'initialized' }
Expand Down

0 comments on commit 3b7fecb

Please sign in to comment.