solargraph 0.17.4 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/solargraph.rb +16 -12
- data/lib/solargraph/api_map.rb +516 -588
- data/lib/solargraph/api_map/completion.rb +16 -0
- data/lib/solargraph/api_map/source_to_yard.rb +2 -2
- data/lib/solargraph/language_server.rb +12 -0
- data/lib/solargraph/language_server/completion_item_kinds.rb +31 -0
- data/lib/solargraph/language_server/error_codes.rb +16 -0
- data/lib/solargraph/language_server/host.rb +305 -0
- data/lib/solargraph/language_server/message.rb +70 -0
- data/lib/solargraph/language_server/message/base.rb +64 -0
- data/lib/solargraph/language_server/message/cancel_request.rb +11 -0
- data/lib/solargraph/language_server/message/client.rb +5 -0
- data/lib/solargraph/language_server/message/client/register_capability.rb +13 -0
- data/lib/solargraph/language_server/message/completion_item.rb +9 -0
- data/lib/solargraph/language_server/message/completion_item/resolve.rb +23 -0
- data/lib/solargraph/language_server/message/exit_notification.rb +12 -0
- data/lib/solargraph/language_server/message/extended.rb +15 -0
- data/lib/solargraph/language_server/message/extended/document.rb +18 -0
- data/lib/solargraph/language_server/message/extended/search.rb +18 -0
- data/lib/solargraph/language_server/message/initialize.rb +39 -0
- data/lib/solargraph/language_server/message/initialized.rb +10 -0
- data/lib/solargraph/language_server/message/method_not_found.rb +14 -0
- data/lib/solargraph/language_server/message/method_not_implemented.rb +12 -0
- data/lib/solargraph/language_server/message/shutdown.rb +11 -0
- data/lib/solargraph/language_server/message/text_document.rb +21 -0
- data/lib/solargraph/language_server/message/text_document/base.rb +17 -0
- data/lib/solargraph/language_server/message/text_document/completion.rb +69 -0
- data/lib/solargraph/language_server/message/text_document/definition.rb +38 -0
- data/lib/solargraph/language_server/message/text_document/did_change.rb +15 -0
- data/lib/solargraph/language_server/message/text_document/did_close.rb +12 -0
- data/lib/solargraph/language_server/message/text_document/did_open.rb +13 -0
- data/lib/solargraph/language_server/message/text_document/did_save.rb +15 -0
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +31 -0
- data/lib/solargraph/language_server/message/text_document/formatting.rb +36 -0
- data/lib/solargraph/language_server/message/text_document/hover.rb +19 -0
- data/lib/solargraph/language_server/message/text_document/on_type_formatting.rb +29 -0
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +23 -0
- data/lib/solargraph/language_server/message/workspace.rb +11 -0
- data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +9 -0
- data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +30 -0
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +31 -0
- data/lib/solargraph/language_server/symbol_kinds.rb +32 -0
- data/lib/solargraph/language_server/transport.rb +7 -0
- data/lib/solargraph/language_server/transport/socket.rb +66 -0
- data/lib/solargraph/language_server/uri_helpers.rb +21 -0
- data/lib/solargraph/library.rb +225 -0
- data/lib/solargraph/live_map.rb +1 -1
- data/lib/solargraph/page.rb +61 -0
- data/lib/solargraph/pin.rb +7 -0
- data/lib/solargraph/pin/attribute.rb +9 -0
- data/lib/solargraph/pin/base.rb +76 -6
- data/lib/solargraph/pin/base_variable.rb +29 -7
- data/lib/solargraph/pin/block_parameter.rb +53 -0
- data/lib/solargraph/pin/constant.rb +6 -2
- data/lib/solargraph/pin/conversions.rb +65 -0
- data/lib/solargraph/pin/directed/attribute.rb +4 -0
- data/lib/solargraph/pin/directed/method.rb +6 -1
- data/lib/solargraph/pin/helper.rb +35 -0
- data/lib/solargraph/pin/keyword.rb +22 -0
- data/lib/solargraph/pin/local_variable.rb +0 -1
- data/lib/solargraph/pin/method.rb +55 -2
- data/lib/solargraph/pin/method_parameter.rb +19 -0
- data/lib/solargraph/pin/namespace.rb +7 -2
- data/lib/solargraph/pin/parameter.rb +23 -0
- data/lib/solargraph/pin/plugin/method.rb +3 -2
- data/lib/solargraph/pin/yard_object.rb +101 -0
- data/lib/solargraph/server.rb +82 -135
- data/lib/solargraph/shell.rb +20 -1
- data/lib/solargraph/source.rb +709 -0
- data/lib/solargraph/source/flawed_builder.rb +10 -0
- data/lib/solargraph/source/fragment.rb +319 -0
- data/lib/solargraph/source/position.rb +26 -0
- data/lib/solargraph/source/range.rb +39 -0
- data/lib/solargraph/suggestion.rb +29 -4
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace.rb +105 -0
- data/lib/solargraph/{api_map → workspace}/config.rb +1 -1
- data/lib/solargraph/yard_map.rb +59 -37
- metadata +168 -5
- data/lib/solargraph/api_map/source.rb +0 -470
- 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,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,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,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,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
|