Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
/tmp/
/vendor/bundle/
/node_modules/
/.rubocop-*
45 changes: 45 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
inherit_from:
- https://github.com/onk/onkcop/raw/v0.51.0.0/config/rubocop.yml

AllCops:
TargetRubyVersion: 2.2
Exclude:
- 'bin/**/*'

# TODO: Remove this config after droping Ruby 2.2 support
Layout/IndentHeredoc:
Include:
- 'test/**/*'

Lint/AssignmentInCondition:
Enabled: false

Lint/HandleExceptions:
Enabled: false

Naming/HeredocDelimiterNaming:
Enabled: false

Style/BlockDelimiters:
Enabled: false

Style/MultilineBlockChain:
Enabled: false

Style/Semicolon:
Enabled: false

Metrics/AbcSize:
Max: 50

Metrics/BlockLength:
Max: 30

Metrics/MethodLength:
Max: 40

Metrics/ModuleLength:
Enabled: false

Metrics/LineLength:
Max: 200
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source 'https://rubygems.org'
source "https://rubygems.org"

# Specify your gem's dependencies in language_server.gemspec
gemspec

# TODO: Use released gem after new release includes https://github.com/bbatsov/rubocop/pull/4987
gem 'rubocop', git: 'https://github.com/bbatsov/rubocop'
gem "rubocop", git: "https://github.com/bbatsov/rubocop"
2 changes: 1 addition & 1 deletion Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ guard :minitest, all_after_pass: true do
watch(%r{^test/(.*)\/?test_(.*)\.rb$})
watch(%r{^test/(.*)\/?(.*)_test\.rb$})
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
watch(%r{^test/test_helper\.rb$}) { 'test' }
watch(%r{^test/test_helper\.rb$}) { "test" }
end
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require "rake/testtask"
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList['test/**/*_test.rb']
t.test_files = FileList["test/**/*_test.rb"]
end

task :default => :test
8 changes: 4 additions & 4 deletions benchmark/rubocop
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env ruby

require 'bundler/setup'
require 'benchmark/ips'
require 'language_server'
require "bundler/setup"
require "benchmark/ips"
require "language_server"

error_code = <<-EOS
require "foo
Expand All @@ -13,7 +13,7 @@ a = 1
EOS
valid_code = File.read(__FILE__)

require 'pry-byebug'
require "pry-byebug"

LanguageServer::Linter::Rubocop.new(valid_code).call
Benchmark.ips do |x|
Expand Down
6 changes: 3 additions & 3 deletions benchmark/ruby_wc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env ruby

require 'bundler/setup'
require 'benchmark/ips'
require 'language_server'
require "bundler/setup"
require "benchmark/ips"
require "language_server"

error_code = <<-EOS
require "foo
Expand Down
7 changes: 7 additions & 0 deletions bin/ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env sh

set -ex

bin/setup
bin/rubocop
bin/m
17 changes: 17 additions & 0 deletions bin/rubocop
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
#
# This file was generated by Bundler.
#
# The application 'rubocop' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rubocop", "rubocop")
3 changes: 1 addition & 2 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ jobs:
docker cp . project:/app
docker start project
docker-compose build $SERVICE_NAME
- run: docker-compose run $SERVICE_NAME bin/setup
- run: docker-compose run $SERVICE_NAME bin/m
- run: docker-compose run $SERVICE_NAME bin/ci
test-2-3:
<<: *test
docker:
Expand Down
26 changes: 13 additions & 13 deletions language_server.gemspec
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)

lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'language_server/version'
require "language_server/version"

Gem::Specification.new do |spec|
spec.name = "language_server"
spec.version = LanguageServer::VERSION
spec.authors = ["Fumiaki MATSUSHIMA"]
spec.email = ["mtsmfm@gmail.com"]

spec.summary = %q{A Ruby Language Server implementation}
spec.description = %q{A Ruby Language Server implementation}
spec.summary = "A Ruby Language Server implementation"
spec.description = "A Ruby Language Server implementation"
spec.homepage = "https://github.com/mtsmfm/language_server-ruby"
spec.license = "MIT"

Expand All @@ -19,24 +19,24 @@ Gem::Specification.new do |spec|
f.match(%r{^(test|spec|features)/})
end
rescue
Dir.glob("**/*").reject {|path| File.directory?(path) }
Dir.glob("**/*").reject { |path| File.directory?(path) }
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "rcodetools"
spec.add_dependency "language_server-protocol", "0.4.0"
spec.add_dependency "rcodetools"

spec.add_development_dependency "awesome_print"
spec.add_development_dependency "benchmark-ips"
spec.add_development_dependency "bundler", "~> 1.14"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "minitest", "~> 5.0"
spec.add_development_dependency "guard"
spec.add_development_dependency "guard-minitest"
spec.add_development_dependency "m"
spec.add_development_dependency "minitest", "~> 5.0"
spec.add_development_dependency "minitest-color"
spec.add_development_dependency "pry-byebug"
spec.add_development_dependency "minitest-power_assert"
spec.add_development_dependency "m"
spec.add_development_dependency "awesome_print"
spec.add_development_dependency "benchmark-ips"
spec.add_development_dependency "pry-byebug"
spec.add_development_dependency "rake", "~> 10.0"
end
28 changes: 13 additions & 15 deletions lib/language_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,14 @@ def notify(method:, params: {})

method = request[:method].to_sym

_, subscriber = subscribers.find {|k, _|
k === method
}
subscriber = subscribers[method]

if subscriber
keys = subscriber.parameters.map(&:last)
result = subscriber.call(
{
request: request, notifier: writer.method(:notify), variables: variables
}.merge(variables).select {|k, _| keys.include?(k) }
}.merge(variables).select { |k, _| keys.include?(k) },
)

if request[:id]
Expand Down Expand Up @@ -74,14 +72,14 @@ def on(method, &callback)
Protocol::Interface::InitializeResult.new(
capabilities: Protocol::Interface::ServerCapabilities.new(
text_document_sync: Protocol::Interface::TextDocumentSyncOptions.new(
change: Protocol::Constant::TextDocumentSyncKind::FULL
change: Protocol::Constant::TextDocumentSyncKind::FULL,
),
completion_provider: Protocol::Interface::CompletionOptions.new(
resolve_provider: true,
trigger_characters: %w(.)
trigger_characters: %w[.],
),
definition_provider: true
)
definition_provider: true,
),
)
end

Expand All @@ -103,22 +101,22 @@ def on(method, &callback)
range: Protocol::Interface::Range.new(
start: Protocol::Interface::Position.new(
line: error.line_num,
character: 0
character: 0,
),
end: Protocol::Interface::Position.new(
line: error.line_num,
character: 0
)
)
character: 0,
),
),
)
end

notifier.call(
method: :"textDocument/publishDiagnostics",
params: Protocol::Interface::PublishDiagnosticsParams.new(
uri: uri,
diagnostics: diagnostics
)
diagnostics: diagnostics,
),
)
end

Expand All @@ -128,7 +126,7 @@ def on(method, &callback)

[
CompletionProvider::AdHoc.new(uri: uri, line: line, character: character, project: project),
CompletionProvider::Rcodetools.new(uri: uri, line: line, character: character, file_store: file_store)
CompletionProvider::Rcodetools.new(uri: uri, line: line, character: character, file_store: file_store),
].flat_map(&:call)
end

Expand Down
14 changes: 7 additions & 7 deletions lib/language_server/completion_provider/ad_hoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,35 @@ def initialize(uri:, line:, character:, project:)
end

def call
(project.constants(uri: uri, line: line, character: character).map {|c|
(project.constants(uri: uri, line: line, character: character).map { |c|
Protocol::Interface::CompletionItem.new(
label: c.name,
detail: c.full_name,
documentation: "#{c.remote_path}##{c.lineno}",
kind: Protocol::Constant::CompletionItemKind::ENUM
kind: Protocol::Constant::CompletionItemKind::ENUM,
)
} +
project.classes(uri: uri, line: line, character: character).map {|c|
project.classes(uri: uri, line: line, character: character).map { |c|
Protocol::Interface::CompletionItem.new(
label: c.name,
detail: c.full_name,
documentation: "#{c.remote_path}##{c.lineno}",
kind: Protocol::Constant::CompletionItemKind::CLASS
kind: Protocol::Constant::CompletionItemKind::CLASS,
)
} +
project.modules(uri: uri, line: line, character: character).map {|m|
project.modules(uri: uri, line: line, character: character).map { |m|
Protocol::Interface::CompletionItem.new(
label: m.name,
detail: m.full_name,
documentation: "#{m.remote_path}##{m.lineno}",
kind: Protocol::Constant::CompletionItemKind::MODULE
kind: Protocol::Constant::CompletionItemKind::MODULE,
)
}).uniq(&:label)
end

private

attr_reader :uri, :line, :character, :project
attr_reader :uri, :line, :character, :project
end
end
end
8 changes: 4 additions & 4 deletions lib/language_server/completion_provider/rcodetools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ def call
Protocol::Interface::CompletionItem.new(
label: method_name,
detail: description,
kind: Protocol::Constant::CompletionItemKind::METHOD
kind: Protocol::Constant::CompletionItemKind::METHOD,
)
end
end

private

def source
@file_store.read_remote_uri(@uri)
end
def source
@file_store.read_remote_uri(@uri)
end
end
end
end
10 changes: 5 additions & 5 deletions lib/language_server/definition_provider/ad_hoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ def call
range: Protocol::Interface::Range.new(
start: Protocol::Interface::Position.new(
line: n.lines.begin,
character: 0
character: 0,
),
end: Protocol::Interface::Position.new(
line: n.lines.end,
character: 0
)
)
character: 0,
),
),
)
end
end

private

attr_reader :uri, :line, :character, :project
attr_reader :uri, :line, :character, :project
end
end
end
Loading