Skip to content

Commit 4fdca52

Browse files
authored
Merge pull request #69 from glennsarti/add-lang-server-version
Add a version to the language server
2 parents 8e106f7 + 52833ca commit 4fdca52

File tree

6 files changed

+113
-34
lines changed

6 files changed

+113
-34
lines changed

client/src/messages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export namespace PuppetVersionRequest {
77
export interface PuppetVersionDetails {
88
puppetVersion: string;
99
facterVersion: string;
10+
languageServerVersion: string;
1011
}
1112

1213
export interface PuppetResourceRequestParams {

server/README.md

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,45 @@ By default the language server will stop if no connection is made within 10 seco
2727
> bundle install
2828
2929
> bundle exec ruby ./puppet-languageserver --debug=stdout
30-
I, [2017-06-01T20:48:22.295769 #14028] INFO -- : Using Puppet v4.10.1
31-
I, [2017-06-01T20:48:22.296271 #14028] INFO -- : Initializing settings...
32-
I, [2017-06-01T20:48:22.306770 #14028] INFO -- : Creating puppet function environment...
33-
I, [2017-06-01T20:48:23.942964 #14028] INFO -- : Using Facter v2.4.6
34-
I, [2017-06-01T20:48:23.942964 #14028] INFO -- : Preloading Facter (Async)...
35-
I, [2017-06-01T20:48:23.943479 #14028] INFO -- : Preloading Puppet Types (Async)...
36-
I, [2017-06-01T20:48:23.943966 #14028] INFO -- : Preloading Functions (Async)...
37-
I, [2017-06-01T20:48:23.944964 #14028] INFO -- : Starting RPC Server...
38-
D, [2017-06-01T20:48:23.947964 #14028] DEBUG -- : TCPSRV: Services running. Press ^C to stop
39-
D, [2017-06-01T20:48:23.947964 #14028] DEBUG -- : TCPSRV: Will stop the server in 10 seconds if no connection is made.
40-
D, [2017-06-01T20:48:23.948464 #14028] DEBUG -- : TCPSRV: Will stop the server when client disconnects
30+
I, [2017-06-08T13:22:59.742612 #8004] INFO -- : Language Server is v0.0.1
31+
I, [2017-06-08T13:22:59.743611 #8004] INFO -- : Using Puppet v4.10.1
32+
I, [2017-06-08T13:22:59.743611 #8004] INFO -- : Initializing settings...
33+
I, [2017-06-08T13:22:59.744608 #8004] INFO -- : Starting RPC Server...
34+
D, [2017-06-08T13:22:59.750607 #8004] DEBUG -- : TCPSRV: Services running. Press ^C to stop
35+
D, [2017-06-08T13:22:59.751609 #8004] DEBUG -- : TCPSRV: Will stop the server in 10 seconds if no connection is made.
36+
D, [2017-06-08T13:22:59.751609 #8004] DEBUG -- : TCPSRV: Will stop the server when client disconnects
4137
LANGUAGE SERVER RUNNING 127.0.0.1:8081
42-
D, [2017-06-01T20:48:23.953964 #14028] DEBUG -- : TCPSRV: Started listening on 127.0.0.1:8081.
43-
D, [2017-06-01T20:48:36.013438 #14028] DEBUG -- : TCPSRV: No connection has been received in 10 seconds. Shutting down server.
44-
D, [2017-06-01T20:48:36.013917 #14028] DEBUG -- : TCPSRV: Stopping services
45-
D, [2017-06-01T20:48:36.014417 #14028] DEBUG -- : TCPSRV: Stopped listening on 127.0.0.1:8081
46-
D, [2017-06-01T20:48:36.014417 #14028] DEBUG -- : TCPSRV: Started shutdown process. Press ^C to force quit.
47-
D, [2017-06-01T20:48:36.014917 #14028] DEBUG -- : TCPSRV: Stopping services
48-
D, [2017-06-01T20:48:36.014917 #14028] DEBUG -- : TCPSRV: Waiting for workers to cycle down
49-
I, [2017-06-01T20:48:36.020416 #14028] INFO -- : Language Server exited....
38+
D, [2017-06-08T13:22:59.752611 #8004] DEBUG -- : TCPSRV: Started listening on 127.0.0.1:8081.
39+
I, [2017-06-08T13:22:59.761607 #8004] INFO -- : Creating puppet function environment...
40+
I, [2017-06-08T13:23:01.396607 #8004] INFO -- : Using Facter v2.4.6
41+
I, [2017-06-08T13:23:01.396607 #8004] INFO -- : Preloading Facter (Async)...
42+
I, [2017-06-08T13:23:01.398609 #8004] INFO -- : Preloading Puppet Types (Async)...
43+
I, [2017-06-08T13:23:01.398609 #8004] INFO -- : Preloading Functions (Async)...
44+
D, [2017-06-08T13:23:10.606536 #8004] DEBUG -- : TCPSRV: No connection has been received in 10 seconds. Shutting down server.
45+
D, [2017-06-08T13:23:10.606536 #8004] DEBUG -- : TCPSRV: Stopping services
46+
D, [2017-06-08T13:23:10.616540 #8004] DEBUG -- : TCPSRV: Stopped listening on 127.0.0.1:8081
47+
D, [2017-06-08T13:23:10.616540 #8004] DEBUG -- : TCPSRV: Started shutdown process. Press ^C to force quit.
48+
D, [2017-06-08T13:23:10.616540 #8004] DEBUG -- : TCPSRV: Stopping services
49+
D, [2017-06-08T13:23:10.617520 #8004] DEBUG -- : TCPSRV: Waiting for workers to cycle down
50+
I, [2017-06-08T13:23:10.648516 #8004] INFO -- : Language Server exited.
5051
```
5152

5253
To make the server run continuously add `--timeout=0` and `--no-stop` to the command line. For example;
5354

5455
```
5556
> bundle exec ruby ./puppet-languageserver --debug=stdout --timeout=0 --no-stop
56-
I, [2017-06-01T20:52:07.965708 #19760] INFO -- : Using Puppet v4.10.1
57-
I, [2017-06-01T20:52:07.966193 #19760] INFO -- : Initializing settings...
58-
I, [2017-06-01T20:52:07.978691 #19760] INFO -- : Creating puppet function environment...
59-
I, [2017-06-01T20:52:09.431437 #19760] INFO -- : Using Facter v2.4.6
60-
I, [2017-06-01T20:52:09.431437 #19760] INFO -- : Preloading Facter (Async)...
61-
I, [2017-06-01T20:52:09.432938 #19760] INFO -- : Preloading Puppet Types (Async)...
62-
I, [2017-06-01T20:52:09.433438 #19760] INFO -- : Preloading Functions (Async)...
63-
I, [2017-06-01T20:52:09.434440 #19760] INFO -- : Starting RPC Server...
64-
D, [2017-06-01T20:52:09.436939 #19760] DEBUG -- : TCPSRV: Services running. Press ^C to stop
57+
I, [2017-06-08T13:23:38.586369 #18496] INFO -- : Language Server is v0.0.1
58+
I, [2017-06-08T13:23:38.587368 #18496] INFO -- : Using Puppet v4.10.1
59+
I, [2017-06-08T13:23:38.587368 #18496] INFO -- : Initializing settings...
60+
I, [2017-06-08T13:23:38.588362 #18496] INFO -- : Starting RPC Server...
61+
D, [2017-06-08T13:23:38.595352 #18496] DEBUG -- : TCPSRV: Services running. Press ^C to stop
6562
LANGUAGE SERVER RUNNING 127.0.0.1:8081
66-
D, [2017-06-01T20:52:09.443956 #19760] DEBUG -- : TCPSRV: Started listening on 127.0.0.1:8081.
63+
D, [2017-06-08T13:23:38.595352 #18496] DEBUG -- : TCPSRV: Started listening on 127.0.0.1:8081.
64+
I, [2017-06-08T13:23:38.603353 #18496] INFO -- : Creating puppet function environment...
65+
I, [2017-06-08T13:23:40.473284 #18496] INFO -- : Using Facter v2.4.6
66+
I, [2017-06-08T13:23:40.473284 #18496] INFO -- : Preloading Facter (Async)...
67+
I, [2017-06-08T13:23:40.473788 #18496] INFO -- : Preloading Puppet Types (Async)...
68+
I, [2017-06-08T13:23:40.474286 #18496] INFO -- : Preloading Functions (Async)...
6769
...
6870
```
6971

@@ -110,7 +112,7 @@ Usage: puppet-languageserver.rb [options]
110112
--debug=DEBUG Output debug information. Either specify a filename or 'STDOUT'. Default is no debug output
111113
-s, --slow-start Delay starting the TCP Server until Puppet initialisation has completed. Default is to start fast
112114
-h, --help Prints this help
113-
```
115+
-v, --version Prints the Langauge Server version```
114116
115117
## Why are there vendored gems and why only native ruby
116118

server/lib/languageserver/puppet_version.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
module LanguageServer
22
module PuppetVersion
33
# export interface PuppetVersionDetails {
4-
# puppetVersion: string;
5-
# facterVersion: string;
4+
# puppetVersion: string;
5+
# facterVersion: string;
6+
# languageServerVersion: string;
67
# }
78

89
def self.create(options)
@@ -12,6 +13,7 @@ def self.create(options)
1213

1314
result['puppetVersion'] = options['puppetVersion']
1415
result['facterVersion'] = options['facterVersion']
16+
result['languageServerVersion'] = PuppetLanguageServer.version
1517

1618
result
1719
end

server/lib/puppet-languageserver.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'languageserver/languageserver'
22

3-
%w[simple_tcp_server json_rpc_handler message_router server_capabilities document_validator
3+
%w[version simple_tcp_server json_rpc_handler message_router server_capabilities document_validator
44
puppet_parser_helper puppet_helper facter_helper completion_provider hover_provider].each do |lib|
55
begin
66
require "puppet-languageserver/#{lib}"
@@ -65,6 +65,11 @@ def self.parse(options)
6565
puts opts
6666
exit
6767
end
68+
69+
opts.on('-v', '--version', 'Prints the Langauge Server version') do
70+
puts PuppetLanguageServer.version
71+
exit
72+
end
6873
end
6974

7075
opt_parser.parse!(options.dup)
@@ -100,6 +105,7 @@ def self.init_puppet(options)
100105
# Log to file
101106
$logger = Logger.new(options[:debug])
102107
end
108+
log_message(:info, "Language Server is v#{PuppetLanguageServer.version}")
103109
log_message(:info, "Using Puppet v#{Puppet.version}")
104110

105111
log_message(:info, 'Initializing settings...')
@@ -115,7 +121,6 @@ def self.init_puppet(options)
115121
end
116122

117123
def self.init_puppet_worker(options)
118-
log_message('information', 'Initializing settings...')
119124
Puppet.initialize_settings
120125

121126
log_message(:info, 'Creating puppet function environment...')
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module PuppetLanguageServer
2+
if not defined? PUPPETLANGUAGESERVERVERSION then
3+
PUPPETLANGUAGESERVERVERSION = '0.0.1'
4+
end
5+
6+
# @api public
7+
#
8+
# @return [String] containing the langauge server version, e.g. "0.4.0"
9+
def self.version
10+
version_file = File.join(File.dirname(__FILE__), 'VERSION')
11+
return @lang_server_version if @lang_server_version
12+
if version = read_version_file(version_file)
13+
@lang_server_version = version
14+
end
15+
@lang_server_version ||= PUPPETLANGUAGESERVERVERSION
16+
end
17+
18+
# Sets the langauge server version
19+
# Typically only used in testing
20+
#
21+
# @return [void]
22+
#
23+
# @api private
24+
def self.version=(version)
25+
@lang_server_version = version
26+
end
27+
28+
# @api private
29+
#
30+
# @return [String] the version -- for example: "0.4.0" or nil if the VERSION
31+
# file does not exist.
32+
def self.read_version_file(path)
33+
if File.exists?(path)
34+
File.read(path).chomp
35+
end
36+
end
37+
private_class_method :read_version_file
38+
end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require 'spec_helper'
2+
3+
describe "version" do
4+
before :each do
5+
PuppetLanguageServer.instance_eval do
6+
@lang_server_version = nil if @lang_server_version
7+
end
8+
end
9+
10+
context "without a VERSION file" do
11+
before :each do
12+
expect(PuppetLanguageServer).to receive(:read_version_file).and_return(nil)
13+
end
14+
15+
it "is PuppetLanguageServer::PUPPETLANGUAGESERVERVERSION" do
16+
expect(PuppetLanguageServer.version).to eq(PuppetLanguageServer::PUPPETLANGUAGESERVERVERSION)
17+
end
18+
end
19+
20+
context "with a VERSION file" do
21+
let (:file_version) { '1.2.3' }
22+
23+
before :each do
24+
expect(PuppetLanguageServer).to receive(:read_version_file).with(/VERSION$/).and_return(file_version)
25+
end
26+
27+
it "is the content of the file" do
28+
expect(PuppetLanguageServer.version).to eq(file_version)
29+
end
30+
end
31+
end

0 commit comments

Comments
 (0)