lsp-protocol 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/lsp.rb +104 -7
- data/lib/lsp/file_language_server.rb +21 -8
- data/lsp-protocol.gemspec +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cad9cf151c8eea6ed1c792455f49370275229d97
|
4
|
+
data.tar.gz: f1698d0735cd92fd06fd0b369edc483b3e5803bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c36ccab0950c30e39058e69382e9e3d398c0b1bce3c23c80f78eaab45144ed1f3bcdb40f0701bada5be9055b0ecb5cfaeaa55f9d1c11f3a783b37e2d8e9afd23
|
7
|
+
data.tar.gz: 6982ed99efdbc5d629bd7d146cbc068ddd71eabd16ddbfcb857bc653a5ec715f288db9b2c40b62389b0f3f3d44042d741ccfc8651d996dfd877be0561e809a79
|
data/Gemfile.lock
CHANGED
data/lib/lsp.rb
CHANGED
@@ -1,24 +1,109 @@
|
|
1
1
|
module Lsp
|
2
2
|
TextDocumentIdentifier = Struct.new(:uri)
|
3
3
|
|
4
|
-
|
4
|
+
TextDocumentPositionParams = Struct.new(:text_document, :position)
|
5
|
+
InitializeRequest = Struct.new(:root_uri)
|
6
|
+
|
7
|
+
Position = Struct.new(:line, :character) do
|
8
|
+
def self.from_hash(line:, character:)
|
9
|
+
new(line, character)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
Range = Struct.new(:start, :end) do
|
13
|
+
def to_h
|
14
|
+
{
|
15
|
+
start: start.to_h,
|
16
|
+
end: self.end.to_h,
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
Location = Struct.new(:uri, :range) do
|
21
|
+
def to_h
|
22
|
+
{
|
23
|
+
uri: uri,
|
24
|
+
range: range.to_h,
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
ResponseMessage = Struct.new(:result, :error) do
|
30
|
+
def self.successful(result)
|
31
|
+
new(result, nil)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
TextDocumentHoverResult = Struct.new(:contents) do
|
36
|
+
def to_h
|
37
|
+
{
|
38
|
+
contents: self.contents,
|
39
|
+
range: nil,
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
module ResponseError
|
45
|
+
class Base
|
46
|
+
def initialize(code, message, data)
|
47
|
+
@code = code
|
48
|
+
@message = message
|
49
|
+
@data = data
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_h
|
53
|
+
{
|
54
|
+
code: @code,
|
55
|
+
message: @message,
|
56
|
+
data: @data,
|
57
|
+
}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class MethodNotFound < Base
|
62
|
+
def initialize
|
63
|
+
@code = -32601
|
64
|
+
@message = "Method not found"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
5
68
|
|
6
69
|
module LanguageServer
|
7
70
|
LanguageServerError = Class.new(StandardError)
|
8
71
|
NotImplementedError = Class.new(LanguageServerError)
|
9
|
-
UnknownMethodError = Class.new(LanguageServerError)
|
10
72
|
|
11
73
|
def request(id, method_name, params)
|
12
|
-
case method_name
|
74
|
+
response = case method_name
|
13
75
|
when "textDocument/hover"
|
14
|
-
|
15
|
-
|
76
|
+
handle_text_document_hover(
|
77
|
+
TextDocumentPositionParams.new(
|
78
|
+
TextDocumentIdentifier.new(params.fetch(:textDocument).fetch(:uri)),
|
79
|
+
Position.from_hash(params.fetch(:position))))
|
80
|
+
when "textDocument/definition"
|
81
|
+
handle_text_document_definition(
|
82
|
+
TextDocumentPositionParams.new(
|
16
83
|
TextDocumentIdentifier.new(
|
17
84
|
params.fetch(:textDocument)),
|
18
85
|
params.fetch(:position)))
|
19
|
-
|
86
|
+
when "initialize"
|
87
|
+
handle_initialize(
|
88
|
+
InitializeRequest.new(
|
89
|
+
params.fetch(:rootUri)))
|
90
|
+
else
|
91
|
+
ResponseMessage.new(nil, ResponseError::MethodNotFound.new)
|
92
|
+
end
|
93
|
+
@language_server.response(
|
94
|
+
id,
|
95
|
+
response.result ? response.result.to_h : nil,
|
96
|
+
response.error ? response.error.to_h : nil)
|
97
|
+
rescue NotImplementedError
|
98
|
+
ResponseMessage.new(nil, ResponseError::MethodNotFound.new)
|
99
|
+
end
|
100
|
+
|
101
|
+
def notify(method_name, params)
|
102
|
+
case method_name
|
103
|
+
when "textDocument/didOpen"
|
104
|
+
handle_text_document_did_open
|
20
105
|
end
|
21
|
-
|
106
|
+
rescue NotImplementedError
|
22
107
|
end
|
23
108
|
|
24
109
|
attr_writer :language_server
|
@@ -26,6 +111,18 @@ module Lsp
|
|
26
111
|
def handle_text_document_hover(request)
|
27
112
|
raise NotImplementedError
|
28
113
|
end
|
114
|
+
|
115
|
+
def handle_text_document_definition(request)
|
116
|
+
raise NotImplementedError
|
117
|
+
end
|
118
|
+
|
119
|
+
def handle_initialize(request)
|
120
|
+
raise NotImplementedError
|
121
|
+
end
|
122
|
+
|
123
|
+
def handle_text_document_did_open
|
124
|
+
raise NotImplementedError
|
125
|
+
end
|
29
126
|
end
|
30
127
|
end
|
31
128
|
|
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'logger'
|
2
3
|
|
3
4
|
module Lsp
|
4
5
|
class FileLanguageServer
|
5
|
-
def initialize(implementation, input = $stdin, output = $stdout)
|
6
|
+
def initialize(implementation, input = $stdin, output = $stdout, logger: Logger.new(nil))
|
6
7
|
@implementation = implementation
|
7
8
|
@input = input
|
8
9
|
@output = output
|
10
|
+
@logger = logger
|
9
11
|
end
|
10
12
|
|
11
13
|
def start
|
@@ -28,10 +30,17 @@ module Lsp
|
|
28
30
|
|
29
31
|
body_raw = input.read(headers["Content-Length"].to_i)
|
30
32
|
body_json = JSON.parse(body_raw, symbolize_names: true)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
logger.info("RECV #{body_json}")
|
34
|
+
if body_json[:id]
|
35
|
+
implementation.request(
|
36
|
+
body_json.fetch(:id),
|
37
|
+
body_json.fetch(:method),
|
38
|
+
body_json.fetch(:params))
|
39
|
+
else
|
40
|
+
implementation.notify(
|
41
|
+
body_json.fetch(:method),
|
42
|
+
body_json.fetch(:params))
|
43
|
+
end
|
35
44
|
end
|
36
45
|
rescue EOFError
|
37
46
|
end
|
@@ -41,11 +50,15 @@ module Lsp
|
|
41
50
|
end
|
42
51
|
|
43
52
|
def response(id, result, error)
|
44
|
-
|
53
|
+
payload = {
|
54
|
+
jsonrpc: "2.0",
|
45
55
|
id: id,
|
46
56
|
result: result,
|
47
57
|
error: error,
|
48
|
-
}
|
58
|
+
}
|
59
|
+
output.write(build_message(payload))
|
60
|
+
output.flush
|
61
|
+
logger.info("SEND #{payload}")
|
49
62
|
end
|
50
63
|
|
51
64
|
def build_message(hash)
|
@@ -53,6 +66,6 @@ module Lsp
|
|
53
66
|
"Content-Length: #{json.size}\r\n\r\n#{json}"
|
54
67
|
end
|
55
68
|
|
56
|
-
attr_reader :implementation, :input, :output
|
69
|
+
attr_reader :implementation, :input, :output, :logger
|
57
70
|
end
|
58
71
|
end
|
data/lsp-protocol.gemspec
CHANGED
@@ -4,14 +4,14 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'lsp-protocol'
|
7
|
-
spec.version = '0.0.
|
7
|
+
spec.version = '0.0.2'
|
8
8
|
spec.licenses = ['MIT']
|
9
9
|
spec.authors = ['Rafał Łasocha']
|
10
10
|
spec.email = 'lsp@swistak35.com'
|
11
11
|
|
12
12
|
spec.summary = "Language Server Protocol implementation"
|
13
13
|
spec.description = "A simple hello world gem"
|
14
|
-
spec.homepage = 'https://github.com/swistak35/
|
14
|
+
spec.homepage = 'https://github.com/swistak35/lsp'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
17
|
spec.require_paths = ['lib']
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lsp-protocol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafał Łasocha
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -64,7 +64,7 @@ files:
|
|
64
64
|
- lib/lsp.rb
|
65
65
|
- lib/lsp/file_language_server.rb
|
66
66
|
- lsp-protocol.gemspec
|
67
|
-
homepage: https://github.com/swistak35/
|
67
|
+
homepage: https://github.com/swistak35/lsp
|
68
68
|
licenses:
|
69
69
|
- MIT
|
70
70
|
metadata: {}
|