lsp-protocol 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 87f804a9a15bc3a7cda122f38be563977751f0a1
4
+ data.tar.gz: c895c0618fdc176e94ace66ba5c570e75134b4bb
5
+ SHA512:
6
+ metadata.gz: 6544d334f23f647f348eeec15f4d255ec73d70b00893cd1db6aaa3abaee6a5484d70b2c7ec6b383077764900500d65694419ff552d42d94ebc12a86c4ecd709b
7
+ data.tar.gz: 4a3a873014ad130869219e3f6f2ceb7a9c8256b642a8134f6aedac0285f5013160e5debe038a81f6fa9af4c96c7f70984e950a9de2ae0a212ec86ffce9f5f271
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lsp (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ byebug (10.0.2)
10
+ diff-lcs (1.3)
11
+ rspec (3.5.0)
12
+ rspec-core (~> 3.5.0)
13
+ rspec-expectations (~> 3.5.0)
14
+ rspec-mocks (~> 3.5.0)
15
+ rspec-core (3.5.4)
16
+ rspec-support (~> 3.5.0)
17
+ rspec-expectations (3.5.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.5.0)
20
+ rspec-mocks (3.5.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.5.0)
23
+ rspec-support (3.5.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.9)
30
+ byebug
31
+ lsp!
32
+ rspec (~> 3.5.0)
33
+
34
+ BUNDLED WITH
35
+ 1.16.1
@@ -0,0 +1,32 @@
1
+ module Lsp
2
+ TextDocumentIdentifier = Struct.new(:uri)
3
+
4
+ TextDocumentHoverRequest = Struct.new(:text_document, :position)
5
+
6
+ module LanguageServer
7
+ LanguageServerError = Class.new(StandardError)
8
+ NotImplementedError = Class.new(LanguageServerError)
9
+ UnknownMethodError = Class.new(LanguageServerError)
10
+
11
+ def request(id, method_name, params)
12
+ case method_name
13
+ when "textDocument/hover"
14
+ result = handle_text_document_hover(
15
+ TextDocumentHoverRequest.new(
16
+ TextDocumentIdentifier.new(
17
+ params.fetch(:textDocument)),
18
+ params.fetch(:position)))
19
+ else raise UnknownMethodError
20
+ end
21
+ @language_server.response(id, result, nil)
22
+ end
23
+
24
+ attr_writer :language_server
25
+
26
+ def handle_text_document_hover(request)
27
+ raise NotImplementedError
28
+ end
29
+ end
30
+ end
31
+
32
+ require 'lsp/file_language_server'
@@ -0,0 +1,58 @@
1
+ require 'json'
2
+
3
+ module Lsp
4
+ class FileLanguageServer
5
+ def initialize(implementation, input = $stdin, output = $stdout)
6
+ @implementation = implementation
7
+ @input = input
8
+ @output = output
9
+ end
10
+
11
+ def start
12
+ prepare
13
+
14
+ loop do
15
+ headers = {}
16
+ loop do
17
+ header_line = input.readline.strip
18
+ if header_line.empty?
19
+ if headers.empty?
20
+ redo
21
+ else
22
+ break
23
+ end
24
+ end
25
+ header_name, header_value = header_line.split(":", 2)
26
+ headers[header_name.strip] = header_value.strip
27
+ end
28
+
29
+ body_raw = input.read(headers["Content-Length"].to_i)
30
+ body_json = JSON.parse(body_raw, symbolize_names: true)
31
+ implementation.request(
32
+ body_json.fetch(:id),
33
+ body_json.fetch(:method),
34
+ body_json.fetch(:params))
35
+ end
36
+ rescue EOFError
37
+ end
38
+
39
+ def prepare
40
+ implementation.language_server = self
41
+ end
42
+
43
+ def response(id, result, error)
44
+ output.write(build_message({
45
+ id: id,
46
+ result: result,
47
+ error: error,
48
+ }))
49
+ end
50
+
51
+ def build_message(hash)
52
+ json = hash.to_json
53
+ "Content-Length: #{json.size}\r\n\r\n#{json}"
54
+ end
55
+
56
+ attr_reader :implementation, :input, :output
57
+ end
58
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'lsp-protocol'
7
+ spec.version = '0.0.1'
8
+ spec.licenses = ['MIT']
9
+ spec.authors = ['Rafał Łasocha']
10
+ spec.email = 'lsp@swistak35.com'
11
+
12
+ spec.summary = "Language Server Protocol implementation"
13
+ spec.description = "A simple hello world gem"
14
+ spec.homepage = 'https://github.com/swistak35/language_server_protocol'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_development_dependency 'bundler', '~> 1.9'
20
+ spec.add_development_dependency 'rspec', '~> 3.5.0'
21
+ spec.add_development_dependency 'byebug'
22
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lsp-protocol
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rafał Łasocha
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-06-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.5.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.5.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: A simple hello world gem
56
+ email: lsp@swistak35.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - ".rspec"
62
+ - Gemfile
63
+ - Gemfile.lock
64
+ - lib/lsp.rb
65
+ - lib/lsp/file_language_server.rb
66
+ - lsp-protocol.gemspec
67
+ homepage: https://github.com/swistak35/language_server_protocol
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.6.14
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Language Server Protocol implementation
91
+ test_files: []