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 +5 -5
- data/.gitignore +1 -0
- data/.rubocop.yml +45 -0
- data/CHANGELOG.md +5 -0
- data/Dockerfile +2 -0
- data/Dockerfile.development +1 -1
- data/Gemfile +4 -1
- data/Guardfile +1 -1
- data/README.md +2 -0
- data/Rakefile +1 -1
- data/benchmark/rubocop +25 -0
- data/benchmark/ruby_wc +3 -3
- data/bin/ci +7 -0
- data/bin/rubocop +17 -0
- data/circle.yml +10 -2
- data/exe/language_server-ruby +23 -1
- data/language_server.gemspec +13 -14
- data/lib/language_server.rb +42 -25
- data/lib/language_server/completion_provider/ad_hoc.rb +7 -7
- data/lib/language_server/completion_provider/rcodetools.rb +4 -4
- data/lib/language_server/definition_provider/ad_hoc.rb +5 -5
- data/lib/language_server/file_store.rb +21 -21
- data/lib/language_server/linter/rubocop.rb +16 -18
- data/lib/language_server/linter/ruby_wc.rb +48 -37
- data/lib/language_server/logger.rb +12 -12
- data/lib/language_server/project.rb +34 -34
- data/lib/language_server/project/node.rb +15 -12
- data/lib/language_server/project/parser.rb +54 -54
- data/lib/language_server/version.rb +1 -1
- metadata +44 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8d1bb86816f7e13333c5e9fbc6ed4930d48dcc90b7c865fc10942ffd3e279fd2
|
4
|
+
data.tar.gz: 59f55973ed8a7fcba78d0172235baa6247ca755758533bd64f0516c13da491fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 015ee3cdc9cdf83bf92fc39f892c09aa27c5cf2161cc55da7168b67f58ad59214a9c38cdd10ffa3e3aeb6757dcd4c3c89c8564a1211ead9649b205acdb9da847
|
7
|
+
data.tar.gz: c5360bb9e9a02a8fa326dce7ebae9e331b8556534e692f7885f919430c9928c9cb9132371b78af3742bc410e03d8cc7ea922fa8ad09f0b085938c0797512a27f
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -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
|
data/CHANGELOG.md
CHANGED
data/Dockerfile
CHANGED
data/Dockerfile.development
CHANGED
data/Gemfile
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
source
|
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$}) {
|
8
|
+
watch(%r{^test/test_helper\.rb$}) { "test" }
|
9
9
|
end
|
data/README.md
CHANGED
data/Rakefile
CHANGED
data/benchmark/rubocop
ADDED
@@ -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
|
data/benchmark/ruby_wc
CHANGED
data/bin/ci
ADDED
data/bin/rubocop
ADDED
@@ -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/
|
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
|
data/exe/language_server-ruby
CHANGED
@@ -5,4 +5,26 @@ if Dir.exist?(File.join(__dir__, "..", ".git"))
|
|
5
5
|
end
|
6
6
|
|
7
7
|
require "language_server"
|
8
|
-
|
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)
|
data/language_server.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path(
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
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 =
|
13
|
-
spec.description =
|
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 "
|
40
|
-
spec.add_development_dependency "
|
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
|
data/lib/language_server.rb
CHANGED
@@ -13,7 +13,11 @@ require "json"
|
|
13
13
|
|
14
14
|
module LanguageServer
|
15
15
|
class << self
|
16
|
-
|
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
|
-
|
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] =
|
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:
|
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
|
-
|
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:
|
121
|
+
character: error.characters.min,
|
107
122
|
),
|
108
123
|
end: Protocol::Interface::Position.new(
|
109
124
|
line: error.line_num,
|
110
|
-
character:
|
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
|
-
|
131
|
-
|
132
|
-
|
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
|
-
|
141
|
-
|
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
|