Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAT-1670 - Fix onTypeFormatting due to undefined variable json_rpc_handler #376

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
# 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."
)

Check warning on line 308 in lib/puppet-languageserver/message_handler.rb

View check run for this annotation

Codecov / codecov/patch

lib/puppet-languageserver/message_handler.rb#L303-L308

Added lines #L303 - L308 were not covered by tests
)
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
Loading