Module: PuppetLanguageServer
- Defined in:
- lib/puppet_languageserver.rb,
lib/puppet-languageserver/crash_dump.rb,
lib/puppet-languageserver/uri_helper.rb,
lib/puppet-languageserver/facter_helper.rb,
lib/puppet-languageserver/global_queues.rb,
lib/puppet-languageserver/puppet_helper.rb,
lib/puppet-languageserver/message_handler.rb,
lib/puppet-languageserver/sidecar_protocol.rb,
lib/puppet-languageserver/server_capabilities.rb,
lib/puppet-languageserver/client_session_state.rb,
lib/puppet-languageserver/puppet_parser_helper.rb,
lib/puppet-languageserver/epp/validation_provider.rb,
lib/puppet-languageserver/manifest/hover_provider.rb,
lib/puppet-languageserver/manifest/folding_provider.rb,
lib/puppet-languageserver/session_state/object_cache.rb,
lib/puppet-languageserver/global_queues/sidecar_queue.rb,
lib/puppet-languageserver/manifest/signature_provider.rb,
lib/puppet-languageserver/manifest/completion_provider.rb,
lib/puppet-languageserver/manifest/definition_provider.rb,
lib/puppet-languageserver/manifest/validation_provider.rb,
lib/puppet-languageserver/session_state/document_store.rb,
lib/puppet-languageserver/session_state/language_client.rb,
lib/puppet-languageserver/global_queues/validation_queue.rb,
lib/puppet-languageserver/puppetfile/validation_provider.rb,
lib/puppet-languageserver/manifest/format_on_type_provider.rb,
lib/puppet-languageserver/manifest/document_symbol_provider.rb,
lib/puppet-languageserver/global_queues/single_instance_queue.rb
Defined Under Namespace
Modules: CrashDump, Epp, FacterHelper, GlobalQueues, Manifest, PuppetHelper, PuppetParserHelper, Puppetfile, ServerCapabilites, SessionState, Sidecar, UriHelper
Classes: ClientSessionState, CommandLineParser, DisabledMessageHandler, MessageHandler
Class Method Summary
collapse
Class Method Details
.active? ⇒ Bool
Whether the language server is actually in a state that can be used. Typically this is false when a catastrophic error occurs during startup e.g. Puppet is missing.
23
24
25
|
# File 'lib/puppet_languageserver.rb', line 23
def self.active?
@server_is_active
end
|
31
32
33
|
# File 'lib/puppet_languageserver.rb', line 31
def self.configure_featureflags(flags)
@flags = flags
end
|
.featureflag?(flagname) ⇒ Boolean
35
36
37
38
39
|
# File 'lib/puppet_languageserver.rb', line 35
def self.featureflag?(flagname)
return false if @flags.nil? || @flags.empty?
@flags.include?(flagname)
end
|
.init_puppet(options) ⇒ Object
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
# File 'lib/puppet_languageserver.rb', line 208
def self.init_puppet(options)
PuppetEditorServices.init_logging(options)
log_message(:info, "Language Server is v#{PuppetEditorServices.version}")
log_message(:debug, 'Loading gems...')
require_gems(options)
return unless active?
log_message(:info, "Using Puppet v#{Puppet.version}")
log_message(:info, "Using Facter v#{Facter.version}")
raise("Detected Puppet #{Puppet.version} however the Language Server requires Puppet 5.0 and above") if Gem::Version.new(Puppet.version) < Gem::Version.new('5.0.0')
log_message(:debug, "Detected additional puppet settings #{options[:puppet_settings]}")
options[:puppet_settings].nil? ? Puppet.initialize_settings : Puppet.initialize_settings(options[:puppet_settings])
log_message(:info, 'Initializing settings...')
Puppet::Util::Log.destinations.clear
Puppet::Util::Log.newdestination('null_logger')
true
end
|
.log_message(severity, message) ⇒ Object
204
205
206
|
# File 'lib/puppet_languageserver.rb', line 204
def self.log_message(severity, message)
PuppetEditorServices.log_message(severity, message)
end
|
.require_gems(options) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/puppet_languageserver.rb', line 41
def self.require_gems(options)
original_verbose = $VERBOSE
$VERBOSE = nil
@server_is_active = false
unless options[:puppet_version].nil?
available_puppet_gems = Gem::Specification
.select { |item| item.name.casecmp('puppet').zero? }
.map { |item| item.version.to_s }
if available_puppet_gems.include?(options[:puppet_version])
gem 'puppet', options[:puppet_version]
else
log_message(:warn, "Unable to use puppet version #{options[:puppet_version]}, as only the following versions are available [#{available_puppet_gems.join(', ')}]")
end
end
%w[
client_session_state
crash_dump
message_handler
server_capabilities
].each do |lib|
require "puppet-languageserver/#{lib}"
rescue LoadError
require File.expand_path(File.join(File.dirname(__FILE__), 'puppet-languageserver', lib))
end
begin
require 'lsp/lsp'
require 'puppet'
require 'facter'
rescue LoadError => e
log_message(:error, "Error while loading a critical gem: #{e} #{e.backtrace}")
return
end
%w[
sidecar_protocol
global_queues
puppet_lexer_helper
puppet_parser_helper
puppet_helper
facter_helper
uri_helper
puppet_monkey_patches
providers
].each do |lib|
require "puppet-languageserver/#{lib}"
rescue LoadError
require File.expand_path(File.join(File.dirname(__FILE__), 'puppet-languageserver', lib))
end
unless options[:flags].nil? || options[:flags].empty?
flags = options[:flags]
log_message(:debug, "Detected feature flags [#{flags.join(', ')}]")
configure_featureflags(flags)
end
@server_is_active = true
ensure
$VERBOSE = original_verbose
end
|
.rpc_server(options) ⇒ Object
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
|
# File 'lib/puppet_languageserver.rb', line 232
def self.rpc_server(options)
log_message(:info, 'Starting RPC Server...')
options[:servicename] = 'LANGUAGE SERVER'
require 'puppet_editor_services/protocol/json_rpc'
server_options = options
protocol_options = { class: PuppetEditorServices::Protocol::JsonRPC }.merge(options)
handler_options = { class: PuppetLanguageServer::MessageHandler }.merge(options)
unless active?
handler_options[:class] = PuppetLanguageServer::DisabledMessageHandler
log_message(:info, 'Configured the Language Server to use the Disabled Message Router')
end
if options[:stdio]
log_message(:debug, 'Using STDIO Server')
require 'puppet_editor_services/server/stdio'
server = ::PuppetEditorServices::Server::Stdio.new(server_options, protocol_options, handler_options)
trap('INT') { server.stop }
else
log_message(:debug, 'Using TCP Server')
require 'puppet_editor_services/server/tcp'
server = ::PuppetEditorServices::Server::Tcp.new(server_options, protocol_options, handler_options)
trap('INT') { server.stop_services(true) }
end
server.start
log_message(:info, 'Language Server exited.')
end
|
.static_data_dir ⇒ Object
27
28
29
|
# File 'lib/puppet_languageserver.rb', line 27
def self.static_data_dir
@static_data_dir ||= File.expand_path(File.join(__dir__, 'puppet-languageserver', 'static_data'))
end
|