language_server 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4ad7bdb98ed0fdc4c493cecd7c296fc551d23c0
4
- data.tar.gz: a458cc4c3aaf8b95d5ae5780fb9896d157476e8e
3
+ metadata.gz: 4d42055dc4ef0fbe7007913db9a924082a9370af
4
+ data.tar.gz: cce1ea0bd8e0adad433428032fab8a72832c2494
5
5
  SHA512:
6
- metadata.gz: 8cd2bf30dd8548f44fa82dd28530f694fce2b68445de389a1945d754ce56de2f96ec8a7fb9ad40c3225a1d017a433a0e88b5193e3773f52075fe0a9e71fd344d
7
- data.tar.gz: e37e1fd641490f0ab03deb515fec382724248231f59ffc179e6ea3c4cc5ef6722a503cf3cfd5f65dbea336049afe1090dbfe99d528764c7d27b1a8cac7cb548a
6
+ metadata.gz: b53cfe73ccb8c8c53030a0807b5675410c6d9d99c9f7a222f49ac16d02cb2d255456a9bae2df19a34c79dc8efe8acca4bb910d52107ecc906bff3669dd26917e
7
+ data.tar.gz: b88d4f4fa7039b551fd948e4b6564f8e5a95855fc2295079cd72fb3fc1cbe46a3372808ccc756b12b16715acf6cdc069845ee1de920ef11090a4dbc6df261da3
@@ -0,0 +1,6 @@
1
+ FROM node:7.10-alpine
2
+
3
+ RUN mkdir /app && chown node:node /app
4
+
5
+ USER node
6
+ WORKDIR /app
data/README.md CHANGED
@@ -55,7 +55,7 @@ https://github.com/EugenMayer/docker-sync/wiki/1.-Installation
55
55
  ### Setup
56
56
 
57
57
  $ git clone https://github.com/mtsmfm/language_server-ruby.git
58
- $ cs language_server-ruby
58
+ $ cd language_server-ruby
59
59
  $ docker-sync start
60
60
  $ docker-compose run app bin/setup
61
61
 
data/docker-compose.yml CHANGED
@@ -7,14 +7,13 @@ services:
7
7
  volumes:
8
8
  - app-sync:/app:nocopy
9
9
  - home:/home/ruby
10
- - $HOME:/$HOME
11
10
  - $HOME/.gitconfig:/home/ruby/.gitconfig:ro
12
11
  - $HOME/.ssh:/home/ruby/.ssh:ro
13
12
  - $HOME/.gem:/home/ruby/.gem
14
13
  node:
15
- image: node:7.10-alpine
16
- user: node
17
- working_dir: /app
14
+ build:
15
+ context: .
16
+ dockerfile: Dockerfile-node.development
18
17
  volumes:
19
18
  - app-sync/:/app
20
19
  - home:/home/node
@@ -25,6 +25,8 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ["lib"]
27
27
 
28
+ spec.add_dependency "rcodetools"
29
+
28
30
  spec.add_development_dependency "bundler", "~> 1.14"
29
31
  spec.add_development_dependency "rake", "~> 10.0"
30
32
  spec.add_development_dependency "minitest", "~> 5.0"
@@ -1,84 +1,15 @@
1
1
  require "language_server/version"
2
2
  require "language_server/protocol/interfaces"
3
3
  require "language_server/protocol/constants"
4
+ require "language_server/protocol/stdio"
4
5
  require "language_server/linter/ruby_wc"
6
+ require "language_server/completion_provider/rcodetools"
7
+ require "language_server/uri_store"
5
8
 
6
9
  require "json"
7
10
  require "logger"
8
- require "open3"
9
- require "tempfile"
10
- require "shellwords"
11
11
 
12
12
  module LanguageServer
13
- module Protocol
14
- module Stdio
15
- class Reader
16
- def read(&block)
17
- buffer = ""
18
- header_parsed = false
19
- content_length = nil
20
-
21
- while char = STDIN.getc
22
- buffer << char
23
-
24
- unless header_parsed
25
- if buffer[-4..-1] == "\r\n" * 2
26
- content_length = buffer.match(/Content-Length: (\d+)/i)[1].to_i
27
-
28
- header_parsed = true
29
- buffer.clear
30
- end
31
- else
32
- if buffer.bytesize == content_length
33
- LanguageServer.logger.debug("Receive: #{buffer}")
34
-
35
- request = JSON.parse(buffer, symbolize_names: true)
36
-
37
- block.call(request)
38
-
39
- header_parsed = false
40
- buffer.clear
41
- end
42
- end
43
- end
44
- end
45
- end
46
-
47
- class Writer
48
- def respond(id:, result:)
49
- write(id: id, result: result)
50
- end
51
-
52
- def notify(method:, params: {})
53
- write(method: method, params: params)
54
- end
55
-
56
- private
57
-
58
- def write(response)
59
- response_str = response.merge(
60
- jsonrpc: "2.0"
61
- ).to_json
62
-
63
- headers = {
64
- "Content-Length" => response_str.bytesize
65
- }
66
-
67
- headers.each do |k, v|
68
- STDOUT.print "#{k}: #{v}\r\n"
69
- end
70
-
71
- STDOUT.print "\r\n"
72
-
73
- STDOUT.print response_str
74
- STDOUT.flush
75
-
76
- LanguageServer.logger.debug("Response: #{response_str}")
77
- end
78
- end
79
- end
80
- end
81
-
82
13
  class << self
83
14
  def logger
84
15
  @logger ||= Logger.new(STDERR)
@@ -123,6 +54,10 @@ module LanguageServer
123
54
  capabilities: Protocol::Interfaces::ServerCapabilities.new(
124
55
  text_document_sync: Protocol::Interfaces::TextDocumentSyncOptions.new(
125
56
  change: Protocol::Constants::TextDocumentSyncKind::FULL
57
+ ),
58
+ completion_provider: Protocol::Interfaces::CompletionOptions.new(
59
+ resolve_provider: true,
60
+ trigger_characters: %w(.)
126
61
  )
127
62
  )
128
63
  )
@@ -133,7 +68,11 @@ module LanguageServer
133
68
  end
134
69
 
135
70
  on :"textDocument/didChange" do |request, notifier|
136
- diagnostics = Linter::RubyWC.new(request[:params][:contentChanges][0][:text]).call.map do |error|
71
+ uri = request[:params][:textDocument][:uri]
72
+ text = request[:params][:contentChanges][0][:text]
73
+ UriStore[uri] = text
74
+
75
+ diagnostics = Linter::RubyWC.new(text).call.map do |error|
137
76
  Protocol::Interfaces::Diagnostic.new(
138
77
  message: error.message,
139
78
  severity: error.warning? ? Protocol::Constants::DiagnosticSeverity::WARNING : Protocol::Constants::DiagnosticSeverity::ERROR,
@@ -153,9 +92,21 @@ module LanguageServer
153
92
  notifier.call(
154
93
  method: :"textDocument/publishDiagnostics",
155
94
  params: Protocol::Interfaces::PublishDiagnosticsParams.new(
156
- uri: request[:params][:textDocument][:uri],
95
+ uri: uri,
157
96
  diagnostics: diagnostics
158
97
  )
159
98
  )
160
99
  end
100
+
101
+ on :"textDocument/completion" do |request|
102
+ uri = request[:params][:textDocument][:uri]
103
+ line, character = request[:params][:position].fetch_values(:line, :character)
104
+ CompletionProvider::Rcodetools.new(uri, line.to_i, character.to_i).call.map do |candidate|
105
+ Protocol::Interfaces::CompletionItem.new(
106
+ label: candidate.method_name,
107
+ detail: candidate.description,
108
+ kind: Protocol::Constants::CompletionItemKind::METHOD
109
+ )
110
+ end
111
+ end
161
112
  end
@@ -0,0 +1,52 @@
1
+ require "language_server/uri_store"
2
+
3
+ require "rcodetools/completion"
4
+
5
+ module LanguageServer
6
+ module CompletionProvider
7
+ class Candidate
8
+ attr_reader :method_name, :description
9
+
10
+ def initialize(method_name:, description:)
11
+ @method_name = method_name
12
+ @description = description
13
+ end
14
+
15
+ def ==(other)
16
+ method_name == other.method_name && description == other.description
17
+ end
18
+ end
19
+
20
+ class Filter < ::Rcodetools::XMPCompletionFilter
21
+ @candidates_with_description_flag = true
22
+
23
+ def completion_code(*args)
24
+ candidates_with_class(*args)
25
+ rescue NewCodeError, RuntimeDataError, NoCandidates
26
+ [nil, []]
27
+ end
28
+ end
29
+
30
+ class Rcodetools
31
+ def initialize(uri, line, character)
32
+ @uri = uri
33
+ @line = line
34
+ @character = character
35
+ end
36
+
37
+ def call
38
+ _, candidates = Filter.run(source, lineno: @line + 1, column: @character)
39
+ candidates.map do |candidate|
40
+ method_name, description = candidate.split(/\0/, 2)
41
+ Candidate.new(method_name: method_name, description: description)
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def source
48
+ UriStore[@uri]
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,2 @@
1
+ require "language_server/protocol/stdio/reader"
2
+ require "language_server/protocol/stdio/writer"
@@ -0,0 +1,37 @@
1
+ module LanguageServer
2
+ module Protocol
3
+ module Stdio
4
+ class Reader
5
+ def read(&block)
6
+ buffer = ""
7
+ header_parsed = false
8
+ content_length = nil
9
+
10
+ while char = STDIN.getc
11
+ buffer << char
12
+
13
+ unless header_parsed
14
+ if buffer[-4..-1] == "\r\n" * 2
15
+ content_length = buffer.match(/Content-Length: (\d+)/i)[1].to_i
16
+
17
+ header_parsed = true
18
+ buffer.clear
19
+ end
20
+ else
21
+ if buffer.bytesize == content_length
22
+ LanguageServer.logger.debug("Receive: #{buffer}")
23
+
24
+ request = JSON.parse(buffer, symbolize_names: true)
25
+
26
+ block.call(request)
27
+
28
+ header_parsed = false
29
+ buffer.clear
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,38 @@
1
+ module LanguageServer
2
+ module Protocol
3
+ module Stdio
4
+ class Writer
5
+ def respond(id:, result:)
6
+ write(id: id, result: result)
7
+ end
8
+
9
+ def notify(method:, params: {})
10
+ write(method: method, params: params)
11
+ end
12
+
13
+ private
14
+
15
+ def write(response)
16
+ response_str = response.merge(
17
+ jsonrpc: "2.0"
18
+ ).to_json
19
+
20
+ headers = {
21
+ "Content-Length" => response_str.bytesize
22
+ }
23
+
24
+ headers.each do |k, v|
25
+ STDOUT.print "#{k}: #{v}\r\n"
26
+ end
27
+
28
+ STDOUT.print "\r\n"
29
+
30
+ STDOUT.print response_str
31
+ STDOUT.flush
32
+
33
+ LanguageServer.logger.debug("Response: #{response_str}")
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,23 @@
1
+ module LanguageServer
2
+ class UriStore
3
+ class << self
4
+ def []=(uri, content)
5
+ store[uri] = content
6
+ end
7
+
8
+ def [](uri)
9
+ store[uri]
10
+ end
11
+
12
+ def clear
13
+ store.clear
14
+ end
15
+
16
+ private
17
+
18
+ def store
19
+ @store ||= {}
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module LanguageServer
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: language_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fumiaki MATSUSHIMA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-24 00:00:00.000000000 Z
11
+ date: 2017-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rcodetools
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -92,6 +106,7 @@ files:
92
106
  - ".vscode/settings.json"
93
107
  - CODE_OF_CONDUCT.md
94
108
  - Dockerfile
109
+ - Dockerfile-node.development
95
110
  - Dockerfile.development
96
111
  - Gemfile
97
112
  - LICENSE.txt
@@ -105,6 +120,7 @@ files:
105
120
  - exe/language_server
106
121
  - language_server.gemspec
107
122
  - lib/language_server.rb
123
+ - lib/language_server/completion_provider/rcodetools.rb
108
124
  - lib/language_server/linter/ruby_wc.rb
109
125
  - lib/language_server/protocol/constants.rb
110
126
  - lib/language_server/protocol/constants/completion_item_kind.rb
@@ -206,6 +222,10 @@ files:
206
222
  - lib/language_server/protocol/interfaces/workspace_client_capabilites.rb
207
223
  - lib/language_server/protocol/interfaces/workspace_edit.rb
208
224
  - lib/language_server/protocol/interfaces/workspace_symbol_params.rb
225
+ - lib/language_server/protocol/stdio.rb
226
+ - lib/language_server/protocol/stdio/reader.rb
227
+ - lib/language_server/protocol/stdio/writer.rb
228
+ - lib/language_server/uri_store.rb
209
229
  - lib/language_server/version.rb
210
230
  - package.json
211
231
  - scripts/generateFiles.ts