language_server 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb3d5efef80939d80e555bd2173a99dc75236902
4
- data.tar.gz: 7931d63a410433d50c168bd346aa37aefba6ef06
3
+ metadata.gz: d4ad7bdb98ed0fdc4c493cecd7c296fc551d23c0
4
+ data.tar.gz: a458cc4c3aaf8b95d5ae5780fb9896d157476e8e
5
5
  SHA512:
6
- metadata.gz: cd985bbe11b1255562895515d1720e99b53e63158aec075129c68d3519050f5495e18c206162ef4912f6c5959112dd5a68532329551947d3df681ab6af3df7e0
7
- data.tar.gz: 19e6365472be889919c633cda694f93e71cf3e26a12afb88648fae7ace4934b383d64947b258cd5f9b3c925c8ba448f506640c5401059f06a189b4d304239624
6
+ metadata.gz: 8cd2bf30dd8548f44fa82dd28530f694fce2b68445de389a1945d754ce56de2f96ec8a7fb9ad40c3225a1d017a433a0e88b5193e3773f52075fe0a9e71fd344d
7
+ data.tar.gz: e37e1fd641490f0ab03deb515fec382724248231f59ffc179e6ea3c4cc5ef6722a503cf3cfd5f65dbea336049afe1090dbfe99d528764c7d27b1a8cac7cb548a
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  /tmp/
10
10
  /vendor/bundle/
11
11
  /node_modules/
12
+ /.docker-sync
@@ -0,0 +1,5 @@
1
+ {
2
+ "ruby-lsc.commandWithArgs": [
3
+ "docker-compose", "run", "--rm", "app"
4
+ ]
5
+ }
data/Dockerfile CHANGED
@@ -1,13 +1,13 @@
1
- FROM ruby:2.4.1
1
+ FROM ruby:2.4.1-alpine
2
2
 
3
- RUN apt-get update && apt-get install less -y
4
- RUN groupadd --gid 1000 ruby && useradd --uid 1000 --gid ruby --shell /bin/bash --create-home ruby
5
- RUN mkdir /app && chown ruby:ruby /app
3
+ WORKDIR /app
6
4
 
7
- ENV LANG=C.UTF-8 \
8
- BUNDLE_PATH=/app/vendor/bundle \
9
- BUNDLE_JOBS=4
5
+ COPY lib/language_server/version.rb /app/lib/language_server/
6
+ COPY Gemfile language_server.gemspec /app/
7
+
8
+ RUN bundle install --without development
9
+
10
+ COPY lib /app/lib/
11
+ COPY exe /app/exe/
10
12
 
11
- USER ruby
12
- WORKDIR /app
13
13
  CMD ["bundle", "exec", "exe/language_server"]
@@ -0,0 +1,13 @@
1
+ FROM ruby:2.4.1
2
+
3
+ RUN apt-get update && apt-get install less -y
4
+ RUN groupadd --gid 1000 ruby && useradd --uid 1000 --gid ruby --shell /bin/bash --create-home ruby
5
+ RUN mkdir /app && chown ruby:ruby /app
6
+
7
+ ENV LANG=C.UTF-8 \
8
+ BUNDLE_PATH=/app/vendor/bundle \
9
+ BUNDLE_JOBS=4
10
+
11
+ USER ruby
12
+ WORKDIR /app
13
+ CMD ["bundle", "exec", "exe/language_server"]
data/README.md CHANGED
@@ -1,11 +1,19 @@
1
1
  # LanguageServer
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/language_server`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ A Ruby Language Server implementation.
6
4
 
7
5
  ## Installation
8
6
 
7
+ If you are using vscode, instal [ruby-lsc](https://marketplace.visualstudio.com/items?itemName=mtsmfm.ruby-lsc) extension.
8
+
9
+ ### Docker
10
+
11
+ Simply you can pull from [docker hub](https://hub.docker.com/r/mtsmfm/language_server-ruby/)
12
+
13
+ $ docker pull mtsmfm/language_server-ruby
14
+
15
+ ### Ruby gem
16
+
9
17
  Add this line to your application's Gemfile:
10
18
 
11
19
  ```ruby
@@ -22,13 +30,38 @@ Or install it yourself as:
22
30
 
23
31
  ## Usage
24
32
 
25
- TODO: Write usage instructions here
33
+ Currently, language_server-ruby supports only stdio to communicate.
34
+
35
+ ### Docker
36
+
37
+ $ docker run mtsmfm/language_server-ruby
38
+
39
+ ### Ruby gem
40
+
41
+ $ language_server
26
42
 
27
43
  ## Development
28
44
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
45
+ ### Requirements
46
+
47
+ #### docker, docker-compose
48
+
49
+ https://docs.docker.com/engine/installation
50
+
51
+ #### docker-sync
52
+
53
+ https://github.com/EugenMayer/docker-sync/wiki/1.-Installation
54
+
55
+ ### Setup
56
+
57
+ $ git clone https://github.com/mtsmfm/language_server-ruby.git
58
+ $ cs language_server-ruby
59
+ $ docker-sync start
60
+ $ docker-compose run app bin/setup
61
+
62
+ ### Run test
30
63
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
64
+ $ docker-compose run app bundle exec rake test
32
65
 
33
66
  ## Contributing
34
67
 
data/docker-compose.yml CHANGED
@@ -1,9 +1,11 @@
1
- version: '3.2'
1
+ version: '3.0'
2
2
  services:
3
3
  app:
4
- build: .
4
+ build:
5
+ context: .
6
+ dockerfile: Dockerfile.development
5
7
  volumes:
6
- - ./:/app
8
+ - app-sync:/app:nocopy
7
9
  - home:/home/ruby
8
10
  - $HOME:/$HOME
9
11
  - $HOME/.gitconfig:/home/ruby/.gitconfig:ro
@@ -14,7 +16,9 @@ services:
14
16
  user: node
15
17
  working_dir: /app
16
18
  volumes:
17
- - ./:/app
19
+ - app-sync/:/app
18
20
  - home:/home/node
19
21
  volumes:
22
+ app-sync:
23
+ external: true
20
24
  home:
data/docker-sync.yml ADDED
@@ -0,0 +1,7 @@
1
+ version: '2'
2
+ options:
3
+ verbose: true
4
+ syncs:
5
+ app-sync:
6
+ src: .
7
+ sync_userid: 1000
@@ -9,13 +9,17 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Fumiaki MATSUSHIMA"]
10
10
  spec.email = ["mtsmfm@gmail.com"]
11
11
 
12
- spec.summary = %q{}
13
- spec.description = %q{}
12
+ spec.summary = %q{A Ruby Language Server implementation}
13
+ spec.description = %q{A Ruby Language Server implementation}
14
14
  spec.homepage = "https://github.com/mtsmfm/language_server-ruby"
15
15
  spec.license = "MIT"
16
16
 
17
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
- f.match(%r{^(test|spec|features)/})
17
+ spec.files = begin
18
+ `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ rescue
22
+ Dir.glob("**/*").reject {|path| File.directory?(path) }
19
23
  end
20
24
  spec.bindir = "exe"
21
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
@@ -25,4 +29,5 @@ Gem::Specification.new do |spec|
25
29
  spec.add_development_dependency "rake", "~> 10.0"
26
30
  spec.add_development_dependency "minitest", "~> 5.0"
27
31
  spec.add_development_dependency "pry-byebug"
32
+ spec.add_development_dependency "minitest-power_assert"
28
33
  end
@@ -0,0 +1,37 @@
1
+ require "open3"
2
+
3
+ module LanguageServer
4
+ module Linter
5
+ class Error
6
+ attr_reader :line_num, :message, :type
7
+
8
+ def initialize(line_num:, message:, type:)
9
+ @line_num = line_num
10
+ @message = message
11
+ @type = type
12
+ end
13
+
14
+ def warning?
15
+ @type == "warning"
16
+ end
17
+
18
+ def ==(other)
19
+ line_num == other.line_num && message == other.message
20
+ end
21
+ end
22
+
23
+ class RubyWC
24
+ def initialize(source)
25
+ @source = source
26
+ end
27
+
28
+ def call
29
+ _, err, _ = Open3.capture3("ruby -wc", stdin_data: @source)
30
+
31
+ err.scan(/.+:(\d+):\s*(.+?)[,:]\s(.+)/).map do |line_num, type, message|
32
+ Error.new(line_num: line_num.to_i, message: message, type: type)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,3 +1,3 @@
1
1
  module LanguageServer
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,6 +1,7 @@
1
1
  require "language_server/version"
2
2
  require "language_server/protocol/interfaces"
3
3
  require "language_server/protocol/constants"
4
+ require "language_server/linter/ruby_wc"
4
5
 
5
6
  require "json"
6
7
  require "logger"
@@ -132,43 +133,27 @@ module LanguageServer
132
133
  end
133
134
 
134
135
  on :"textDocument/didChange" do |request, notifier|
135
- uri = request[:params][:textDocument][:uri]
136
- text = request[:params][:contentChanges][0][:text]
137
-
138
- diagnostics = nil
139
-
140
- Tempfile.create do |file|
141
- file.write(text)
142
- file.flush
143
-
144
- out, err, status = Open3.capture3("ruby -wc #{file.path.shellescape}")
145
- severity = status.success? ? Protocol::Constants::DiagnosticSeverity::WARNING : Protocol::Constants::DiagnosticSeverity::ERROR
146
-
147
- diagnostics = err.lines.map do |line|
148
- line_num, message = line.scan(/#{Regexp.escape(file.path)}:(\d+): (.*)\n/).flatten
149
- line_num = line_num.to_i
150
-
151
- Protocol::Interfaces::Diagnostic.new(
152
- message: message,
153
- severity: severity,
154
- range: Protocol::Interfaces::Range.new(
155
- start: Protocol::Interfaces::Position.new(
156
- line: line_num.to_i - 1,
157
- character: 0
158
- ),
159
- end: Protocol::Interfaces::Position.new(
160
- line: line_num.to_i - 1,
161
- character: 0
162
- )
136
+ diagnostics = Linter::RubyWC.new(request[:params][:contentChanges][0][:text]).call.map do |error|
137
+ Protocol::Interfaces::Diagnostic.new(
138
+ message: error.message,
139
+ severity: error.warning? ? Protocol::Constants::DiagnosticSeverity::WARNING : Protocol::Constants::DiagnosticSeverity::ERROR,
140
+ range: Protocol::Interfaces::Range.new(
141
+ start: Protocol::Interfaces::Position.new(
142
+ line: error.line_num,
143
+ character: 0
144
+ ),
145
+ end: Protocol::Interfaces::Position.new(
146
+ line: error.line_num,
147
+ character: 0
163
148
  )
164
149
  )
165
- end
150
+ )
166
151
  end
167
152
 
168
153
  notifier.call(
169
154
  method: :"textDocument/publishDiagnostics",
170
155
  params: Protocol::Interfaces::PublishDiagnosticsParams.new(
171
- uri: uri,
156
+ uri: request[:params][:textDocument][:uri],
172
157
  diagnostics: diagnostics
173
158
  )
174
159
  )
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: language_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.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-19 00:00:00.000000000 Z
11
+ date: 2017-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,7 +66,21 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description: ''
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-power_assert
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: A Ruby Language Server implementation
70
84
  email:
71
85
  - mtsmfm@gmail.com
72
86
  executables:
@@ -75,9 +89,10 @@ extensions: []
75
89
  extra_rdoc_files: []
76
90
  files:
77
91
  - ".gitignore"
92
+ - ".vscode/settings.json"
78
93
  - CODE_OF_CONDUCT.md
79
94
  - Dockerfile
80
- - Dockerfile.production
95
+ - Dockerfile.development
81
96
  - Gemfile
82
97
  - LICENSE.txt
83
98
  - README.md
@@ -86,9 +101,11 @@ files:
86
101
  - bin/generate_files
87
102
  - bin/setup
88
103
  - docker-compose.yml
104
+ - docker-sync.yml
89
105
  - exe/language_server
90
106
  - language_server.gemspec
91
107
  - lib/language_server.rb
108
+ - lib/language_server/linter/ruby_wc.rb
92
109
  - lib/language_server/protocol/constants.rb
93
110
  - lib/language_server/protocol/constants/completion_item_kind.rb
94
111
  - lib/language_server/protocol/constants/diagnostic_severity.rb
@@ -216,5 +233,5 @@ rubyforge_project:
216
233
  rubygems_version: 2.6.12
217
234
  signing_key:
218
235
  specification_version: 4
219
- summary: ''
236
+ summary: A Ruby Language Server implementation
220
237
  test_files: []
@@ -1,5 +0,0 @@
1
- FROM ruby:2.4.1-alpine
2
-
3
- RUN gem install language_server
4
-
5
- CMD ["language_server"]