language_server 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/bin/console +6 -0
  3. data/circle.yml +0 -1
  4. data/docker-compose.yml +2 -7
  5. data/language_server.gemspec +1 -0
  6. data/lib/language_server/completion_provider/ad_hoc.rb +6 -6
  7. data/lib/language_server/completion_provider/rcodetools.rb +3 -5
  8. data/lib/language_server/definition_provider/ad_hoc.rb +34 -0
  9. data/lib/language_server/logger.rb +37 -0
  10. data/lib/language_server/project/node.rb +65 -1
  11. data/lib/language_server/project/parser.rb +40 -10
  12. data/lib/language_server/project.rb +20 -3
  13. data/lib/language_server/version.rb +1 -1
  14. data/lib/language_server.rb +43 -24
  15. metadata +19 -110
  16. data/Dockerfile-node.development +0 -6
  17. data/bin/generate_files +0 -5
  18. data/lib/language_server/protocol/constants/completion_item_kind.rb +0 -29
  19. data/lib/language_server/protocol/constants/diagnostic_severity.rb +0 -24
  20. data/lib/language_server/protocol/constants/document_highlight_kind.rb +0 -23
  21. data/lib/language_server/protocol/constants/error_codes.rb +0 -18
  22. data/lib/language_server/protocol/constants/file_change_type.rb +0 -23
  23. data/lib/language_server/protocol/constants/initialize_error.rb +0 -15
  24. data/lib/language_server/protocol/constants/insert_text_format.rb +0 -27
  25. data/lib/language_server/protocol/constants/message_type.rb +0 -24
  26. data/lib/language_server/protocol/constants/symbol_kind.rb +0 -29
  27. data/lib/language_server/protocol/constants/text_document_save_reason.rb +0 -24
  28. data/lib/language_server/protocol/constants/text_document_sync_kind.rb +0 -26
  29. data/lib/language_server/protocol/constants.rb +0 -11
  30. data/lib/language_server/protocol/interfaces/apply_workspace_edit_params.rb +0 -29
  31. data/lib/language_server/protocol/interfaces/apply_workspace_edit_response.rb +0 -29
  32. data/lib/language_server/protocol/interfaces/cancel_params.rb +0 -29
  33. data/lib/language_server/protocol/interfaces/client_capabilities.rb +0 -47
  34. data/lib/language_server/protocol/interfaces/code_action_context.rb +0 -33
  35. data/lib/language_server/protocol/interfaces/code_action_params.rb +0 -50
  36. data/lib/language_server/protocol/interfaces/code_lens.rb +0 -55
  37. data/lib/language_server/protocol/interfaces/code_lens_options.rb +0 -32
  38. data/lib/language_server/protocol/interfaces/code_lens_params.rb +0 -29
  39. data/lib/language_server/protocol/interfaces/code_lens_registration_options.rb +0 -29
  40. data/lib/language_server/protocol/interfaces/command.rb +0 -48
  41. data/lib/language_server/protocol/interfaces/completion_item.rb +0 -145
  42. data/lib/language_server/protocol/interfaces/completion_list.rb +0 -43
  43. data/lib/language_server/protocol/interfaces/completion_options.rb +0 -42
  44. data/lib/language_server/protocol/interfaces/completion_registration_options.rb +0 -39
  45. data/lib/language_server/protocol/interfaces/diagnostic.rb +0 -67
  46. data/lib/language_server/protocol/interfaces/did_change_configuration_params.rb +0 -29
  47. data/lib/language_server/protocol/interfaces/did_change_text_document_params.rb +0 -40
  48. data/lib/language_server/protocol/interfaces/did_change_watched_files_params.rb +0 -29
  49. data/lib/language_server/protocol/interfaces/did_close_text_document_params.rb +0 -29
  50. data/lib/language_server/protocol/interfaces/did_open_text_document_params.rb +0 -29
  51. data/lib/language_server/protocol/interfaces/did_save_text_document_params.rb +0 -39
  52. data/lib/language_server/protocol/interfaces/document_filter.rb +0 -47
  53. data/lib/language_server/protocol/interfaces/document_formatting_params.rb +0 -38
  54. data/lib/language_server/protocol/interfaces/document_highlight.rb +0 -43
  55. data/lib/language_server/protocol/interfaces/document_link.rb +0 -42
  56. data/lib/language_server/protocol/interfaces/document_link_options.rb +0 -32
  57. data/lib/language_server/protocol/interfaces/document_link_params.rb +0 -29
  58. data/lib/language_server/protocol/interfaces/document_link_registration_options.rb +0 -29
  59. data/lib/language_server/protocol/interfaces/document_on_type_formatting_options.rb +0 -41
  60. data/lib/language_server/protocol/interfaces/document_on_type_formatting_params.rb +0 -56
  61. data/lib/language_server/protocol/interfaces/document_on_type_formatting_registration_options.rb +0 -38
  62. data/lib/language_server/protocol/interfaces/document_range_formatting_params.rb +0 -47
  63. data/lib/language_server/protocol/interfaces/document_symbol_params.rb +0 -29
  64. data/lib/language_server/protocol/interfaces/execute_command_options.rb +0 -32
  65. data/lib/language_server/protocol/interfaces/execute_command_params.rb +0 -38
  66. data/lib/language_server/protocol/interfaces/execute_command_registration_options.rb +0 -32
  67. data/lib/language_server/protocol/interfaces/file_event.rb +0 -41
  68. data/lib/language_server/protocol/interfaces/formatting_options.rb +0 -41
  69. data/lib/language_server/protocol/interfaces/hover.rb +0 -42
  70. data/lib/language_server/protocol/interfaces/initialize_error.rb +0 -35
  71. data/lib/language_server/protocol/interfaces/initialize_params.rb +0 -79
  72. data/lib/language_server/protocol/interfaces/initialize_result.rb +0 -29
  73. data/lib/language_server/protocol/interfaces/location.rb +0 -32
  74. data/lib/language_server/protocol/interfaces/log_message_params.rb +0 -38
  75. data/lib/language_server/protocol/interfaces/message.rb +0 -26
  76. data/lib/language_server/protocol/interfaces/message_action_item.rb +0 -29
  77. data/lib/language_server/protocol/interfaces/notification_message.rb +0 -38
  78. data/lib/language_server/protocol/interfaces/parameter_information.rb +0 -44
  79. data/lib/language_server/protocol/interfaces/position.rb +0 -38
  80. data/lib/language_server/protocol/interfaces/publish_diagnostics_params.rb +0 -38
  81. data/lib/language_server/protocol/interfaces/range.rb +0 -38
  82. data/lib/language_server/protocol/interfaces/reference_context.rb +0 -29
  83. data/lib/language_server/protocol/interfaces/reference_params.rb +0 -26
  84. data/lib/language_server/protocol/interfaces/registration.rb +0 -51
  85. data/lib/language_server/protocol/interfaces/registration_params.rb +0 -26
  86. data/lib/language_server/protocol/interfaces/rename_params.rb +0 -49
  87. data/lib/language_server/protocol/interfaces/request_message.rb +0 -47
  88. data/lib/language_server/protocol/interfaces/response_error.rb +0 -48
  89. data/lib/language_server/protocol/interfaces/response_message.rb +0 -48
  90. data/lib/language_server/protocol/interfaces/save_options.rb +0 -32
  91. data/lib/language_server/protocol/interfaces/server_capabilities.rb +0 -183
  92. data/lib/language_server/protocol/interfaces/show_message_params.rb +0 -38
  93. data/lib/language_server/protocol/interfaces/show_message_request_params.rb +0 -47
  94. data/lib/language_server/protocol/interfaces/signature_help.rb +0 -64
  95. data/lib/language_server/protocol/interfaces/signature_help_options.rb +0 -33
  96. data/lib/language_server/protocol/interfaces/signature_help_registration_options.rb +0 -30
  97. data/lib/language_server/protocol/interfaces/signature_information.rb +0 -54
  98. data/lib/language_server/protocol/interfaces/symbol_information.rb +0 -60
  99. data/lib/language_server/protocol/interfaces/text_document_change_registration_options.rb +0 -33
  100. data/lib/language_server/protocol/interfaces/text_document_client_capabilities.rb +0 -155
  101. data/lib/language_server/protocol/interfaces/text_document_content_change_event.rb +0 -51
  102. data/lib/language_server/protocol/interfaces/text_document_edit.rb +0 -38
  103. data/lib/language_server/protocol/interfaces/text_document_identifier.rb +0 -29
  104. data/lib/language_server/protocol/interfaces/text_document_item.rb +0 -57
  105. data/lib/language_server/protocol/interfaces/text_document_position_params.rb +0 -38
  106. data/lib/language_server/protocol/interfaces/text_document_registration_options.rb +0 -30
  107. data/lib/language_server/protocol/interfaces/text_document_save_registration_options.rb +0 -29
  108. data/lib/language_server/protocol/interfaces/text_document_sync_options.rb +0 -66
  109. data/lib/language_server/protocol/interfaces/text_edit.rb +0 -40
  110. data/lib/language_server/protocol/interfaces/unregistration.rb +0 -42
  111. data/lib/language_server/protocol/interfaces/unregistration_params.rb +0 -26
  112. data/lib/language_server/protocol/interfaces/versioned_text_document_identifier.rb +0 -29
  113. data/lib/language_server/protocol/interfaces/will_save_text_document_params.rb +0 -41
  114. data/lib/language_server/protocol/interfaces/workspace_client_capabilites.rb +0 -78
  115. data/lib/language_server/protocol/interfaces/workspace_edit.rb +0 -40
  116. data/lib/language_server/protocol/interfaces/workspace_symbol_params.rb +0 -32
  117. data/lib/language_server/protocol/interfaces.rb +0 -87
  118. data/lib/language_server/protocol/stdio/reader.rb +0 -37
  119. data/lib/language_server/protocol/stdio/writer.rb +0 -38
  120. data/lib/language_server/protocol/stdio.rb +0 -2
  121. data/scripts/generateFiles.ts +0 -224
  122. data/yarn.lock +0 -295
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7afd0094b57b216afc44723653a9bd07aa1f7910
4
- data.tar.gz: 1c440fef75c1492a7c4048e31f70123cdcd5c049
3
+ metadata.gz: bd9f5e6f9f5a2519287df5f2fde05e24d4db7b4f
4
+ data.tar.gz: 84aa9599f3d9d417ddc6d7e8b326e08136a472bd
5
5
  SHA512:
6
- metadata.gz: e9826d5f5402567b90eac9a722d4e4baa0cea4b9d388df2b263641a9a28190759f86cb739b56f355365302b1640c6c1f90890ae8abe91b1c08b99af8443c5864
7
- data.tar.gz: f1eb2ab1791cdd3d1440500603e00498e886f68ba1e71f59e615e2cac6a1d59cc0fce0dbdfd0586d70369c32dc1b403b29d9bbc61fe60756cd82db3a6f0f1b01
6
+ metadata.gz: 8b70d5f63f934908bb155bba4a9aa76424ceda6afbc872fa13e84c2e5c283e518ee5f68c50ec818eb456e14f0fee0b160868c05e4f290f2016cb798b648026dc
7
+ data.tar.gz: ef92ada00816057dce269cc9bb3fd6ed070f38403c80123e991ef67e50abaa3b736beeae83dba2d72d837817181f1ef5f6fab93050a432c243928f6d36b273c1
data/bin/console CHANGED
@@ -6,6 +6,12 @@ require "language_server"
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
+ def project
10
+ @project ||= LanguageServer::Project.new(
11
+ LanguageServer::FileStore.new(load_paths: $LOAD_PATH, remote_root: ENV['LANGUAGE_SERVER_RUBY_REMOTE_ROOT'], local_root: Dir.getwd)
12
+ )
13
+ end
14
+
9
15
  # (If you use this, don't forget to add pry to your Gemfile!)
10
16
  require "pry-byebug"
11
17
  Pry.start
data/circle.yml CHANGED
@@ -25,7 +25,6 @@ jobs:
25
25
  name: test
26
26
  command: |
27
27
  set -x
28
- docker-compose run node bin/generate_files
29
28
  docker-compose run app bin/m
30
29
  docker-compose run ruby-2-3 bin/m
31
30
  docker-compose run ruby-2-2 bin/m
data/docker-compose.yml CHANGED
@@ -4,6 +4,8 @@ services:
4
4
  build: &app-build
5
5
  context: .
6
6
  dockerfile: Dockerfile.development
7
+ environment:
8
+ LANGUAGE_SERVER_RUBY_REMOTE_ROOT: $PWD
7
9
  volumes:
8
10
  - mtsmfm-language-server-sync:/app:nocopy
9
11
  - home:/home/ruby
@@ -22,13 +24,6 @@ services:
22
24
  <<: *app-build
23
25
  args:
24
26
  RUBY_VERSION: 2.2
25
- node:
26
- build:
27
- context: .
28
- dockerfile: Dockerfile-node.development
29
- volumes:
30
- - mtsmfm-language-server-sync:/app:nocopy
31
- - home:/home/node
32
27
  volumes:
33
28
  mtsmfm-language-server-sync:
34
29
  external: true
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.require_paths = ["lib"]
27
27
 
28
28
  spec.add_dependency "rcodetools"
29
+ spec.add_dependency "language_server-protocol", "0.3.0"
29
30
 
30
31
  spec.add_development_dependency "bundler", "~> 1.14"
31
32
  spec.add_development_dependency "rake", "~> 10.0"
@@ -12,27 +12,27 @@ module LanguageServer
12
12
 
13
13
  def call
14
14
  (project.constants(uri: uri, line: line, character: character).map {|c|
15
- Protocol::Interfaces::CompletionItem.new(
15
+ Protocol::Interface::CompletionItem.new(
16
16
  label: c.name,
17
17
  detail: c.full_name,
18
18
  documentation: "#{c.remote_path}##{c.lineno}",
19
- kind: Protocol::Constants::CompletionItemKind::ENUM
19
+ kind: Protocol::Constant::CompletionItemKind::ENUM
20
20
  )
21
21
  } +
22
22
  project.classes(uri: uri, line: line, character: character).map {|c|
23
- Protocol::Interfaces::CompletionItem.new(
23
+ Protocol::Interface::CompletionItem.new(
24
24
  label: c.name,
25
25
  detail: c.full_name,
26
26
  documentation: "#{c.remote_path}##{c.lineno}",
27
- kind: Protocol::Constants::CompletionItemKind::CLASS
27
+ kind: Protocol::Constant::CompletionItemKind::CLASS
28
28
  )
29
29
  } +
30
30
  project.modules(uri: uri, line: line, character: character).map {|m|
31
- Protocol::Interfaces::CompletionItem.new(
31
+ Protocol::Interface::CompletionItem.new(
32
32
  label: m.name,
33
33
  detail: m.full_name,
34
34
  documentation: "#{m.remote_path}##{m.lineno}",
35
- kind: Protocol::Constants::CompletionItemKind::MODULE
35
+ kind: Protocol::Constant::CompletionItemKind::MODULE
36
36
  )
37
37
  }).uniq(&:label)
38
38
  end
@@ -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"
4
2
  require "rcodetools/completion"
5
3
 
6
4
  module LanguageServer
@@ -27,10 +25,10 @@ module LanguageServer
27
25
  _, candidates = Filter.run(source, lineno: @line + 1, column: @character)
28
26
  candidates.map do |candidate|
29
27
  method_name, description = candidate.split(/\0/, 2)
30
- Protocol::Interfaces::CompletionItem.new(
28
+ Protocol::Interface::CompletionItem.new(
31
29
  label: method_name,
32
30
  detail: description,
33
- kind: Protocol::Constants::CompletionItemKind::METHOD
31
+ kind: Protocol::Constant::CompletionItemKind::METHOD
34
32
  )
35
33
  end
36
34
  end
@@ -0,0 +1,34 @@
1
+ module LanguageServer
2
+ module DefinitionProvider
3
+ class AdHoc
4
+ def initialize(uri:, line:, character:, project:)
5
+ @uri = uri
6
+ @line = line
7
+ @character = character
8
+ @project = project
9
+ end
10
+
11
+ def call
12
+ project.find_definitions(uri: uri, line: line, character: character).map do |n|
13
+ Protocol::Interface::Location.new(
14
+ uri: "file://#{n.remote_path}",
15
+ range: Protocol::Interface::Range.new(
16
+ start: Protocol::Interface::Position.new(
17
+ line: n.lines.begin,
18
+ character: 0
19
+ ),
20
+ end: Protocol::Interface::Position.new(
21
+ line: n.lines.end,
22
+ character: 0
23
+ )
24
+ )
25
+ )
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :uri, :line, :character, :project
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,37 @@
1
+ require 'logger'
2
+
3
+ module LanguageServer
4
+ class << self
5
+ def logger
6
+ @logger ||= ::Logger.new(STDERR, formatter: Formatter.new)
7
+ end
8
+ end
9
+
10
+ class Formatter
11
+ RESET = "\e[0m"
12
+ RED = "\e[31m"
13
+ YELLOW = "\e[33m"
14
+
15
+ def call(severity, *rest)
16
+ msg = default_message(severity, *rest)
17
+ case severity
18
+ when 'ERROR'
19
+ RED + msg + RESET
20
+ when 'WARN'
21
+ YELLOW + msg + RESET
22
+ else
23
+ msg
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def default_message(*args)
30
+ default_formatter.call(*args)
31
+ end
32
+
33
+ def default_formatter
34
+ @default_formatter ||= ::Logger::Formatter.new
35
+ end
36
+ end
37
+ end
@@ -21,7 +21,7 @@ end
21
21
  end
22
22
  end
23
23
 
24
- attributes :lineno, :path
24
+ attributes :lineno, :character, :path
25
25
 
26
26
  def remote_path; path.remote_path; end
27
27
  def local_path; path.local_path; end
@@ -92,5 +92,69 @@ end
92
92
  "<Class #{full_name}#L#{lines.begin}-#{lines.end}>"
93
93
  end
94
94
  end
95
+
96
+ class VarRef < Node
97
+ attributes :node
98
+
99
+ def lines
100
+ node.lineno..node.lineno
101
+ end
102
+
103
+ def characters
104
+ node.character..(character - 1)
105
+ end
106
+
107
+ def unshift_namespace(class_or_module)
108
+ node.unshift_namespace(class_or_module) if node.respond_to?(:unshift_namespace)
109
+ end
110
+
111
+ def names
112
+ node.names
113
+ end
114
+
115
+ def name
116
+ node.name
117
+ end
118
+
119
+ def full_name
120
+ names.join('::')
121
+ end
122
+
123
+ def inspect
124
+ "<VarRef #{full_name}#L#{lineno}(#{characters})>"
125
+ end
126
+ end
127
+
128
+ class ConstPathRef < Node
129
+ attributes :nodes
130
+
131
+ def lines
132
+ (nodes.first.lineno)..(nodes.last.lineno)
133
+ end
134
+
135
+ def characters
136
+ (nodes.first.characters.begin)..(nodes.last.character)
137
+ end
138
+
139
+ def unshift_namespace(class_or_module)
140
+ nodes.first.unshift_namespace(class_or_module)
141
+ end
142
+
143
+ def name
144
+ nodes.last.name
145
+ end
146
+
147
+ def names
148
+ nodes.flat_map(&:names)
149
+ end
150
+
151
+ def full_name
152
+ names.join('::')
153
+ end
154
+
155
+ def inspect
156
+ "<ConstPathRef #{full_name}#L#{lineno}(#{characters})>"
157
+ end
158
+ end
95
159
  end
96
160
  end
@@ -5,12 +5,13 @@ module LanguageServer
5
5
  class Project
6
6
  class Parser < Ripper
7
7
  class Result
8
- attr_reader :constants, :classes, :modules
8
+ attr_reader :constants, :classes, :modules, :refs
9
9
 
10
10
  def initialize
11
11
  @constants = []
12
12
  @classes = []
13
13
  @modules = []
14
+ @refs = []
14
15
  end
15
16
  end
16
17
 
@@ -27,11 +28,12 @@ module LanguageServer
27
28
 
28
29
  @path = path
29
30
  @result = Result.new
30
- @current_constants = []
31
31
  end
32
32
 
33
33
  private
34
34
 
35
+ alias character column
36
+
35
37
  attr_reader :path
36
38
 
37
39
  def lineno
@@ -39,14 +41,36 @@ module LanguageServer
39
41
  super - 1
40
42
  end
41
43
 
42
- def on_const(name)
43
- Constant.new(namespaces: [], name: name, value: nil, lineno: lineno, path: path).tap do |c|
44
- @current_constants.push(c)
44
+ def on_var_ref(node)
45
+ if node.instance_of?(Constant)
46
+ build_node(VarRef, node: node).tap do |n|
47
+ result.refs << n
48
+ end
49
+ else
50
+ node
51
+ end
52
+ end
53
+
54
+ def on_const_path_ref(*nodes)
55
+ if nodes.all? {|n| [Constant, ConstPathRef, VarRef].include?(n.class) }
56
+ build_node(ConstPathRef, nodes: nodes).tap do |n|
57
+ result.refs << n
58
+ end
59
+ else
60
+ nodes
45
61
  end
46
62
  end
47
63
 
64
+ def on_const(name)
65
+ build_node(Constant, namespaces: [], name: name, value: nil)
66
+ end
67
+
68
+ def on_def(*args)
69
+ args.flatten.compact
70
+ end
71
+
48
72
  def on_int(value)
49
- LiteralValue.new(value: value.to_i, lineno: lineno, path: path)
73
+ build_node(LiteralValue, value: value.to_i)
50
74
  end
51
75
 
52
76
  def on_stmts_add(*args)
@@ -61,20 +85,26 @@ module LanguageServer
61
85
  end
62
86
 
63
87
  def on_module(constant, children)
64
- cn = children.select {|child| child.instance_of?(Constant) || child.instance_of?(Module) || child.instance_of?(Class)}
65
- Module.new(constant: constant, lineno: lineno, path: path, children: cn).tap do |m|
88
+ cn = children.select {|child| child.respond_to?(:unshift_namespace) }
89
+
90
+ build_node(Module, constant: constant, children: cn).tap do |m|
66
91
  result.modules << m
67
92
  cn.each {|child| child.unshift_namespace(m) }
68
93
  end
69
94
  end
70
95
 
71
96
  def on_class(constant, superclass, children)
72
- cn = children.select {|child| child.instance_of?(Constant) || child.instance_of?(Module) || child.instance_of?(Class)}
73
- Class.new(constant: constant, superclass: superclass, lineno: lineno, path: path, children: cn).tap do |c|
97
+ cn = children.select {|child| child.respond_to?(:unshift_namespace) }
98
+
99
+ build_node(Class, constant: constant, superclass: superclass, children: cn).tap do |c|
74
100
  result.classes << c
75
101
  cn.each {|child| child.unshift_namespace(c) }
76
102
  end
77
103
  end
104
+
105
+ def build_node(klass, **args)
106
+ klass.new({lineno: lineno, character: character, path: path}.merge(args))
107
+ end
78
108
  end
79
109
  end
80
110
  end
@@ -9,9 +9,19 @@ module LanguageServer
9
9
  fetch_result
10
10
  end
11
11
 
12
+ def find_definitions(uri:, line:, character:)
13
+ result = result_store[file_store.path_from_remote_uri(uri)]
14
+
15
+ ref = result.refs.select {|node| node.lines.include?(line) && node.characters.include?(character) }.min_by {|node| node.characters.size }
16
+
17
+ return [] unless ref
18
+
19
+ lazy_modules.select {|n| n.full_name == ref.full_name }.force + lazy_classes.select {|n| n.full_name == ref.full_name }.force
20
+ end
21
+
12
22
  def recalculate_result(uri)
13
23
  path = file_store.path_from_remote_uri(uri)
14
- result_store[path] = calculate(file_store.read(path), path)
24
+ calculate(file_store.read(path), path)
15
25
  end
16
26
 
17
27
  def constants(uri: nil, line: nil, character: nil)
@@ -50,7 +60,7 @@ module LanguageServer
50
60
 
51
61
  def fetch_result
52
62
  file_store.each {|content, path|
53
- result_store[path] = calculate(content, path)
63
+ calculate(content, path)
54
64
  }
55
65
  end
56
66
 
@@ -61,7 +71,14 @@ module LanguageServer
61
71
  end
62
72
 
63
73
  def calculate(content, path)
64
- Parser.parse(content, path)
74
+ begin
75
+ result = Parser.parse(content, path)
76
+ rescue => e
77
+ LanguageServer.logger.warn("Parse failed (local: #{path.local_path}, remote: #{path.remote_path})")
78
+ LanguageServer.logger.warn(e)
79
+ end
80
+
81
+ result_store[path] = result if result
65
82
  end
66
83
  end
67
84
  end
@@ -1,3 +1,3 @@
1
1
  module LanguageServer
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -1,31 +1,40 @@
1
1
  require "language_server/version"
2
- require "language_server/protocol/interfaces"
3
- require "language_server/protocol/constants"
4
- require "language_server/protocol/stdio"
2
+ require "language_server/logger"
3
+ require "language_server/protocol"
5
4
  require "language_server/linter/ruby_wc"
6
5
  require "language_server/completion_provider/rcodetools"
7
6
  require "language_server/completion_provider/ad_hoc"
7
+ require "language_server/definition_provider/ad_hoc"
8
8
  require "language_server/file_store"
9
9
  require "language_server/project"
10
10
 
11
11
  require "json"
12
- require "logger"
13
12
 
14
13
  module LanguageServer
15
14
  class << self
16
- def logger
17
- @logger ||= Logger.new(STDERR)
18
- end
19
-
20
15
  def run
21
- writer = Protocol::Stdio::Writer.new
22
- reader = Protocol::Stdio::Reader.new
16
+ writer = Protocol::Transport::Stdio::Writer.new
17
+ reader = Protocol::Transport::Stdio::Reader.new
23
18
  variables = {}
24
19
 
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
+
25
34
  reader.read do |request|
26
- method = request[:method].to_sym
35
+ logger.debug("Receive: #{JSON.pretty_generate(request)}")
27
36
 
28
- logger.debug("Method: #{method} called")
37
+ method = request[:method].to_sym
29
38
 
30
39
  _, subscriber = subscribers.find {|k, _|
31
40
  k === method
@@ -61,15 +70,16 @@ module LanguageServer
61
70
  variables[:file_store] = FileStore.new(load_paths: $LOAD_PATH, remote_root: request[:params][:rootPath], local_root: Dir.getwd)
62
71
  variables[:project] = Project.new(variables[:file_store])
63
72
 
64
- Protocol::Interfaces::InitializeResult.new(
65
- capabilities: Protocol::Interfaces::ServerCapabilities.new(
66
- text_document_sync: Protocol::Interfaces::TextDocumentSyncOptions.new(
67
- 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
68
77
  ),
69
- completion_provider: Protocol::Interfaces::CompletionOptions.new(
78
+ completion_provider: Protocol::Interface::CompletionOptions.new(
70
79
  resolve_provider: true,
71
80
  trigger_characters: %w(.)
72
- )
81
+ ),
82
+ definition_provider: true
73
83
  )
74
84
  )
75
85
  end
@@ -85,15 +95,15 @@ module LanguageServer
85
95
  project.recalculate_result(uri)
86
96
 
87
97
  diagnostics = Linter::RubyWC.new(text).call.map do |error|
88
- Protocol::Interfaces::Diagnostic.new(
98
+ Protocol::Interface::Diagnostic.new(
89
99
  message: error.message,
90
- severity: error.warning? ? Protocol::Constants::DiagnosticSeverity::WARNING : Protocol::Constants::DiagnosticSeverity::ERROR,
91
- range: Protocol::Interfaces::Range.new(
92
- 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(
93
103
  line: error.line_num,
94
104
  character: 0
95
105
  ),
96
- end: Protocol::Interfaces::Position.new(
106
+ end: Protocol::Interface::Position.new(
97
107
  line: error.line_num,
98
108
  character: 0
99
109
  )
@@ -103,7 +113,7 @@ module LanguageServer
103
113
 
104
114
  notifier.call(
105
115
  method: :"textDocument/publishDiagnostics",
106
- params: Protocol::Interfaces::PublishDiagnosticsParams.new(
116
+ params: Protocol::Interface::PublishDiagnosticsParams.new(
107
117
  uri: uri,
108
118
  diagnostics: diagnostics
109
119
  )
@@ -119,4 +129,13 @@ module LanguageServer
119
129
  CompletionProvider::Rcodetools.new(uri: uri, line: line, character: character, file_store: file_store)
120
130
  ].flat_map(&:call)
121
131
  end
132
+
133
+ on :"textDocument/definition" do |request:, project:|
134
+ uri = request[:params][:textDocument][:uri]
135
+ line, character = request[:params][:position].fetch_values(:line, :character).map(&:to_i)
136
+
137
+ [
138
+ DefinitionProvider::AdHoc.new(uri: uri, line: line, character: character, project: project),
139
+ ].flat_map(&:call)
140
+ end
122
141
  end