language_server 0.9.0 → 0.10.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
- SHA1:
3
- metadata.gz: eea2a987076e6db2c0d04467487fbe2e23af67ca
4
- data.tar.gz: a171c9796c6cb96bc70175728d19f2ff093928e9
2
+ SHA256:
3
+ metadata.gz: 8d1bb86816f7e13333c5e9fbc6ed4930d48dcc90b7c865fc10942ffd3e279fd2
4
+ data.tar.gz: 59f55973ed8a7fcba78d0172235baa6247ca755758533bd64f0516c13da491fa
5
5
  SHA512:
6
- metadata.gz: 456d5911f25822d1fc2ffc270b4ea979a34aacb9fa79f283a7298f2647581032857242ce9e33afe6af2af8695fda533e2c93747c83fc378b12b1fb7bfdcf0124
7
- data.tar.gz: 39a4b4ab6984d4d55d6de26d480817d3eaab800d04c06389242e61bbd574bf514da8fec3f8ef3ea53b6ecf4177cb1947cb0dceaa6565d3c08808669f5d61c95b
6
+ metadata.gz: 015ee3cdc9cdf83bf92fc39f892c09aa27c5cf2161cc55da7168b67f58ad59214a9c38cdd10ffa3e3aeb6757dcd4c3c89c8564a1211ead9649b205acdb9da847
7
+ data.tar.gz: c5360bb9e9a02a8fa326dce7ebae9e331b8556534e692f7885f919430c9928c9cb9132371b78af3742bc410e03d8cc7ea922fa8ad09f0b085938c0797512a27f
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  /tmp/
10
10
  /vendor/bundle/
11
11
  /node_modules/
12
+ /.rubocop-*
@@ -0,0 +1,45 @@
1
+ inherit_from:
2
+ - https://github.com/onk/onkcop/raw/v0.51.0.0/config/rubocop.yml
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.2
6
+ Exclude:
7
+ - 'bin/**/*'
8
+
9
+ # TODO: Remove this config after droping Ruby 2.2 support
10
+ Layout/IndentHeredoc:
11
+ Include:
12
+ - 'test/**/*'
13
+
14
+ Lint/AssignmentInCondition:
15
+ Enabled: false
16
+
17
+ Lint/HandleExceptions:
18
+ Enabled: false
19
+
20
+ Naming/HeredocDelimiterNaming:
21
+ Enabled: false
22
+
23
+ Style/BlockDelimiters:
24
+ Enabled: false
25
+
26
+ Style/MultilineBlockChain:
27
+ Enabled: false
28
+
29
+ Style/Semicolon:
30
+ Enabled: false
31
+
32
+ Metrics/AbcSize:
33
+ Max: 50
34
+
35
+ Metrics/BlockLength:
36
+ Max: 30
37
+
38
+ Metrics/MethodLength:
39
+ Max: 40
40
+
41
+ Metrics/ModuleLength:
42
+ Enabled: false
43
+
44
+ Metrics/LineLength:
45
+ Max: 200
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Not released
4
4
 
5
+ ## 0.10.0
6
+
7
+ - Add --experimental-features flag
8
+ - Currently rubocop integration and adhoc provider are very unstable...
9
+
5
10
  ## 0.9.0
6
11
 
7
12
  - rubocop support #27
data/Dockerfile CHANGED
@@ -1,5 +1,7 @@
1
1
  FROM ruby:2.4.2-alpine
2
2
 
3
+ RUN apk add --no-cache git
4
+
3
5
  WORKDIR /app
4
6
 
5
7
  COPY lib/language_server/version.rb /app/lib/language_server/
@@ -11,4 +11,4 @@ ENV LANG=C.UTF-8 \
11
11
 
12
12
  USER ruby
13
13
  WORKDIR /app
14
- CMD ["bin/language_server-ruby"]
14
+ CMD ["bin/language_server-ruby", "--experimental-features"]
data/Gemfile CHANGED
@@ -1,4 +1,7 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in language_server.gemspec
4
4
  gemspec
5
+
6
+ # TODO: Use released gem after new release includes https://github.com/bbatsov/rubocop/pull/4987
7
+ gem "rubocop", git: "https://github.com/bbatsov/rubocop", ref: "88d9e3b"
data/Guardfile CHANGED
@@ -5,5 +5,5 @@ guard :minitest, all_after_pass: true do
5
5
  watch(%r{^test/(.*)\/?test_(.*)\.rb$})
6
6
  watch(%r{^test/(.*)\/?(.*)_test\.rb$})
7
7
  watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
8
- watch(%r{^test/test_helper\.rb$}) { 'test' }
8
+ watch(%r{^test/test_helper\.rb$}) { "test" }
9
9
  end
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # LanguageServer
2
2
 
3
+ [Alpha quality]
4
+
3
5
  A Ruby Language Server implementation.
4
6
 
5
7
  ## Installation
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require "rake/testtask"
4
4
  Rake::TestTask.new(:test) do |t|
5
5
  t.libs << "test"
6
6
  t.libs << "lib"
7
- t.test_files = FileList['test/**/*_test.rb']
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
8
  end
9
9
 
10
10
  task :default => :test
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "benchmark/ips"
5
+ require "language_server"
6
+
7
+ error_code = <<-EOS
8
+ require "foo
9
+ if a == "\\n"
10
+ EOS
11
+ warn_code = <<-EOS
12
+ a = 1
13
+ EOS
14
+ valid_code = File.read(__FILE__)
15
+
16
+ require "pry-byebug"
17
+
18
+ LanguageServer::Linter::Rubocop.new(valid_code).call
19
+ Benchmark.ips do |x|
20
+ x.report(`git log --pretty=oneline --abbrev-commit -n 1`) do
21
+ [error_code, warn_code, valid_code].each do |code|
22
+ LanguageServer::Linter::Rubocop.new(code).call
23
+ end
24
+ end
25
+ end
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'bundler/setup'
4
- require 'benchmark/ips'
5
- require 'language_server'
3
+ require "bundler/setup"
4
+ require "benchmark/ips"
5
+ require "language_server"
6
6
 
7
7
  error_code = <<-EOS
8
8
  require "foo
data/bin/ci ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env sh
2
+
3
+ set -ex
4
+
5
+ bin/setup
6
+ bin/rubocop
7
+ bin/m
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rubocop' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("rubocop", "rubocop")
data/circle.yml CHANGED
@@ -20,8 +20,7 @@ jobs:
20
20
  docker cp . project:/app
21
21
  docker start project
22
22
  docker-compose build $SERVICE_NAME
23
- - run: docker-compose run $SERVICE_NAME bin/setup
24
- - run: docker-compose run $SERVICE_NAME bin/m
23
+ - run: docker-compose run $SERVICE_NAME bin/ci
25
24
  test-2-3:
26
25
  <<: *test
27
26
  docker:
@@ -36,6 +35,14 @@ jobs:
36
35
  environment:
37
36
  COMPOSE_FILE: docker-compose.yml:docker-compose.ci.yml
38
37
  SERVICE_NAME: ruby-2-2
38
+ test-docker-build:
39
+ docker:
40
+ - image: docker
41
+ steps:
42
+ - checkout
43
+ - setup_remote_docker:
44
+ version: 17.05.0-ce
45
+ - run: docker build .
39
46
  workflows:
40
47
  version: 2
41
48
  test:
@@ -43,3 +50,4 @@ workflows:
43
50
  - test-2-4
44
51
  - test-2-3
45
52
  - test-2-2
53
+ - test-docker-build
@@ -5,4 +5,26 @@ if Dir.exist?(File.join(__dir__, "..", ".git"))
5
5
  end
6
6
 
7
7
  require "language_server"
8
- LanguageServer.run
8
+ require "optparse"
9
+
10
+ options = { experimental_features_enabled: false }
11
+ opt_parser = OptionParser.new do |opts|
12
+ opts.banner = "Usage: language_server-ruby [options]"
13
+
14
+ opts.on("--experimental-features", "Enable experimental features") do |e|
15
+ options[:experimental_features_enabled] = e
16
+ end
17
+
18
+ opts.on("-v", "--version", "Show version") do
19
+ puts LanguageServer::VERSION
20
+ exit
21
+ end
22
+ end
23
+ begin
24
+ opt_parser.parse!
25
+ rescue OptionParser::InvalidOption
26
+ puts opt_parser
27
+ exit 1
28
+ end
29
+
30
+ LanguageServer.run(options)
@@ -1,7 +1,7 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'language_server/version'
4
+ require "language_server/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "language_server"
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Fumiaki MATSUSHIMA"]
10
10
  spec.email = ["mtsmfm@gmail.com"]
11
11
 
12
- spec.summary = %q{A Ruby Language Server implementation}
13
- spec.description = %q{A Ruby Language Server implementation}
12
+ spec.summary = "A Ruby Language Server implementation"
13
+ spec.description = "A Ruby Language Server implementation"
14
14
  spec.homepage = "https://github.com/mtsmfm/language_server-ruby"
15
15
  spec.license = "MIT"
16
16
 
@@ -19,25 +19,24 @@ Gem::Specification.new do |spec|
19
19
  f.match(%r{^(test|spec|features)/})
20
20
  end
21
21
  rescue
22
- Dir.glob("**/*").reject {|path| File.directory?(path) }
22
+ Dir.glob("**/*").reject { |path| File.directory?(path) }
23
23
  end
24
24
  spec.bindir = "exe"
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
  spec.add_dependency "language_server-protocol", "0.4.0"
29
+ spec.add_dependency "rcodetools"
30
30
 
31
+ spec.add_development_dependency "awesome_print"
32
+ spec.add_development_dependency "benchmark-ips"
31
33
  spec.add_development_dependency "bundler", "~> 1.14"
32
- spec.add_development_dependency "rake", "~> 10.0"
33
- spec.add_development_dependency "minitest", "~> 5.0"
34
34
  spec.add_development_dependency "guard"
35
35
  spec.add_development_dependency "guard-minitest"
36
+ spec.add_development_dependency "m"
37
+ spec.add_development_dependency "minitest", "~> 5.0"
36
38
  spec.add_development_dependency "minitest-color"
37
- spec.add_development_dependency "pry-byebug"
38
39
  spec.add_development_dependency "minitest-power_assert"
39
- spec.add_development_dependency "m"
40
- spec.add_development_dependency "awesome_print"
41
- spec.add_development_dependency "benchmark-ips"
42
- spec.add_development_dependency "rubocop"
40
+ spec.add_development_dependency "pry-byebug"
41
+ spec.add_development_dependency "rake", "~> 12.2"
43
42
  end
@@ -13,7 +13,11 @@ require "json"
13
13
 
14
14
  module LanguageServer
15
15
  class << self
16
- def run
16
+ attr_accessor :options
17
+
18
+ def run(options)
19
+ self.options = options
20
+
17
21
  writer = Protocol::Transport::Stdio::Writer.new
18
22
  reader = Protocol::Transport::Stdio::Reader.new
19
23
  variables = {}
@@ -37,16 +41,14 @@ module LanguageServer
37
41
 
38
42
  method = request[:method].to_sym
39
43
 
40
- _, subscriber = subscribers.find {|k, _|
41
- k === method
42
- }
44
+ subscriber = subscribers[method]
43
45
 
44
46
  if subscriber
45
47
  keys = subscriber.parameters.map(&:last)
46
48
  result = subscriber.call(
47
49
  {
48
50
  request: request, notifier: writer.method(:notify), variables: variables
49
- }.merge(variables).select {|k, _| keys.include?(k) }
51
+ }.merge(variables).select { |k, _| keys.include?(k) },
50
52
  )
51
53
 
52
54
  if request[:id]
@@ -58,6 +60,14 @@ module LanguageServer
58
60
  end
59
61
  end
60
62
 
63
+ def rubocop_enabled?
64
+ options[:experimental_features_enabled]
65
+ end
66
+
67
+ def adhoc_enabled?
68
+ options[:experimental_features_enabled]
69
+ end
70
+
61
71
  def subscribers
62
72
  @subscribers ||= {}
63
73
  end
@@ -69,19 +79,22 @@ module LanguageServer
69
79
 
70
80
  on :initialize do |request:, variables:|
71
81
  variables[:file_store] = FileStore.new(load_paths: $LOAD_PATH, remote_root: request[:params][:rootPath], local_root: Dir.getwd)
72
- variables[:project] = Project.new(variables[:file_store])
82
+ variables[:project] =
83
+ if LanguageServer.adhoc_enabled?
84
+ variables[:project] = Project.new(variables[:file_store])
85
+ end
73
86
 
74
87
  Protocol::Interface::InitializeResult.new(
75
88
  capabilities: Protocol::Interface::ServerCapabilities.new(
76
89
  text_document_sync: Protocol::Interface::TextDocumentSyncOptions.new(
77
- change: Protocol::Constant::TextDocumentSyncKind::FULL
90
+ change: Protocol::Constant::TextDocumentSyncKind::FULL,
78
91
  ),
79
92
  completion_provider: Protocol::Interface::CompletionOptions.new(
80
93
  resolve_provider: true,
81
- trigger_characters: %w(.)
94
+ trigger_characters: %w[.],
82
95
  ),
83
- definition_provider: true
84
- )
96
+ definition_provider: LanguageServer.adhoc_enabled?,
97
+ ),
85
98
  )
86
99
  end
87
100
 
@@ -93,8 +106,10 @@ module LanguageServer
93
106
  uri = request[:params][:textDocument][:uri]
94
107
  text = request[:params][:contentChanges][0][:text]
95
108
  file_store.cache(uri, text)
96
- project.recalculate_result(uri)
97
- diagnostics = (Linter::Rubocop.new(text).call + Linter::RubyWC.new(text).call).flatten
109
+ project.recalculate_result(uri) if LanguageServer.adhoc_enabled?
110
+
111
+ diagnostics = Linter::RubyWC.new(text).call
112
+ diagnostics += Linter::Rubocop.new(text).call if LanguageServer.rubocop_enabled?
98
113
 
99
114
  diagnostics = diagnostics.map do |error|
100
115
  Protocol::Interface::Diagnostic.new(
@@ -103,13 +118,13 @@ module LanguageServer
103
118
  range: Protocol::Interface::Range.new(
104
119
  start: Protocol::Interface::Position.new(
105
120
  line: error.line_num,
106
- character: 0
121
+ character: error.characters.min,
107
122
  ),
108
123
  end: Protocol::Interface::Position.new(
109
124
  line: error.line_num,
110
- character: 0
111
- )
112
- )
125
+ character: error.characters.max,
126
+ ),
127
+ ),
113
128
  )
114
129
  end
115
130
 
@@ -117,8 +132,8 @@ module LanguageServer
117
132
  method: :"textDocument/publishDiagnostics",
118
133
  params: Protocol::Interface::PublishDiagnosticsParams.new(
119
134
  uri: uri,
120
- diagnostics: diagnostics
121
- )
135
+ diagnostics: diagnostics,
136
+ ),
122
137
  )
123
138
  end
124
139
 
@@ -126,18 +141,20 @@ module LanguageServer
126
141
  uri = request[:params][:textDocument][:uri]
127
142
  line, character = request[:params][:position].fetch_values(:line, :character).map(&:to_i)
128
143
 
129
- [
130
- CompletionProvider::AdHoc.new(uri: uri, line: line, character: character, project: project),
131
- CompletionProvider::Rcodetools.new(uri: uri, line: line, character: character, file_store: file_store)
132
- ].flat_map(&:call)
144
+ providers = [CompletionProvider::Rcodetools.new(uri: uri, line: line, character: character, file_store: file_store)]
145
+ providers << CompletionProvider::AdHoc.new(uri: uri, line: line, character: character, project: project) if LanguageServer.adhoc_enabled?
146
+
147
+ providers.flat_map(&:call)
133
148
  end
134
149
 
135
150
  on :"textDocument/definition" do |request:, project:|
136
151
  uri = request[:params][:textDocument][:uri]
137
152
  line, character = request[:params][:position].fetch_values(:line, :character).map(&:to_i)
138
153
 
139
- [
140
- DefinitionProvider::AdHoc.new(uri: uri, line: line, character: character, project: project),
141
- ].flat_map(&:call)
154
+ if LanguageServer.adhoc_enabled?
155
+ [
156
+ DefinitionProvider::AdHoc.new(uri: uri, line: line, character: character, project: project),
157
+ ].flat_map(&:call)
158
+ end
142
159
  end
143
160
  end