Skip to content

Commit

Permalink
(puppetlabsGH-221) Puppet Node Graph to json
Browse files Browse the repository at this point in the history
This commit changes the Node Graph method to return a json data hash
instead of a dot graph to support puppetlabs/puppet-vscode#613
  • Loading branch information
jpogran committed Mar 11, 2020
1 parent 8f012e9 commit 522e7c5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
9 changes: 1 addition & 8 deletions lib/puppet-languageserver-sidecar/puppet_parser_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@ def self.compile_node_graph(content)
result = PuppetLanguageServerSidecar::Protocol::NodeGraph.new

begin
# The fontsize is inserted in the puppet code. Need to remove it so the client can render appropriately. Need to
# set it to blank. The graph label is set to editorservices so that we can do text replacement client side to inject the
# appropriate styling.
options = {
'fontsize' => '""',
'name' => 'editorservices'
}
node_graph = compile_to_pretty_relationship_graph(content)
if node_graph.vertices.count.zero?
result.set_error('There were no resources created in the node graph. Is there an include statement missing?')
else
result.dot_content = node_graph.to_dot(options)
result.content = JSON.generate(node_graph.to_data_hash)
end
rescue StandardError => e
result.set_error("Error while parsing the file. #{e}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def with_temporary_file(content)
deserial = PuppetLanguageServer::Sidecar::Protocol::NodeGraph.new()
expect { deserial.from_json!(result) }.to_not raise_error

expect(deserial.dot_content).to match(/Fixture\[test\]/)
expect(deserial.content).to match(/Fixture\[test\]/)
expect(deserial.error_content.to_s).to eq('')
end
end
Expand Down Expand Up @@ -240,7 +240,7 @@ def with_temporary_file(content)
deserial = PuppetLanguageServer::Sidecar::Protocol::NodeGraph.new()
expect { deserial.from_json!(result) }.to_not raise_error

expect(deserial.dot_content).to match(/Envtype\[test\]/)
expect(deserial.content).to match(/Envtype\[test\]/)
expect(deserial.error_content.to_s).to eq('')
end
end
Expand Down Expand Up @@ -343,7 +343,7 @@ def with_temporary_file(content)
deserial = PuppetLanguageServer::Sidecar::Protocol::NodeGraph.new()
expect { deserial.from_json!(result) }.to_not raise_error

expect(deserial.dot_content).to_not eq('')
expect(deserial.content).to_not eq('')
expect(deserial.error_content.to_s).to eq('')
end
end
Expand Down

0 comments on commit 522e7c5

Please sign in to comment.