Skip to content

Commit 06890fe

Browse files
authored
Merge pull request #17 from mtsmfm/protocol-gem
Extract language_server-protocol gem
2 parents 67c016f + 3bfe10a commit 06890fe

File tree

115 files changed

+47
-4832
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+47
-4832
lines changed

Dockerfile-node.development

Lines changed: 0 additions & 6 deletions
This file was deleted.

bin/generate_files

Lines changed: 0 additions & 5 deletions
This file was deleted.

circle.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ jobs:
2525
name: test
2626
command: |
2727
set -x
28-
docker-compose run node bin/generate_files
2928
docker-compose run app bin/m
3029
docker-compose run ruby-2-3 bin/m
3130
docker-compose run ruby-2-2 bin/m

docker-compose.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ services:
2424
<<: *app-build
2525
args:
2626
RUBY_VERSION: 2.2
27-
node:
28-
build:
29-
context: .
30-
dockerfile: Dockerfile-node.development
31-
volumes:
32-
- mtsmfm-language-server-sync:/app:nocopy
33-
- home:/home/node
3427
volumes:
3528
mtsmfm-language-server-sync:
3629
external: true

language_server.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
2626
spec.require_paths = ["lib"]
2727

2828
spec.add_dependency "rcodetools"
29+
spec.add_dependency "language_server-protocol", "0.3.0"
2930

3031
spec.add_development_dependency "bundler", "~> 1.14"
3132
spec.add_development_dependency "rake", "~> 10.0"

lib/language_server.rb

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
require "language_server/version"
22
require "language_server/logger"
3-
require "language_server/protocol/interfaces"
4-
require "language_server/protocol/constants"
5-
require "language_server/protocol/stdio"
3+
require "language_server/protocol"
64
require "language_server/linter/ruby_wc"
75
require "language_server/completion_provider/rcodetools"
86
require "language_server/completion_provider/ad_hoc"
@@ -15,14 +13,28 @@
1513
module LanguageServer
1614
class << self
1715
def run
18-
writer = Protocol::Stdio::Writer.new
19-
reader = Protocol::Stdio::Reader.new
16+
writer = Protocol::Transport::Stdio::Writer.new
17+
reader = Protocol::Transport::Stdio::Reader.new
2018
variables = {}
2119

20+
class << writer
21+
def respond(id:, result:)
22+
write(id: id, result: result)
23+
24+
LanguageServer.logger.debug("Respond: id: #{id}, result: #{JSON.pretty_generate(result)}")
25+
end
26+
27+
def notify(method:, params: {})
28+
write(method: method, params: params)
29+
30+
LanguageServer.logger.debug("Notify: method: #{method}, params: #{JSON.pretty_generate(params)}")
31+
end
32+
end
33+
2234
reader.read do |request|
23-
method = request[:method].to_sym
35+
logger.debug("Receive: #{JSON.pretty_generate(request)}")
2436

25-
logger.debug("Method: #{method} called")
37+
method = request[:method].to_sym
2638

2739
_, subscriber = subscribers.find {|k, _|
2840
k === method
@@ -58,12 +70,12 @@ def on(method, &callback)
5870
variables[:file_store] = FileStore.new(load_paths: $LOAD_PATH, remote_root: request[:params][:rootPath], local_root: Dir.getwd)
5971
variables[:project] = Project.new(variables[:file_store])
6072

61-
Protocol::Interfaces::InitializeResult.new(
62-
capabilities: Protocol::Interfaces::ServerCapabilities.new(
63-
text_document_sync: Protocol::Interfaces::TextDocumentSyncOptions.new(
64-
change: Protocol::Constants::TextDocumentSyncKind::FULL
73+
Protocol::Interface::InitializeResult.new(
74+
capabilities: Protocol::Interface::ServerCapabilities.new(
75+
text_document_sync: Protocol::Interface::TextDocumentSyncOptions.new(
76+
change: Protocol::Constant::TextDocumentSyncKind::FULL
6577
),
66-
completion_provider: Protocol::Interfaces::CompletionOptions.new(
78+
completion_provider: Protocol::Interface::CompletionOptions.new(
6779
resolve_provider: true,
6880
trigger_characters: %w(.)
6981
),
@@ -83,15 +95,15 @@ def on(method, &callback)
8395
project.recalculate_result(uri)
8496

8597
diagnostics = Linter::RubyWC.new(text).call.map do |error|
86-
Protocol::Interfaces::Diagnostic.new(
98+
Protocol::Interface::Diagnostic.new(
8799
message: error.message,
88-
severity: error.warning? ? Protocol::Constants::DiagnosticSeverity::WARNING : Protocol::Constants::DiagnosticSeverity::ERROR,
89-
range: Protocol::Interfaces::Range.new(
90-
start: Protocol::Interfaces::Position.new(
100+
severity: error.warning? ? Protocol::Constant::DiagnosticSeverity::WARNING : Protocol::Constant::DiagnosticSeverity::ERROR,
101+
range: Protocol::Interface::Range.new(
102+
start: Protocol::Interface::Position.new(
91103
line: error.line_num,
92104
character: 0
93105
),
94-
end: Protocol::Interfaces::Position.new(
106+
end: Protocol::Interface::Position.new(
95107
line: error.line_num,
96108
character: 0
97109
)
@@ -101,7 +113,7 @@ def on(method, &callback)
101113

102114
notifier.call(
103115
method: :"textDocument/publishDiagnostics",
104-
params: Protocol::Interfaces::PublishDiagnosticsParams.new(
116+
params: Protocol::Interface::PublishDiagnosticsParams.new(
105117
uri: uri,
106118
diagnostics: diagnostics
107119
)

lib/language_server/completion_provider/ad_hoc.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@ def initialize(uri:, line:, character:, project:)
1212

1313
def call
1414
(project.constants(uri: uri, line: line, character: character).map {|c|
15-
Protocol::Interfaces::CompletionItem.new(
15+
Protocol::Interface::CompletionItem.new(
1616
label: c.name,
1717
detail: c.full_name,
1818
documentation: "#{c.remote_path}##{c.lineno}",
19-
kind: Protocol::Constants::CompletionItemKind::ENUM
19+
kind: Protocol::Constant::CompletionItemKind::ENUM
2020
)
2121
} +
2222
project.classes(uri: uri, line: line, character: character).map {|c|
23-
Protocol::Interfaces::CompletionItem.new(
23+
Protocol::Interface::CompletionItem.new(
2424
label: c.name,
2525
detail: c.full_name,
2626
documentation: "#{c.remote_path}##{c.lineno}",
27-
kind: Protocol::Constants::CompletionItemKind::CLASS
27+
kind: Protocol::Constant::CompletionItemKind::CLASS
2828
)
2929
} +
3030
project.modules(uri: uri, line: line, character: character).map {|m|
31-
Protocol::Interfaces::CompletionItem.new(
31+
Protocol::Interface::CompletionItem.new(
3232
label: m.name,
3333
detail: m.full_name,
3434
documentation: "#{m.remote_path}##{m.lineno}",
35-
kind: Protocol::Constants::CompletionItemKind::MODULE
35+
kind: Protocol::Constant::CompletionItemKind::MODULE
3636
)
3737
}).uniq(&:label)
3838
end

lib/language_server/completion_provider/rcodetools.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
require "language_server/protocol/interfaces/completion_item"
2-
require "language_server/protocol/constants/completion_item_kind"
3-
1+
require "language_server/protocol"
42
require "rcodetools/completion"
53

64
module LanguageServer
@@ -27,10 +25,10 @@ def call
2725
_, candidates = Filter.run(source, lineno: @line + 1, column: @character)
2826
candidates.map do |candidate|
2927
method_name, description = candidate.split(/\0/, 2)
30-
Protocol::Interfaces::CompletionItem.new(
28+
Protocol::Interface::CompletionItem.new(
3129
label: method_name,
3230
detail: description,
33-
kind: Protocol::Constants::CompletionItemKind::METHOD
31+
kind: Protocol::Constant::CompletionItemKind::METHOD
3432
)
3533
end
3634
end

lib/language_server/definition_provider/ad_hoc.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ def initialize(uri:, line:, character:, project:)
1010

1111
def call
1212
project.find_definitions(uri: uri, line: line, character: character).map do |n|
13-
Protocol::Interfaces::Location.new(
13+
Protocol::Interface::Location.new(
1414
uri: "file://#{n.remote_path}",
15-
range: Protocol::Interfaces::Range.new(
16-
start: Protocol::Interfaces::Position.new(
15+
range: Protocol::Interface::Range.new(
16+
start: Protocol::Interface::Position.new(
1717
line: n.lines.begin,
1818
character: 0
1919
),
20-
end: Protocol::Interfaces::Position.new(
20+
end: Protocol::Interface::Position.new(
2121
line: n.lines.end,
2222
character: 0
2323
)

lib/language_server/protocol/constants.rb

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)