solargraph 0.17.4 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/lib/solargraph.rb +16 -12
  3. data/lib/solargraph/api_map.rb +516 -588
  4. data/lib/solargraph/api_map/completion.rb +16 -0
  5. data/lib/solargraph/api_map/source_to_yard.rb +2 -2
  6. data/lib/solargraph/language_server.rb +12 -0
  7. data/lib/solargraph/language_server/completion_item_kinds.rb +31 -0
  8. data/lib/solargraph/language_server/error_codes.rb +16 -0
  9. data/lib/solargraph/language_server/host.rb +305 -0
  10. data/lib/solargraph/language_server/message.rb +70 -0
  11. data/lib/solargraph/language_server/message/base.rb +64 -0
  12. data/lib/solargraph/language_server/message/cancel_request.rb +11 -0
  13. data/lib/solargraph/language_server/message/client.rb +5 -0
  14. data/lib/solargraph/language_server/message/client/register_capability.rb +13 -0
  15. data/lib/solargraph/language_server/message/completion_item.rb +9 -0
  16. data/lib/solargraph/language_server/message/completion_item/resolve.rb +23 -0
  17. data/lib/solargraph/language_server/message/exit_notification.rb +12 -0
  18. data/lib/solargraph/language_server/message/extended.rb +15 -0
  19. data/lib/solargraph/language_server/message/extended/document.rb +18 -0
  20. data/lib/solargraph/language_server/message/extended/search.rb +18 -0
  21. data/lib/solargraph/language_server/message/initialize.rb +39 -0
  22. data/lib/solargraph/language_server/message/initialized.rb +10 -0
  23. data/lib/solargraph/language_server/message/method_not_found.rb +14 -0
  24. data/lib/solargraph/language_server/message/method_not_implemented.rb +12 -0
  25. data/lib/solargraph/language_server/message/shutdown.rb +11 -0
  26. data/lib/solargraph/language_server/message/text_document.rb +21 -0
  27. data/lib/solargraph/language_server/message/text_document/base.rb +17 -0
  28. data/lib/solargraph/language_server/message/text_document/completion.rb +69 -0
  29. data/lib/solargraph/language_server/message/text_document/definition.rb +38 -0
  30. data/lib/solargraph/language_server/message/text_document/did_change.rb +15 -0
  31. data/lib/solargraph/language_server/message/text_document/did_close.rb +12 -0
  32. data/lib/solargraph/language_server/message/text_document/did_open.rb +13 -0
  33. data/lib/solargraph/language_server/message/text_document/did_save.rb +15 -0
  34. data/lib/solargraph/language_server/message/text_document/document_symbol.rb +31 -0
  35. data/lib/solargraph/language_server/message/text_document/formatting.rb +36 -0
  36. data/lib/solargraph/language_server/message/text_document/hover.rb +19 -0
  37. data/lib/solargraph/language_server/message/text_document/on_type_formatting.rb +29 -0
  38. data/lib/solargraph/language_server/message/text_document/signature_help.rb +23 -0
  39. data/lib/solargraph/language_server/message/workspace.rb +11 -0
  40. data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +9 -0
  41. data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +30 -0
  42. data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +31 -0
  43. data/lib/solargraph/language_server/symbol_kinds.rb +32 -0
  44. data/lib/solargraph/language_server/transport.rb +7 -0
  45. data/lib/solargraph/language_server/transport/socket.rb +66 -0
  46. data/lib/solargraph/language_server/uri_helpers.rb +21 -0
  47. data/lib/solargraph/library.rb +225 -0
  48. data/lib/solargraph/live_map.rb +1 -1
  49. data/lib/solargraph/page.rb +61 -0
  50. data/lib/solargraph/pin.rb +7 -0
  51. data/lib/solargraph/pin/attribute.rb +9 -0
  52. data/lib/solargraph/pin/base.rb +76 -6
  53. data/lib/solargraph/pin/base_variable.rb +29 -7
  54. data/lib/solargraph/pin/block_parameter.rb +53 -0
  55. data/lib/solargraph/pin/constant.rb +6 -2
  56. data/lib/solargraph/pin/conversions.rb +65 -0
  57. data/lib/solargraph/pin/directed/attribute.rb +4 -0
  58. data/lib/solargraph/pin/directed/method.rb +6 -1
  59. data/lib/solargraph/pin/helper.rb +35 -0
  60. data/lib/solargraph/pin/keyword.rb +22 -0
  61. data/lib/solargraph/pin/local_variable.rb +0 -1
  62. data/lib/solargraph/pin/method.rb +55 -2
  63. data/lib/solargraph/pin/method_parameter.rb +19 -0
  64. data/lib/solargraph/pin/namespace.rb +7 -2
  65. data/lib/solargraph/pin/parameter.rb +23 -0
  66. data/lib/solargraph/pin/plugin/method.rb +3 -2
  67. data/lib/solargraph/pin/yard_object.rb +101 -0
  68. data/lib/solargraph/server.rb +82 -135
  69. data/lib/solargraph/shell.rb +20 -1
  70. data/lib/solargraph/source.rb +709 -0
  71. data/lib/solargraph/source/flawed_builder.rb +10 -0
  72. data/lib/solargraph/source/fragment.rb +319 -0
  73. data/lib/solargraph/source/position.rb +26 -0
  74. data/lib/solargraph/source/range.rb +39 -0
  75. data/lib/solargraph/suggestion.rb +29 -4
  76. data/lib/solargraph/version.rb +1 -1
  77. data/lib/solargraph/workspace.rb +105 -0
  78. data/lib/solargraph/{api_map → workspace}/config.rb +1 -1
  79. data/lib/solargraph/yard_map.rb +59 -37
  80. metadata +168 -5
  81. data/lib/solargraph/api_map/source.rb +0 -470
  82. data/lib/solargraph/code_map.rb +0 -868
@@ -0,0 +1,64 @@
1
+ module Solargraph
2
+ module LanguageServer
3
+ module Message
4
+ class Base
5
+ # @return [Solargraph::LanguageServer::Host]
6
+ attr_reader :host
7
+ attr_reader :id
8
+ attr_reader :request
9
+ attr_reader :method
10
+ attr_reader :params
11
+ attr_reader :result
12
+ attr_reader :error
13
+
14
+ def initialize host, request
15
+ @host = host
16
+ @id = request['id'].freeze
17
+ @request = request.freeze
18
+ @method = request['method'].freeze
19
+ @params = request['params'].freeze
20
+ post_initialize
21
+ end
22
+
23
+ def post_initialize
24
+ end
25
+
26
+ def process
27
+ end
28
+
29
+ def set_result data
30
+ @result = data
31
+ end
32
+
33
+ def set_error code, message
34
+ @error = {
35
+ code: code,
36
+ message: message
37
+ }
38
+ end
39
+
40
+ def response
41
+ response = {}
42
+ response[:result] = result
43
+ response[:error] = error unless error.nil?
44
+ response
45
+ end
46
+
47
+ def send
48
+ unless id.nil? or host.cancel?(id)
49
+ response = {
50
+ jsonrpc: "2.0",
51
+ id: id,
52
+ }
53
+ response[:result] = result unless result.nil?
54
+ response[:error] = error unless error.nil?
55
+ json = response.to_json
56
+ envelope = "Content-Length: #{json.bytesize}\r\n\r\n#{json}"
57
+ host.queue envelope
58
+ end
59
+ host.clear id
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,11 @@
1
+ module Solargraph
2
+ module LanguageServer
3
+ module Message
4
+ class CancelRequest < Base
5
+ def process
6
+ host.cancel params['id']
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Solargraph
2
+ module Client
3
+ autoload :RegisterCapability, 'solargraph/language_server/message/client/register_capability'
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ module Solargraph
2
+ module LanguageServer
3
+ module Message
4
+ module Client
5
+ class RegisterCapability < Solargraph::LanguageServer::Message::Base
6
+ def process
7
+
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module Solargraph
2
+ module LanguageServer
3
+ module Message
4
+ module CompletionItem
5
+ autoload :Resolve, 'solargraph/language_server/message/completion_item/resolve'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ require 'reverse_markdown'
2
+ require 'uri'
3
+
4
+ module Solargraph
5
+ module LanguageServer
6
+ module Message
7
+ module CompletionItem
8
+ class Resolve < Base
9
+ def process
10
+ pin = host.locate_pin params
11
+ if pin.nil?
12
+ set_error(Solargraph::LanguageServer::ErrorCodes::INVALID_REQUEST, "Completion item could not be resolved")
13
+ else
14
+ set_result(
15
+ params.merge(pin.resolve_completion_item)
16
+ )
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,12 @@
1
+ module Solargraph
2
+ module LanguageServer
3
+ module Message
4
+ class ExitNotification < Base
5
+ def process
6
+ host.stop
7
+ exit
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ module Solargraph
2
+ module LanguageServer
3
+ module Message
4
+ # Messages in the Extended module are custom to the Solargraph
5
+ # implementation of the language server. In the protocol, the method
6
+ # names should start with "$/" so clients that don't recognize them can
7
+ # ignore them, as per the LSP specification.
8
+ #
9
+ module Extended
10
+ autoload :Document, 'solargraph/language_server/message/extended/document'
11
+ autoload :Search, 'solargraph/language_server/message/extended/search'
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ module Solargraph
2
+ module LanguageServer
3
+ module Message
4
+ module Extended
5
+ class Document < Base
6
+ def process
7
+ objects = host.library.document(params['query'])
8
+ page = Solargraph::Page.new(host.options['viewsPath'])
9
+ content = page.render('document', locals: {objects: objects})
10
+ set_result(
11
+ content: content
12
+ )
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module Solargraph
2
+ module LanguageServer
3
+ module Message
4
+ module Extended
5
+ class Search < Base
6
+ def process
7
+ results = host.library.search(params['query'])
8
+ page = Solargraph::Page.new(host.options['viewsPath'])
9
+ content = page.render('search', locals: {query: params['query'], results: results})
10
+ set_result(
11
+ content: content
12
+ )
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,39 @@
1
+ module Solargraph
2
+ module LanguageServer
3
+ module Message
4
+ class Initialize < Base
5
+ def process
6
+ host.configure params['initializationOptions']
7
+ host.prepare params['rootPath']
8
+ set_result(
9
+ capabilities: {
10
+ textDocumentSync: 2, # @todo What should this be?
11
+ completionProvider: {
12
+ resolveProvider: true,
13
+ triggerCharacters: ['.', ':', '@']
14
+ },
15
+ hoverProvider: true,
16
+ definitionProvider: true,
17
+ signatureHelpProvider: {
18
+ triggerCharacters: ['(', ',']
19
+ },
20
+ documentFormattingProvider: true,
21
+ documentOnTypeFormattingProvider: {
22
+ firstTriggerCharacter: '{',
23
+ moreTriggerCharacter: ['(']
24
+ },
25
+ documentSymbolProvider: true,
26
+ workspaceSymbolProvider: true,
27
+ workspace: {
28
+ workspaceFolders: {
29
+ supported: true,
30
+ changeNotifications: true
31
+ }
32
+ }
33
+ }
34
+ )
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,10 @@
1
+ module Solargraph
2
+ module LanguageServer
3
+ module Message
4
+ class Initialized < Base
5
+ def process
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ module Solargraph
2
+ module LanguageServer
3
+ module Message
4
+ class MethodNotFound < Base
5
+ def process
6
+ set_error(
7
+ Solargraph::LanguageServer::ErrorCodes::METHOD_NOT_FOUND,
8
+ "Method not found: #{request['message']}"
9
+ )
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ module Solargraph
2
+ module LanguageServer
3
+ module Message
4
+ class MethodNotImplemented < Base
5
+ def process
6
+ # This method ignores optional requests, e.g., any method that
7
+ # starts with `$/`.
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ module Solargraph
2
+ module LanguageServer
3
+ module Message
4
+ class Shutdown < Base
5
+ def process
6
+ set_result({})
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ module Solargraph
2
+ module LanguageServer
3
+ module Message
4
+ module TextDocument
5
+ autoload :Base, 'solargraph/language_server/message/text_document/base'
6
+ autoload :Completion, 'solargraph/language_server/message/text_document/completion'
7
+ autoload :DidOpen, 'solargraph/language_server/message/text_document/did_open'
8
+ autoload :DidChange, 'solargraph/language_server/message/text_document/did_change'
9
+ autoload :DidClose, 'solargraph/language_server/message/text_document/did_close'
10
+ autoload :DidSave, 'solargraph/language_server/message/text_document/did_save'
11
+ autoload :Hover, 'solargraph/language_server/message/text_document/hover'
12
+ autoload :SignatureHelp, 'solargraph/language_server/message/text_document/signature_help'
13
+ autoload :DiagnosticsQueue, 'solargraph/language_server/message/text_document/diagnostics_queue'
14
+ autoload :OnTypeFormatting, 'solargraph/language_server/message/text_document/on_type_formatting'
15
+ autoload :Definition, 'solargraph/language_server/message/text_document/definition'
16
+ autoload :DocumentSymbol, 'solargraph/language_server/message/text_document/document_symbol'
17
+ autoload :Formatting, 'solargraph/language_server/message/text_document/formatting'
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ module Solargraph
2
+ module LanguageServer
3
+ module Message
4
+ module TextDocument
5
+ class Base < Solargraph::LanguageServer::Message::Base
6
+ include Solargraph::LanguageServer::UriHelpers
7
+
8
+ attr_reader :filename
9
+
10
+ def post_initialize
11
+ @filename = uri_to_file(params['textDocument']['uri'])
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,69 @@
1
+ require 'time'
2
+
3
+ module Solargraph
4
+ module LanguageServer
5
+ module Message
6
+ module TextDocument
7
+ class Completion < Base
8
+ def process
9
+ begin
10
+ start = Time.now
11
+ processed = false
12
+ until processed
13
+ host.synchronize do
14
+ if host.changing?(params['textDocument']['uri'])
15
+ # STDERR.puts "Waiting..."
16
+ if Time.now - start > 1
17
+ set_result empty_result
18
+ processed = true
19
+ end
20
+ else
21
+ inner_process
22
+ processed = true
23
+ end
24
+ end
25
+ sleep 0.1 unless processed
26
+ end
27
+ rescue Exception => e
28
+ STDERR.puts e.message
29
+ STDERR.puts e.backtrace
30
+ set_error ErrorCodes::INTERNAL_ERROR, e.message
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def inner_process
37
+ filename = uri_to_file(params['textDocument']['uri'])
38
+ line = params['position']['line']
39
+ col = params['position']['character']
40
+ completion = host.library.completions_at(filename, line, col)
41
+ items = []
42
+ idx = 0
43
+ completion.pins.each do |pin|
44
+ items.push pin.completion_item.merge({
45
+ textEdit: {
46
+ range: completion.range.to_hash,
47
+ newText: pin.name
48
+ },
49
+ sortText: "#{pin.name}#{idx.to_s.rjust(4, '0')}"
50
+ })
51
+ idx += 1
52
+ end
53
+ set_result(
54
+ isIncomplete: false,
55
+ items: items
56
+ )
57
+ end
58
+
59
+ def empty_result
60
+ {
61
+ isIncomplete: false,
62
+ items: []
63
+ }
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,38 @@
1
+ require 'uri'
2
+
3
+ module Solargraph::LanguageServer::Message::TextDocument
4
+ class Definition < Base
5
+ def process
6
+ # source = host.read(params['textDocument']['uri'])
7
+ # code_map = Solargraph::CodeMap.from_source(source, host.api_map)
8
+ # offset = code_map.get_offset(params['position']['line'], params['position']['character'])
9
+ # suggestions = code_map.define_symbol_at(offset)
10
+ filename = uri_to_file(params['textDocument']['uri'])
11
+ line = params['position']['line']
12
+ col = params['position']['character']
13
+ suggestions = host.library.definitions_at(filename, line, col)
14
+ locations = suggestions.map do |pin|
15
+ unless pin.location.nil?
16
+ parts = pin.location.split(':')
17
+ char = parts.pop.to_i
18
+ line = parts.pop.to_i
19
+ filename = parts.join(':')
20
+ {
21
+ uri: file_to_uri(filename),
22
+ range: {
23
+ start: {
24
+ line: line,
25
+ character: char
26
+ },
27
+ end: {
28
+ line: line,
29
+ character: char
30
+ }
31
+ }
32
+ }
33
+ end
34
+ end
35
+ set_result locations
36
+ end
37
+ end
38
+ end