yoda-language-server 0.6.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/yoda/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Yoda
2
- VERSION = "0.6.2"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -26,10 +26,11 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency 'parslet', '~> 1.8'
27
27
  spec.add_dependency 'parser', '~> 2.0'
28
28
  spec.add_dependency 'unparser', '~> 0.2.6'
29
- spec.add_dependency 'language_server-protocol', '~> 3.7.0.0'
29
+ spec.add_dependency 'language_server-protocol', '~> 3.12.0.0'
30
30
  spec.add_dependency 'leveldb', '~> 0.1.9'
31
31
  spec.add_dependency 'lmdb', '~> 0.4.8'
32
32
  spec.add_dependency 'ruby-progressbar'
33
+ spec.add_dependency 'concurrent-ruby', '~> 1.0.0'
33
34
 
34
35
  spec.add_development_dependency "bundler", "~> 1.16"
35
36
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yoda-language-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomoya Chiba
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-29 00:00:00.000000000 Z
11
+ date: 2018-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 3.7.0.0
89
+ version: 3.12.0.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 3.7.0.0
96
+ version: 3.12.0.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: leveldb
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: concurrent-ruby
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 1.0.0
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 1.0.0
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: bundler
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -373,14 +387,22 @@ files:
373
387
  - lib/yoda/parsing/type_parser.rb
374
388
  - lib/yoda/runner.rb
375
389
  - lib/yoda/server.rb
376
- - lib/yoda/server/completion_provider.rb
377
- - lib/yoda/server/definition_provider.rb
390
+ - lib/yoda/server/concurrent_writer.rb
378
391
  - lib/yoda/server/deserializer.rb
379
- - lib/yoda/server/hover_provider.rb
380
- - lib/yoda/server/initialization_provider.rb
392
+ - lib/yoda/server/file_store.rb
393
+ - lib/yoda/server/lifecycle_handler.rb
381
394
  - lib/yoda/server/notifier.rb
395
+ - lib/yoda/server/providers.rb
396
+ - lib/yoda/server/providers/base.rb
397
+ - lib/yoda/server/providers/completion.rb
398
+ - lib/yoda/server/providers/definition.rb
399
+ - lib/yoda/server/providers/hover.rb
400
+ - lib/yoda/server/providers/signature.rb
401
+ - lib/yoda/server/providers/text_document_did_change.rb
402
+ - lib/yoda/server/providers/text_document_did_open.rb
403
+ - lib/yoda/server/providers/text_document_did_save.rb
404
+ - lib/yoda/server/root_handler.rb
382
405
  - lib/yoda/server/session.rb
383
- - lib/yoda/server/signature_provider.rb
384
406
  - lib/yoda/store.rb
385
407
  - lib/yoda/store/actions.rb
386
408
  - lib/yoda/store/actions/build_core_index.rb
@@ -1,78 +0,0 @@
1
- module Yoda
2
- class Server
3
- class CompletionProvider
4
- # @type Session
5
- attr_reader :session
6
-
7
- # @param session [Session]
8
- def initialize(session)
9
- @session = session
10
- end
11
-
12
- # @param uri [String]
13
- # @param position [{Symbol => Integer}]
14
- def complete(uri, position)
15
- source = session.file_store.get(uri)
16
- location = Parsing::Location.of_language_server_protocol_position(line: position[:line], character: position[:character])
17
-
18
- if candidates = comment_complete(source, location)
19
- return candidates
20
- end
21
- complete_from_cut_source(source, location)
22
- end
23
-
24
- private
25
-
26
- # @param source [String]
27
- # @param location [Parsing::Location]
28
- # @return [LanguageServerProtocol::Interface::CompletionList, nil]
29
- def comment_complete(source, location)
30
- ast, comments = Parsing::Parser.new.parse_with_comments(source)
31
- return nil unless Parsing::Query::CurrentCommentQuery.new(comments, location).current_comment
32
- completion_worker = Evaluation::CommentCompletion.new(session.registry, ast, comments, location)
33
- return nil unless completion_worker.available?
34
-
35
- completion_items = completion_worker.candidates
36
-
37
- LSP::Interface::CompletionList.new(
38
- is_incomplete: false,
39
- items: completion_worker.candidates.map { |completion_item| create_completion_item(completion_item) },
40
- )
41
- rescue ::Parser::SyntaxError
42
- nil
43
- end
44
-
45
- # @param source [String]
46
- # @param location [Parsing::Location]
47
- # @return [LanguageServerProtocol::Interface::CompletionList, nil]
48
- def complete_from_cut_source(source, location)
49
- cut_source = Parsing::SourceCutter.new(source, location).error_recovered_source
50
- method_completion_worker = Evaluation::CodeCompletion.new(session.registry, cut_source, location)
51
- completion_items = method_completion_worker.candidates
52
- return nil if completion_items.empty?
53
-
54
- LSP::Interface::CompletionList.new(
55
- is_incomplete: false,
56
- items: completion_items.map { |completion_item| create_completion_item(completion_item) },
57
- )
58
- end
59
-
60
- # @param completion_item [Model::CompletionItem]
61
- # @return [LSP::Interface::CompletionItem]
62
- def create_completion_item(completion_item)
63
- LSP::Interface::CompletionItem.new(
64
- label: completion_item.description.is_a?(Model::Descriptions::FunctionDescription) ? completion_item.description.signature : completion_item.description.sort_text,
65
- kind: completion_item.language_server_kind,
66
- detail: completion_item.description.title,
67
- documentation: completion_item.description.to_markdown,
68
- sort_text: completion_item.description.sort_text,
69
- text_edit: LSP::Interface::TextEdit.new(
70
- range: LSP::Interface::Range.new(completion_item.range.to_language_server_protocol_range),
71
- new_text: completion_item.edit_text,
72
- ),
73
- data: {},
74
- )
75
- end
76
- end
77
- end
78
- end
@@ -1,36 +0,0 @@
1
- module Yoda
2
- class Server
3
- class DefinitionProvider
4
- # @type Session
5
- attr_reader :session
6
-
7
- # @param session [Session]
8
- def initialize(session)
9
- @session = session
10
- end
11
-
12
- # @param uri [String]
13
- # @param position [{Symbol => Integer}]
14
- # @param include_declaration [Boolean]
15
- def provide(uri, position, include_declaration = false)
16
- source = session.file_store.get(uri)
17
- location = Parsing::Location.of_language_server_protocol_position(line: position[:line], character: position[:character])
18
-
19
- node_worker = Evaluation::CurrentNodeExplain.new(session.registry, source, location)
20
- references = node_worker.defined_files
21
- references.map { |(path, line, column)| create_location(path, line, column) }
22
- end
23
-
24
- # @param path [String]
25
- # @param line [Integer]
26
- # @param column [Integer]
27
- def create_location(path, line, column)
28
- location = Parsing::Location.new(row: line - 1, column: column)
29
- LSP::Interface::Location.new(
30
- uri: session.uri_of_path(path),
31
- range: LSP::Interface::Range.new(Parsing::Range.new(location, location).to_language_server_protocol_range),
32
- )
33
- end
34
- end
35
- end
36
- end
@@ -1,39 +0,0 @@
1
- module Yoda
2
- class Server
3
- class HoverProvider
4
- # @return [Session]
5
- attr_reader :session
6
-
7
- # @param session [Session]
8
- def initialize(session)
9
- @session = session
10
- end
11
-
12
- # @param uri [String]
13
- # @param position [{Symbol => Integer}]
14
- def request_hover(uri, position)
15
- source = session.file_store.get(uri)
16
- location = Parsing::Location.of_language_server_protocol_position(line: position[:line], character: position[:character])
17
-
18
- node_worker = Evaluation::CurrentNodeExplain.new(session.registry, source, location)
19
-
20
- current_node_signature = node_worker.current_node_signature
21
- create_hover(current_node_signature) if current_node_signature
22
- end
23
-
24
- # @param signature [Evaluation::NodeSignature]
25
- def create_hover(signature)
26
- LSP::Interface::Hover.new(
27
- contents: signature.descriptions.map { |value| create_hover_text(value) },
28
- range: LSP::Interface::Range.new(signature.node_range.to_language_server_protocol_range),
29
- )
30
- end
31
-
32
- # @param description [Evaluation::Descriptions::Base]
33
- # @return [String]
34
- def create_hover_text(description)
35
- description.to_markdown
36
- end
37
- end
38
- end
39
- end
@@ -1,96 +0,0 @@
1
- module Yoda
2
- class Server
3
- class InitializationProvider
4
- # @return [Session]
5
- attr_reader :session
6
-
7
- # @return [Notifier]
8
- attr_reader :notifier
9
-
10
- # @param session [Session]
11
- # @param nofitier [Notifier]
12
- def initialize(session:, notifier:)
13
- @session = session
14
- @notifier = notifier
15
- end
16
-
17
- # @return [LanguageServer::Protocol::Interface::ShowMessageParams, nil]
18
- def provide
19
- errors = Instrument.instance.hear(initialization_progress: method(:notify_initialization_progress)) do
20
- session.setup
21
- end
22
- build_complete_message(errors)
23
- end
24
-
25
- private
26
-
27
- # @param errors [Array<BaseError>]
28
- # @return [Array<Object>]
29
- def build_complete_message(errors)
30
- return [] if errors.empty?
31
- gem_import_errors = errors.select { |error| error.is_a?(GemImportError) }
32
- core_import_errors = errors.select { |error| error.is_a?(CoreImportError) }
33
-
34
- notifications = [
35
- {
36
- method: 'window/showMessage',
37
- params: LanguageServer::Protocol::Interface::ShowMessageParams.new(
38
- type: LanguageServer::Protocol::Constant::MessageType::WARNING,
39
- message: "Failed to load some libraries (Please check console for details)",
40
- )
41
- }
42
- ]
43
-
44
- if gem_message = gem_import_warnings(gem_import_errors)
45
- notifications.push(
46
- method: 'window/logMessage',
47
- params: LanguageServer::Protocol::Interface::LogMessageParams.new(
48
- type: LanguageServer::Protocol::Constant::MessageType::WARNING,
49
- message: gem_message,
50
- ),
51
- )
52
- end
53
-
54
- if core_message = core_import_warnings(core_import_errors)
55
- notifications.push(
56
- method: 'window/logMessage',
57
- params: LanguageServer::Protocol::Interface::LogMessageParams.new(
58
- type: LanguageServer::Protocol::Constant::MessageType::WARNING,
59
- message: core_message,
60
- ),
61
- )
62
- end
63
-
64
- notifications
65
- end
66
-
67
- # @param gem_import_errors [Array<GemImportError>]
68
- # @return [String, nil]
69
- def gem_import_warnings(gem_import_errors)
70
- return if gem_import_errors.empty?
71
- warnings = gem_import_errors.map { |error| "- #{error.name} (#{error.version})" }
72
-
73
- <<~EOS
74
- Failed to import some gems.
75
- Please check these gems are installed for Ruby version #{RUBY_VERSION}.
76
- #{warnings.join("\n")}
77
- EOS
78
- end
79
-
80
- # @param gem_import_errors [Array<GemImportError>]
81
- # @return [String, nil]
82
- def core_import_warnings(core_import_errors)
83
- return if core_import_errors.empty?
84
-
85
- <<~EOS
86
- Failed to import some core libraries (Ruby version: #{RUBY_VERSION}).
87
- Please execute `yoda setup` with Ruby version #{RUBY_VERSION}.
88
- EOS
89
- end
90
-
91
- def notify_initialization_progress(phase: nil, message: nil, **params)
92
- notifier.event(type: :initialization, phase: phase, message: message)
93
- end
94
- end
95
- end
96
- end
@@ -1,46 +0,0 @@
1
- module Yoda
2
- class Server
3
- class SignatureProvider
4
- attr_reader :session
5
-
6
- # @param session [Session]
7
- def initialize(session)
8
- @session = session
9
- end
10
-
11
- # @param uri [String]
12
- # @param position [{Symbol => Integer}]
13
- def provide(uri, position)
14
- source = session.file_store.get(uri)
15
- location = Parsing::Location.of_language_server_protocol_position(line: position[:line], character: position[:character])
16
- cut_source = Parsing::SourceCutter.new(source, location).error_recovered_source
17
-
18
- signature_worker = Evaluation::SignatureDiscovery.new(session.registry, cut_source, location)
19
-
20
- functions = signature_worker.method_candidates
21
- create_signature_help(functions)
22
- end
23
-
24
- # @param code_objects [Array<Model::FunctionSignatures::Base>]
25
- def create_signature_help(functions)
26
- signatures = functions.map { |func| Model::Descriptions::FunctionDescription.new(func) }
27
- LSP::Interface::SignatureHelp.new(
28
- signatures: signatures.map { |signature| create_signature_info(signature) },
29
- )
30
- end
31
-
32
- # @param signature [Evaluation::Descriptions::FunctionDescription]
33
- def create_signature_info(signature)
34
- LSP::Interface::SignatureInformation.new(
35
- label: signature.title.to_s,
36
- documentation: signature.to_markdown,
37
- parameters: signature.parameter_names.map do |parameter|
38
- LSP::Interface::ParameterInformation.new(
39
- label: parameter,
40
- )
41
- end,
42
- )
43
- end
44
- end
45
- end
46
- end