solargraph 0.59.0.dev.1 → 0.59.0.dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/plugins.yml +4 -1
- data/.github/workflows/rspec.yml +3 -14
- data/.gitignore +1 -0
- data/.rubocop.yml +32 -5
- data/.rubocop_todo.yml +37 -931
- data/CHANGELOG.md +7 -1
- data/Gemfile +3 -1
- data/Rakefile +25 -23
- data/bin/solargraph +2 -1
- data/lib/solargraph/api_map/index.rb +5 -11
- data/lib/solargraph/api_map/source_to_yard.rb +9 -8
- data/lib/solargraph/api_map/store.rb +22 -20
- data/lib/solargraph/api_map.rb +50 -37
- data/lib/solargraph/bench.rb +44 -45
- data/lib/solargraph/complex_type/type_methods.rb +12 -15
- data/lib/solargraph/complex_type/unique_type.rb +54 -43
- data/lib/solargraph/complex_type.rb +69 -61
- data/lib/solargraph/convention/data_definition/data_assignment_node.rb +61 -61
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +4 -4
- data/lib/solargraph/convention/data_definition.rb +1 -1
- data/lib/solargraph/convention/gemfile.rb +15 -15
- data/lib/solargraph/convention/gemspec.rb +23 -23
- data/lib/solargraph/convention/rakefile.rb +17 -17
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +1 -1
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +3 -3
- data/lib/solargraph/convention/struct_definition.rb +3 -3
- data/lib/solargraph/convention.rb +78 -78
- data/lib/solargraph/converters/dd.rb +19 -17
- data/lib/solargraph/converters/dl.rb +17 -15
- data/lib/solargraph/converters/dt.rb +17 -15
- data/lib/solargraph/converters/misc.rb +3 -1
- data/lib/solargraph/diagnostics/rubocop.rb +10 -10
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +3 -3
- data/lib/solargraph/diagnostics/type_check.rb +10 -10
- data/lib/solargraph/diagnostics/update_errors.rb +37 -41
- data/lib/solargraph/doc_map.rb +9 -10
- data/lib/solargraph/equality.rb +3 -3
- data/lib/solargraph/gem_pins.rb +7 -5
- data/lib/solargraph/language_server/error_codes.rb +20 -20
- data/lib/solargraph/language_server/host/diagnoser.rb +89 -89
- data/lib/solargraph/language_server/host/dispatch.rb +2 -3
- data/lib/solargraph/language_server/host/message_worker.rb +2 -2
- data/lib/solargraph/language_server/host/sources.rb +1 -1
- data/lib/solargraph/language_server/host.rb +24 -21
- data/lib/solargraph/language_server/message/base.rb +97 -97
- data/lib/solargraph/language_server/message/client/register_capability.rb +13 -15
- data/lib/solargraph/language_server/message/completion_item/resolve.rb +58 -60
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +10 -11
- data/lib/solargraph/language_server/message/extended/document_gems.rb +32 -32
- data/lib/solargraph/language_server/message/extended/download_core.rb +20 -19
- data/lib/solargraph/language_server/message/extended/search.rb +20 -20
- data/lib/solargraph/language_server/message/initialize.rb +197 -191
- data/lib/solargraph/language_server/message/text_document/completion.rb +8 -8
- data/lib/solargraph/language_server/message/text_document/definition.rb +41 -34
- data/lib/solargraph/language_server/message/text_document/document_highlight.rb +23 -16
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +29 -21
- data/lib/solargraph/language_server/message/text_document/formatting.rb +6 -6
- data/lib/solargraph/language_server/message/text_document/hover.rb +3 -5
- data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +18 -11
- data/lib/solargraph/language_server/message/text_document/references.rb +23 -16
- data/lib/solargraph/language_server/message/text_document/rename.rb +26 -19
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +2 -2
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +25 -19
- data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +41 -35
- data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +48 -40
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +32 -26
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +27 -19
- data/lib/solargraph/language_server/message.rb +94 -94
- data/lib/solargraph/language_server/request.rb +29 -27
- data/lib/solargraph/language_server/transport/data_reader.rb +72 -74
- data/lib/solargraph/language_server/uri_helpers.rb +49 -49
- data/lib/solargraph/library.rb +28 -33
- data/lib/solargraph/location.rb +10 -12
- data/lib/solargraph/logging.rb +4 -4
- data/lib/solargraph/page.rb +92 -92
- data/lib/solargraph/parser/comment_ripper.rb +12 -4
- data/lib/solargraph/parser/flow_sensitive_typing.rb +32 -42
- data/lib/solargraph/parser/node_processor/base.rb +4 -4
- data/lib/solargraph/parser/node_processor.rb +1 -1
- data/lib/solargraph/parser/parser_gem/class_methods.rb +4 -4
- data/lib/solargraph/parser/parser_gem/flawed_builder.rb +19 -19
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +20 -20
- data/lib/solargraph/parser/parser_gem/node_methods.rb +66 -65
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +12 -12
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +3 -3
- data/lib/solargraph/parser/parser_gem/node_processors/defs_node.rb +38 -37
- data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +3 -3
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +3 -5
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +118 -112
- data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +29 -29
- data/lib/solargraph/parser/parser_gem/node_processors/when_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem.rb +14 -12
- data/lib/solargraph/parser/snippet.rb +2 -0
- data/lib/solargraph/parser.rb +25 -23
- data/lib/solargraph/pin/base.rb +78 -64
- data/lib/solargraph/pin/base_variable.rb +28 -71
- data/lib/solargraph/pin/block.rb +3 -2
- data/lib/solargraph/pin/breakable.rb +2 -0
- data/lib/solargraph/pin/callable.rb +23 -26
- data/lib/solargraph/pin/closure.rb +5 -4
- data/lib/solargraph/pin/common.rb +5 -2
- data/lib/solargraph/pin/compound_statement.rb +3 -3
- data/lib/solargraph/pin/constant.rb +43 -45
- data/lib/solargraph/pin/conversions.rb +9 -4
- data/lib/solargraph/pin/delegated_method.rb +4 -4
- data/lib/solargraph/pin/documenting.rb +3 -2
- data/lib/solargraph/pin/local_variable.rb +4 -4
- data/lib/solargraph/pin/method.rb +71 -70
- data/lib/solargraph/pin/namespace.rb +13 -12
- data/lib/solargraph/pin/parameter.rb +28 -27
- data/lib/solargraph/pin/proxy_type.rb +2 -0
- data/lib/solargraph/pin/reference.rb +17 -0
- data/lib/solargraph/pin/search.rb +2 -2
- data/lib/solargraph/pin/signature.rb +9 -14
- data/lib/solargraph/pin/symbol.rb +1 -0
- data/lib/solargraph/pin/until.rb +1 -3
- data/lib/solargraph/pin/while.rb +1 -3
- data/lib/solargraph/pin_cache.rb +16 -19
- data/lib/solargraph/position.rb +35 -17
- data/lib/solargraph/range.rb +10 -9
- data/lib/solargraph/rbs_map/conversions.rb +312 -206
- data/lib/solargraph/rbs_map/core_fills.rb +91 -84
- data/lib/solargraph/rbs_map/stdlib_map.rb +0 -1
- data/lib/solargraph/rbs_map.rb +3 -12
- data/lib/solargraph/server_methods.rb +16 -16
- data/lib/solargraph/shell.rb +63 -53
- data/lib/solargraph/source/chain/array.rb +39 -37
- data/lib/solargraph/source/chain/call.rb +49 -44
- data/lib/solargraph/source/chain/class_variable.rb +13 -13
- data/lib/solargraph/source/chain/constant.rb +3 -1
- data/lib/solargraph/source/chain/global_variable.rb +13 -13
- data/lib/solargraph/source/chain/hash.rb +8 -6
- data/lib/solargraph/source/chain/if.rb +11 -10
- data/lib/solargraph/source/chain/instance_variable.rb +3 -1
- data/lib/solargraph/source/chain/link.rb +99 -109
- data/lib/solargraph/source/chain/literal.rb +4 -6
- data/lib/solargraph/source/chain/or.rb +2 -4
- data/lib/solargraph/source/chain/q_call.rb +13 -11
- data/lib/solargraph/source/chain/variable.rb +15 -13
- data/lib/solargraph/source/chain/z_super.rb +28 -30
- data/lib/solargraph/source/chain.rb +24 -16
- data/lib/solargraph/source/change.rb +3 -3
- data/lib/solargraph/source/cursor.rb +18 -18
- data/lib/solargraph/source/encoding_fixes.rb +6 -7
- data/lib/solargraph/source/source_chainer.rb +46 -32
- data/lib/solargraph/source/updater.rb +1 -1
- data/lib/solargraph/source.rb +27 -29
- data/lib/solargraph/source_map/clip.rb +38 -30
- data/lib/solargraph/source_map/mapper.rb +52 -46
- data/lib/solargraph/source_map.rb +8 -4
- data/lib/solargraph/type_checker/rules.rb +8 -8
- data/lib/solargraph/type_checker.rb +95 -101
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +10 -9
- data/lib/solargraph/workspace/gemspecs.rb +1 -1
- data/lib/solargraph/workspace.rb +21 -44
- data/lib/solargraph/yard_map/helpers.rb +6 -2
- data/lib/solargraph/yard_map/mapper/to_method.rb +8 -6
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +1 -1
- data/lib/solargraph/yard_map/mapper.rb +12 -12
- data/lib/solargraph/yard_tags.rb +20 -20
- data/lib/solargraph.rb +5 -5
- data/solargraph.gemspec +35 -34
- metadata +28 -28
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'solargraph'
|
|
4
|
-
|
|
5
|
-
module Solargraph
|
|
6
|
-
module LanguageServer
|
|
7
|
-
# The Message namespace contains classes that implement language server
|
|
8
|
-
# protocol methods.
|
|
9
|
-
#
|
|
10
|
-
module Message
|
|
11
|
-
autoload :Base, 'solargraph/language_server/message/base'
|
|
12
|
-
autoload :Initialize, 'solargraph/language_server/message/initialize'
|
|
13
|
-
autoload :Initialized, 'solargraph/language_server/message/initialized'
|
|
14
|
-
autoload :TextDocument, 'solargraph/language_server/message/text_document'
|
|
15
|
-
autoload :CompletionItem, 'solargraph/language_server/message/completion_item'
|
|
16
|
-
autoload :CancelRequest, 'solargraph/language_server/message/cancel_request'
|
|
17
|
-
autoload :MethodNotFound, 'solargraph/language_server/message/method_not_found'
|
|
18
|
-
autoload :MethodNotImplemented, 'solargraph/language_server/message/method_not_implemented'
|
|
19
|
-
autoload :Extended, 'solargraph/language_server/message/extended'
|
|
20
|
-
autoload :Shutdown, 'solargraph/language_server/message/shutdown'
|
|
21
|
-
autoload :ExitNotification, 'solargraph/language_server/message/exit_notification'
|
|
22
|
-
autoload :Workspace, 'solargraph/language_server/message/workspace'
|
|
23
|
-
|
|
24
|
-
class << self
|
|
25
|
-
# Register a method name and message for handling by the language
|
|
26
|
-
# server.
|
|
27
|
-
#
|
|
28
|
-
# @example
|
|
29
|
-
# Message.register 'initialize', Solargraph::Message::Initialize
|
|
30
|
-
#
|
|
31
|
-
# @param path [String] The method name
|
|
32
|
-
# @param message_class [Class<Message::Base>] The message class
|
|
33
|
-
# @return [void]
|
|
34
|
-
def register path, message_class
|
|
35
|
-
method_map[path] = message_class
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# @param path [String]
|
|
39
|
-
# @return [Class<Solargraph::LanguageServer::Message::Base>]
|
|
40
|
-
def select path
|
|
41
|
-
if method_map.
|
|
42
|
-
method_map[path]
|
|
43
|
-
elsif path.start_with?('$/')
|
|
44
|
-
MethodNotImplemented
|
|
45
|
-
else
|
|
46
|
-
MethodNotFound
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
private
|
|
51
|
-
|
|
52
|
-
# @return [Hash{String => Class<Message::Base>}]
|
|
53
|
-
def method_map
|
|
54
|
-
@method_map ||= {}
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
register 'initialize', Initialize
|
|
59
|
-
register 'initialized', Initialized
|
|
60
|
-
register 'textDocument/completion', TextDocument::Completion
|
|
61
|
-
register 'completionItem/resolve', CompletionItem::Resolve
|
|
62
|
-
register 'textDocument/signatureHelp', TextDocument::SignatureHelp
|
|
63
|
-
register 'textDocument/didOpen', TextDocument::DidOpen
|
|
64
|
-
register 'textDocument/didChange', TextDocument::DidChange
|
|
65
|
-
register 'textDocument/didSave', TextDocument::DidSave
|
|
66
|
-
register 'textDocument/didClose', TextDocument::DidClose
|
|
67
|
-
register 'textDocument/hover', TextDocument::Hover
|
|
68
|
-
register 'textDocument/definition', TextDocument::Definition
|
|
69
|
-
register 'textDocument/typeDefinition', TextDocument::TypeDefinition
|
|
70
|
-
register 'textDocument/formatting', TextDocument::Formatting
|
|
71
|
-
register 'textDocument/onTypeFormatting', TextDocument::OnTypeFormatting
|
|
72
|
-
register 'textDocument/documentSymbol', TextDocument::DocumentSymbol
|
|
73
|
-
register 'textDocument/references', TextDocument::References
|
|
74
|
-
register 'textDocument/rename', TextDocument::Rename
|
|
75
|
-
register 'textDocument/prepareRename', TextDocument::PrepareRename
|
|
76
|
-
register 'textDocument/foldingRange', TextDocument::FoldingRange
|
|
77
|
-
# register 'textDocument/codeAction', TextDocument::CodeAction
|
|
78
|
-
register 'textDocument/documentHighlight', TextDocument::DocumentHighlight
|
|
79
|
-
register 'workspace/didChangeWatchedFiles', Workspace::DidChangeWatchedFiles
|
|
80
|
-
register 'workspace/didChangeConfiguration', Workspace::DidChangeConfiguration
|
|
81
|
-
register 'workspace/didChangeWorkspaceFolders', Workspace::DidChangeWorkspaceFolders
|
|
82
|
-
register 'workspace/symbol', Workspace::WorkspaceSymbol
|
|
83
|
-
register '$/cancelRequest', CancelRequest
|
|
84
|
-
register '$/solargraph/document', Extended::Document
|
|
85
|
-
register '$/solargraph/search', Extended::Search
|
|
86
|
-
register '$/solargraph/checkGemVersion', Extended::CheckGemVersion
|
|
87
|
-
register '$/solargraph/documentGems', Extended::DocumentGems
|
|
88
|
-
register '$/solargraph/downloadCore', Extended::DownloadCore
|
|
89
|
-
register '$/solargraph/environment', Extended::Environment
|
|
90
|
-
register 'shutdown', Shutdown
|
|
91
|
-
register 'exit', ExitNotification
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'solargraph'
|
|
4
|
+
|
|
5
|
+
module Solargraph
|
|
6
|
+
module LanguageServer
|
|
7
|
+
# The Message namespace contains classes that implement language server
|
|
8
|
+
# protocol methods.
|
|
9
|
+
#
|
|
10
|
+
module Message
|
|
11
|
+
autoload :Base, 'solargraph/language_server/message/base'
|
|
12
|
+
autoload :Initialize, 'solargraph/language_server/message/initialize'
|
|
13
|
+
autoload :Initialized, 'solargraph/language_server/message/initialized'
|
|
14
|
+
autoload :TextDocument, 'solargraph/language_server/message/text_document'
|
|
15
|
+
autoload :CompletionItem, 'solargraph/language_server/message/completion_item'
|
|
16
|
+
autoload :CancelRequest, 'solargraph/language_server/message/cancel_request'
|
|
17
|
+
autoload :MethodNotFound, 'solargraph/language_server/message/method_not_found'
|
|
18
|
+
autoload :MethodNotImplemented, 'solargraph/language_server/message/method_not_implemented'
|
|
19
|
+
autoload :Extended, 'solargraph/language_server/message/extended'
|
|
20
|
+
autoload :Shutdown, 'solargraph/language_server/message/shutdown'
|
|
21
|
+
autoload :ExitNotification, 'solargraph/language_server/message/exit_notification'
|
|
22
|
+
autoload :Workspace, 'solargraph/language_server/message/workspace'
|
|
23
|
+
|
|
24
|
+
class << self
|
|
25
|
+
# Register a method name and message for handling by the language
|
|
26
|
+
# server.
|
|
27
|
+
#
|
|
28
|
+
# @example
|
|
29
|
+
# Message.register 'initialize', Solargraph::Message::Initialize
|
|
30
|
+
#
|
|
31
|
+
# @param path [String] The method name
|
|
32
|
+
# @param message_class [Class<Message::Base>] The message class
|
|
33
|
+
# @return [void]
|
|
34
|
+
def register path, message_class
|
|
35
|
+
method_map[path] = message_class
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# @param path [String]
|
|
39
|
+
# @return [Class<Solargraph::LanguageServer::Message::Base>]
|
|
40
|
+
def select path
|
|
41
|
+
if method_map.key?(path)
|
|
42
|
+
method_map[path]
|
|
43
|
+
elsif path.start_with?('$/')
|
|
44
|
+
MethodNotImplemented
|
|
45
|
+
else
|
|
46
|
+
MethodNotFound
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
# @return [Hash{String => Class<Message::Base>}]
|
|
53
|
+
def method_map
|
|
54
|
+
@method_map ||= {}
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
register 'initialize', Initialize
|
|
59
|
+
register 'initialized', Initialized
|
|
60
|
+
register 'textDocument/completion', TextDocument::Completion
|
|
61
|
+
register 'completionItem/resolve', CompletionItem::Resolve
|
|
62
|
+
register 'textDocument/signatureHelp', TextDocument::SignatureHelp
|
|
63
|
+
register 'textDocument/didOpen', TextDocument::DidOpen
|
|
64
|
+
register 'textDocument/didChange', TextDocument::DidChange
|
|
65
|
+
register 'textDocument/didSave', TextDocument::DidSave
|
|
66
|
+
register 'textDocument/didClose', TextDocument::DidClose
|
|
67
|
+
register 'textDocument/hover', TextDocument::Hover
|
|
68
|
+
register 'textDocument/definition', TextDocument::Definition
|
|
69
|
+
register 'textDocument/typeDefinition', TextDocument::TypeDefinition
|
|
70
|
+
register 'textDocument/formatting', TextDocument::Formatting
|
|
71
|
+
register 'textDocument/onTypeFormatting', TextDocument::OnTypeFormatting
|
|
72
|
+
register 'textDocument/documentSymbol', TextDocument::DocumentSymbol
|
|
73
|
+
register 'textDocument/references', TextDocument::References
|
|
74
|
+
register 'textDocument/rename', TextDocument::Rename
|
|
75
|
+
register 'textDocument/prepareRename', TextDocument::PrepareRename
|
|
76
|
+
register 'textDocument/foldingRange', TextDocument::FoldingRange
|
|
77
|
+
# register 'textDocument/codeAction', TextDocument::CodeAction
|
|
78
|
+
register 'textDocument/documentHighlight', TextDocument::DocumentHighlight
|
|
79
|
+
register 'workspace/didChangeWatchedFiles', Workspace::DidChangeWatchedFiles
|
|
80
|
+
register 'workspace/didChangeConfiguration', Workspace::DidChangeConfiguration
|
|
81
|
+
register 'workspace/didChangeWorkspaceFolders', Workspace::DidChangeWorkspaceFolders
|
|
82
|
+
register 'workspace/symbol', Workspace::WorkspaceSymbol
|
|
83
|
+
register '$/cancelRequest', CancelRequest
|
|
84
|
+
register '$/solargraph/document', Extended::Document
|
|
85
|
+
register '$/solargraph/search', Extended::Search
|
|
86
|
+
register '$/solargraph/checkGemVersion', Extended::CheckGemVersion
|
|
87
|
+
register '$/solargraph/documentGems', Extended::DocumentGems
|
|
88
|
+
register '$/solargraph/downloadCore', Extended::DownloadCore
|
|
89
|
+
register '$/solargraph/environment', Extended::Environment
|
|
90
|
+
register 'shutdown', Shutdown
|
|
91
|
+
register 'exit', ExitNotification
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
module LanguageServer
|
|
5
|
-
class Request
|
|
6
|
-
# @param id [Integer]
|
|
7
|
-
# @param
|
|
8
|
-
def initialize id, &block
|
|
9
|
-
@id = id
|
|
10
|
-
@block = block
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
# @
|
|
14
|
-
#
|
|
15
|
-
# @
|
|
16
|
-
# @
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module LanguageServer
|
|
5
|
+
class Request
|
|
6
|
+
# @param id [Integer]
|
|
7
|
+
# @param block [Proc] The block that processes the client's response
|
|
8
|
+
def initialize id, &block
|
|
9
|
+
@id = id
|
|
10
|
+
@block = block
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# @sg-ignore Solargraph::LanguageServer::Request#process return
|
|
14
|
+
# type could not be inferred
|
|
15
|
+
# @param result [Object]
|
|
16
|
+
# @generic T
|
|
17
|
+
# @yieldreturn [generic<T>]
|
|
18
|
+
# @return [generic<T>, nil]
|
|
19
|
+
def process result
|
|
20
|
+
@block&.call(result)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# @return [void]
|
|
24
|
+
def send_response
|
|
25
|
+
# noop
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -1,74 +1,72 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'json'
|
|
4
|
-
|
|
5
|
-
module Solargraph
|
|
6
|
-
module LanguageServer
|
|
7
|
-
module Transport
|
|
8
|
-
class DataReader
|
|
9
|
-
def initialize
|
|
10
|
-
@in_header = true
|
|
11
|
-
@content_length = 0
|
|
12
|
-
@buffer = String.new
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
# Declare a block to be executed for each message received from the
|
|
16
|
-
# client.
|
|
17
|
-
#
|
|
18
|
-
# @yieldparam [Hash] The message received from the client
|
|
19
|
-
# @return [void]
|
|
20
|
-
def set_message_handler &block
|
|
21
|
-
@message_handler = block
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
# Process raw data received from the client. The data will be parsed
|
|
25
|
-
# into messages based on the JSON-RPC protocol. Each message will be
|
|
26
|
-
# passed to the block declared via set_message_handler. Incomplete data
|
|
27
|
-
# will be buffered and subsequent data will be appended to the buffer.
|
|
28
|
-
#
|
|
29
|
-
# @param data [String]
|
|
30
|
-
# @return [void]
|
|
31
|
-
def receive data
|
|
32
|
-
data.each_char do |char|
|
|
33
|
-
@buffer.concat char
|
|
34
|
-
if @in_header
|
|
35
|
-
prepare_to_parse_message if @buffer.end_with?("\r\n\r\n")
|
|
36
|
-
|
|
37
|
-
parse_message_from_buffer
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
private
|
|
43
|
-
|
|
44
|
-
# @return [void]
|
|
45
|
-
def prepare_to_parse_message
|
|
46
|
-
@in_header = false
|
|
47
|
-
@buffer.each_line do |line|
|
|
48
|
-
parts = line.split(':').map(&:strip)
|
|
49
|
-
if parts[0] == 'Content-Length'
|
|
50
|
-
@content_length = parts[1].to_i
|
|
51
|
-
break
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
@buffer.clear
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
# @return [void]
|
|
58
|
-
def parse_message_from_buffer
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
end
|
|
74
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
module Solargraph
|
|
6
|
+
module LanguageServer
|
|
7
|
+
module Transport
|
|
8
|
+
class DataReader
|
|
9
|
+
def initialize
|
|
10
|
+
@in_header = true
|
|
11
|
+
@content_length = 0
|
|
12
|
+
@buffer = String.new
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Declare a block to be executed for each message received from the
|
|
16
|
+
# client.
|
|
17
|
+
#
|
|
18
|
+
# @yieldparam [Hash] The message received from the client
|
|
19
|
+
# @return [void]
|
|
20
|
+
def set_message_handler &block
|
|
21
|
+
@message_handler = block
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Process raw data received from the client. The data will be parsed
|
|
25
|
+
# into messages based on the JSON-RPC protocol. Each message will be
|
|
26
|
+
# passed to the block declared via set_message_handler. Incomplete data
|
|
27
|
+
# will be buffered and subsequent data will be appended to the buffer.
|
|
28
|
+
#
|
|
29
|
+
# @param data [String]
|
|
30
|
+
# @return [void]
|
|
31
|
+
def receive data
|
|
32
|
+
data.each_char do |char|
|
|
33
|
+
@buffer.concat char
|
|
34
|
+
if @in_header
|
|
35
|
+
prepare_to_parse_message if @buffer.end_with?("\r\n\r\n")
|
|
36
|
+
elsif @buffer.bytesize == @content_length
|
|
37
|
+
parse_message_from_buffer
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
# @return [void]
|
|
45
|
+
def prepare_to_parse_message
|
|
46
|
+
@in_header = false
|
|
47
|
+
@buffer.each_line do |line|
|
|
48
|
+
parts = line.split(':').map(&:strip)
|
|
49
|
+
if parts[0] == 'Content-Length'
|
|
50
|
+
@content_length = parts[1].to_i
|
|
51
|
+
break
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
@buffer.clear
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# @return [void]
|
|
58
|
+
def parse_message_from_buffer
|
|
59
|
+
msg = JSON.parse(@buffer)
|
|
60
|
+
@message_handler&.call msg
|
|
61
|
+
rescue JSON::ParserError => e
|
|
62
|
+
Solargraph::Logging.logger.warn "Failed to parse request: #{e.message}"
|
|
63
|
+
Solargraph::Logging.logger.debug "Buffer: #{@buffer}"
|
|
64
|
+
ensure
|
|
65
|
+
@buffer.clear
|
|
66
|
+
@in_header = true
|
|
67
|
+
@content_length = 0
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'cgi'
|
|
4
|
-
|
|
5
|
-
module Solargraph
|
|
6
|
-
module LanguageServer
|
|
7
|
-
# Methods to handle conversions between file URIs and paths.
|
|
8
|
-
#
|
|
9
|
-
module UriHelpers
|
|
10
|
-
module_function
|
|
11
|
-
|
|
12
|
-
# Convert a file URI to a path.
|
|
13
|
-
#
|
|
14
|
-
# @param uri [String]
|
|
15
|
-
# @return [String]
|
|
16
|
-
def uri_to_file uri
|
|
17
|
-
decode(uri).sub(
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# Convert a file path to a URI.
|
|
21
|
-
#
|
|
22
|
-
# @param file [String]
|
|
23
|
-
# @return [String]
|
|
24
|
-
def file_to_uri file
|
|
25
|
-
"file://#{encode(file.gsub(/^([a-z]
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# Encode text to be used as a URI path component in LSP.
|
|
29
|
-
#
|
|
30
|
-
# @param text [String]
|
|
31
|
-
# @return [String]
|
|
32
|
-
def encode text
|
|
33
|
-
CGI.escape(text)
|
|
34
|
-
.gsub('%3A', ':')
|
|
35
|
-
.gsub('%5C', '\\')
|
|
36
|
-
.gsub('%2F', '/')
|
|
37
|
-
.gsub('+', '%20')
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
# Decode text from a URI path component in LSP.
|
|
41
|
-
#
|
|
42
|
-
# @param text [String]
|
|
43
|
-
# @return [String]
|
|
44
|
-
def decode text
|
|
45
|
-
CGI.unescape(text)
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'cgi'
|
|
4
|
+
|
|
5
|
+
module Solargraph
|
|
6
|
+
module LanguageServer
|
|
7
|
+
# Methods to handle conversions between file URIs and paths.
|
|
8
|
+
#
|
|
9
|
+
module UriHelpers
|
|
10
|
+
module_function
|
|
11
|
+
|
|
12
|
+
# Convert a file URI to a path.
|
|
13
|
+
#
|
|
14
|
+
# @param uri [String]
|
|
15
|
+
# @return [String]
|
|
16
|
+
def uri_to_file uri
|
|
17
|
+
decode(uri).sub(%r{^file:(?://)?}, '').sub(%r{^/([a-z]:)}i, '\1')
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Convert a file path to a URI.
|
|
21
|
+
#
|
|
22
|
+
# @param file [String]
|
|
23
|
+
# @return [String]
|
|
24
|
+
def file_to_uri file
|
|
25
|
+
"file://#{encode(file.gsub(/^([a-z]:)/i, '/\1'))}"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Encode text to be used as a URI path component in LSP.
|
|
29
|
+
#
|
|
30
|
+
# @param text [String]
|
|
31
|
+
# @return [String]
|
|
32
|
+
def encode text
|
|
33
|
+
CGI.escape(text)
|
|
34
|
+
.gsub('%3A', ':')
|
|
35
|
+
.gsub('%5C', '\\')
|
|
36
|
+
.gsub('%2F', '/')
|
|
37
|
+
.gsub('+', '%20')
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Decode text from a URI path component in LSP.
|
|
41
|
+
#
|
|
42
|
+
# @param text [String]
|
|
43
|
+
# @return [String]
|
|
44
|
+
def decode text
|
|
45
|
+
CGI.unescape(text)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
data/lib/solargraph/library.rb
CHANGED
|
@@ -127,8 +127,8 @@ module Solargraph
|
|
|
127
127
|
# @return [Boolean] True if at least one file was added to the workspace.
|
|
128
128
|
def create_from_disk *filenames
|
|
129
129
|
sources = filenames
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
.reject { |filename| File.directory?(filename) || !File.exist?(filename) }
|
|
131
|
+
.map { |filename| Solargraph::Source.load_string(File.read(filename), filename) }
|
|
132
132
|
result = workspace.merge(*sources)
|
|
133
133
|
sources.each { |source| maybe_map source }
|
|
134
134
|
result
|
|
@@ -195,10 +195,10 @@ module Solargraph
|
|
|
195
195
|
offset = Solargraph::Position.to_offset(source.code, Solargraph::Position.new(line, column))
|
|
196
196
|
# @sg-ignore Need to add nil check here
|
|
197
197
|
# @type [MatchData, nil]
|
|
198
|
-
lft = source.code[0..offset-1].match(/\[[a-z0-9_:<, ]*?([a-z0-9_:]*)\z/i)
|
|
198
|
+
lft = source.code[0..(offset - 1)].match(/\[[a-z0-9_:<, ]*?([a-z0-9_:]*)\z/i)
|
|
199
199
|
# @sg-ignore Need to add nil check here
|
|
200
200
|
# @type [MatchData, nil]
|
|
201
|
-
rgt = source.code[offset
|
|
201
|
+
rgt = source.code[offset..].match(/^([a-z0-9_]*)(:[a-z0-9_:]*)?[\]>, ]/i)
|
|
202
202
|
if lft && rgt
|
|
203
203
|
# @sg-ignore Need to add nil check here
|
|
204
204
|
tag = (lft[1] + rgt[1]).sub(/:+$/, '')
|
|
@@ -264,10 +264,10 @@ module Solargraph
|
|
|
264
264
|
return [] unless pin
|
|
265
265
|
result = []
|
|
266
266
|
files = if only
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
267
|
+
[api_map.source_map(filename)]
|
|
268
|
+
else
|
|
269
|
+
(workspace.sources + (@current ? [@current] : []))
|
|
270
|
+
end
|
|
271
271
|
files.uniq(&:filename).each do |source|
|
|
272
272
|
found = source.references(pin.name)
|
|
273
273
|
found.select! do |loc|
|
|
@@ -291,7 +291,7 @@ module Solargraph
|
|
|
291
291
|
end
|
|
292
292
|
end
|
|
293
293
|
# HACK: for language clients that exclude special characters from the start of variable names
|
|
294
|
-
if strip && match = cursor.word.match(/^[^a-z0-9_]+/i)
|
|
294
|
+
if strip && (match = cursor.word.match(/^[^a-z0-9_]+/i))
|
|
295
295
|
found.map! do |loc|
|
|
296
296
|
Solargraph::Location.new(loc.filename,
|
|
297
297
|
# @sg-ignore flow sensitive typing needs to handle if foo = bar
|
|
@@ -329,8 +329,8 @@ module Solargraph
|
|
|
329
329
|
end
|
|
330
330
|
workspace.require_paths.each do |path|
|
|
331
331
|
full = File.join path, pin.name
|
|
332
|
-
return_if_match.(full)
|
|
333
|
-
return_if_match.(full <<
|
|
332
|
+
return_if_match.call(full)
|
|
333
|
+
return_if_match.call(full << '.rb')
|
|
334
334
|
end
|
|
335
335
|
nil
|
|
336
336
|
rescue FileNotFoundError
|
|
@@ -543,15 +543,15 @@ module Solargraph
|
|
|
543
543
|
# @return [void]
|
|
544
544
|
def find_external_requires source_map
|
|
545
545
|
# @type [Set<String>]
|
|
546
|
-
new_set = source_map.requires.
|
|
546
|
+
new_set = source_map.requires.to_set(&:name)
|
|
547
547
|
# return if new_set == source_map_external_require_hash[source_map.filename]
|
|
548
548
|
_filenames = nil
|
|
549
|
-
filenames = ->{ _filenames ||= workspace.filenames.to_set }
|
|
549
|
+
filenames = -> { _filenames ||= workspace.filenames.to_set }
|
|
550
550
|
# @sg-ignore Need to add nil check here
|
|
551
551
|
source_map_external_require_hash[source_map.filename] = new_set.reject do |path|
|
|
552
552
|
workspace.require_paths.any? do |base|
|
|
553
553
|
full = File.join(base, path)
|
|
554
|
-
filenames[].include?(full) or filenames[].include?(full <<
|
|
554
|
+
filenames[].include?(full) or filenames[].include?(full << '.rb')
|
|
555
555
|
end
|
|
556
556
|
end
|
|
557
557
|
@external_requires = nil
|
|
@@ -585,12 +585,9 @@ module Solargraph
|
|
|
585
585
|
# @param error [FileNotFoundError]
|
|
586
586
|
# @return [nil]
|
|
587
587
|
def handle_file_not_found filename, error
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
else
|
|
592
|
-
raise error
|
|
593
|
-
end
|
|
588
|
+
raise error unless workspace.source(filename)
|
|
589
|
+
Solargraph.logger.debug "#{filename} is not cataloged in the ApiMap"
|
|
590
|
+
nil
|
|
594
591
|
end
|
|
595
592
|
|
|
596
593
|
# @param source [Source, nil]
|
|
@@ -679,16 +676,14 @@ module Solargraph
|
|
|
679
676
|
finished = @total - pending
|
|
680
677
|
# @sg-ignore flow sensitive typing needs better handling of ||= on lvars
|
|
681
678
|
pct = if @total.zero?
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
message = "#{gem_name}#{
|
|
679
|
+
0
|
|
680
|
+
else
|
|
681
|
+
# @sg-ignore flow sensitive typing needs better handling of ||= on lvars
|
|
682
|
+
((finished.to_f / @total) * 100).to_i
|
|
683
|
+
end
|
|
684
|
+
message = "#{gem_name}#{" (+#{pending})" if pending.positive?}"
|
|
688
685
|
# "
|
|
689
|
-
|
|
690
|
-
@cache_progress.report(message, pct)
|
|
691
|
-
else
|
|
686
|
+
unless @cache_progress
|
|
692
687
|
@cache_progress = LanguageServer::Progress.new('Caching gem')
|
|
693
688
|
# If we don't send both a begin and a report, the progress notification
|
|
694
689
|
# might get stuck in the status bar forever
|
|
@@ -696,9 +691,9 @@ module Solargraph
|
|
|
696
691
|
@cache_progress.begin(message, pct)
|
|
697
692
|
changed
|
|
698
693
|
notify_observers @cache_progress
|
|
699
|
-
# @sg-ignore flow sensitive typing should be able to handle redefinition
|
|
700
|
-
@cache_progress.report(message, pct)
|
|
701
694
|
end
|
|
695
|
+
# @sg-ignore flow sensitive typing should be able to handle redefinition
|
|
696
|
+
@cache_progress.report(message, pct)
|
|
702
697
|
changed
|
|
703
698
|
notify_observers @cache_progress
|
|
704
699
|
end
|
|
@@ -713,11 +708,11 @@ module Solargraph
|
|
|
713
708
|
|
|
714
709
|
# @return [void]
|
|
715
710
|
def sync_catalog
|
|
716
|
-
return if @sync_count
|
|
711
|
+
return if @sync_count.zero?
|
|
717
712
|
|
|
718
713
|
mutex.synchronize do
|
|
719
714
|
logger.info "Cataloging #{workspace.directory.empty? ? 'generic workspace' : workspace.directory}"
|
|
720
|
-
source_map_hash.
|
|
715
|
+
source_map_hash.each_value { |map| find_external_requires(map) }
|
|
721
716
|
api_map.catalog bench
|
|
722
717
|
logger.info "Catalog complete (#{api_map.source_maps.length} files, #{api_map.pins.length} pins)"
|
|
723
718
|
logger.info "#{api_map.uncached_gemspecs.length} uncached gemspecs"
|