Skip to content

Commit 685ad8e

Browse files
committed
(GH-163) Allow the aggregate to be used in all cases
Previously the metadata aggregate action could only be used with the puppetstrings feature flag. However it is also very useful for normal operation. This commit changes the action to be valid, and adds tests for this scenario.
1 parent 0f6a609 commit 685ad8e

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
lines changed

lib/puppet-languageserver/sidecar_protocol.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,11 @@ def types
385385
@aggregate[:types]
386386
end
387387

388+
def concat!(array)
389+
return if array.nil? || array.empty?
390+
array.each { |item| append!(item) }
391+
end
392+
388393
def append!(obj)
389394
list_for_object_class(obj.class) << obj
390395
end

lib/puppet_languageserver_sidecar.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ def self.inject_workspace_as_environment
256256
def self.execute(options)
257257
use_puppet_strings = featureflag?('puppetstrings')
258258

259+
log_message(:debug, "Executing #{options[:action]} action")
259260
case options[:action].downcase
260261
when 'noop'
261262
[]
@@ -265,8 +266,7 @@ def self.execute(options)
265266
if use_puppet_strings
266267
PuppetLanguageServerSidecar::PuppetHelper.retrieve_via_puppet_strings(cache, :object_types => PuppetLanguageServerSidecar::PuppetHelper.available_documentation_types)
267268
else
268-
log_message(:warn, 'The default_aggregate action is only supported with the puppetstrings feature flag')
269-
{}
269+
create_aggregate(cache)
270270
end
271271

272272
when 'default_classes'
@@ -326,8 +326,7 @@ def self.execute(options)
326326
:object_types => PuppetLanguageServerSidecar::PuppetHelper.available_documentation_types,
327327
:root_path => PuppetLanguageServerSidecar::Workspace.root_path)
328328
else
329-
log_message(:warn, 'The workspace_aggregate action is only supported with the puppetstrings feature flag')
330-
{}
329+
create_aggregate(PuppetLanguageServerSidecar::Cache::Null.new, PuppetLanguageServerSidecar::Workspace.root_path)
331330
end
332331

333332
when 'workspace_classes'
@@ -374,6 +373,15 @@ def self.execute(options)
374373
end
375374
end
376375

376+
def self.create_aggregate(cache, root_path = nil)
377+
result = PuppetLanguageServer::Sidecar::Protocol::AggregateMetadata.new
378+
result.concat!(PuppetLanguageServerSidecar::PuppetHelper.retrieve_types(cache, :root_path => root_path))
379+
result.concat!(PuppetLanguageServerSidecar::PuppetHelper.retrieve_functions(cache, :root_path => root_path))
380+
result.concat!(PuppetLanguageServerSidecar::PuppetHelper.retrieve_classes(cache, :root_path => root_path))
381+
result
382+
end
383+
private_class_method :create_aggregate
384+
377385
def self.output(result, options)
378386
if options[:output].nil? || options[:output].empty?
379387
STDOUT.binmode

spec/languageserver-sidecar/integration/puppet-languageserver-sidecar/puppet-languageserver-sidecar_spec.rb

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,17 @@ def with_temporary_file(content)
4848
describe 'when running default_aggregate action' do
4949
let (:cmd_options) { ['--action', 'default_aggregate'] }
5050

51-
it 'should return an empty hash' do
51+
it 'should return a deserializable aggregate object with all default metadata' do
5252
result = run_sidecar(cmd_options)
53+
deserial = PuppetLanguageServer::Sidecar::Protocol::AggregateMetadata.new
54+
expect { deserial.from_json!(result) }.to_not raise_error
55+
56+
# The contents of the result are tested later
5357

54-
expect(result).to eq('{}')
58+
# There should be at least one item per list in the aggregate
59+
deserial.each_list do |_, v|
60+
expect(v.count).to be > 0
61+
end
5562
end
5663
end
5764

@@ -139,10 +146,17 @@ def with_temporary_file(content)
139146
describe 'when running workspace_aggregate action' do
140147
let (:cmd_options) { ['--action', 'workspace_aggregate', '--local-workspace', workspace] }
141148

142-
it 'should return an empty hash' do
149+
it 'should return a deserializable aggregate object with all workspace metadata' do
143150
result = run_sidecar(cmd_options)
151+
deserial = PuppetLanguageServer::Sidecar::Protocol::AggregateMetadata.new
152+
expect { deserial.from_json!(result) }.to_not raise_error
153+
154+
# The contents of the result are tested later
144155

145-
expect(result).to eq('{}')
156+
# There should be at least one item per list in the aggregate
157+
deserial.each_list do |_, v|
158+
expect(v.count).to be > 0
159+
end
146160
end
147161
end
148162

@@ -235,10 +249,17 @@ def with_temporary_file(content)
235249
describe 'when running workspace_aggregate action' do
236250
let (:cmd_options) { ['--action', 'workspace_aggregate', '--local-workspace', workspace] }
237251

238-
it 'should return an empty hash' do
252+
it 'should return a deserializable aggregate object with all workspace metadata' do
239253
result = run_sidecar(cmd_options)
254+
deserial = PuppetLanguageServer::Sidecar::Protocol::AggregateMetadata.new
255+
expect { deserial.from_json!(result) }.to_not raise_error
240256

241-
expect(result).to eq('{}')
257+
# The contents of the result are tested later
258+
259+
# There should be at least one item per list in the aggregate
260+
deserial.each_list do |_, v|
261+
expect(v.count).to be > 0
262+
end
242263
end
243264
end
244265

0 commit comments

Comments
 (0)