Skip to content
Closed
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
5 changes: 4 additions & 1 deletion lib/puppet-languageserver/message_router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,11 @@ def receive_request(request)
case documents.document_type(file_uri)
when :manifest
request.reply_result(PuppetLanguageServer::Manifest::DocumentSymbolProvider.extract_document_symbols(content, :tasks_mode => PuppetLanguageServer::DocumentStore.module_plan_file?(file_uri)))
when :puppetfile
result = PuppetLanguageServer::Puppetfile::DocumentSymbolProvider.extract_document_symbols(content)
request.reply_result(result)
else
raise "Unable to provide definition on #{file_uri}"
raise "Unable to provide document symbols on #{file_uri}"
end
rescue StandardError => exception
PuppetLanguageServer.log_message(:error, "(textDocument/documentSymbol) #{exception}")
Expand Down
1 change: 1 addition & 0 deletions lib/puppet-languageserver/providers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
puppetfile/r10k/module/git
puppetfile/r10k/module/svn
puppetfile/r10k/puppetfile
puppetfile/document_symbol_provider
puppetfile/validation_provider
].each do |lib|
begin
Expand Down
44 changes: 44 additions & 0 deletions lib/puppet-languageserver/puppetfile/document_symbol_provider.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module PuppetLanguageServer
module Puppetfile
module DocumentSymbolProvider
def self.max_line_length
# TODO: ... need to figure out the actual line length
1000
end

# def self.workspace_symbols(query)
# query = '' if query.nil?
# result = []
# result
# end

def self.extract_document_symbols(content)
symbols = []

puppetfile = nil
begin
puppetfile = PuppetLanguageServer::Puppetfile::R10K::Puppetfile.new
puppetfile.load!(content)
rescue StandardError, SyntaxError, LoadError => _detail
return symbols
end
return symbols if puppetfile.nil?

puppetfile.modules.each do |mod|
next if mod.properties[:type] == :invalid

symbols.push(LanguageServer::DocumentSymbol.create(
'name' => mod.name,
'kind' => LanguageServer::SYMBOLKIND_FILE,
'detail' => mod.title,
'range' => [mod.puppetfile_line_number, 0, mod.puppetfile_line_number, max_line_length],
'selectionRange' => [mod.puppetfile_line_number, 0, mod.puppetfile_line_number, max_line_length],
'children' => []
))
end

symbols
end
end
end
end