solargraph 0.32.1 → 0.32.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +6 -0
- data/.travis.yml +25 -0
- data/EXAMPLES.md +76 -0
- data/Gemfile +3 -0
- data/LANGUAGE_SERVER.md +51 -0
- data/LICENSE +21 -0
- data/OVERVIEW.md +37 -0
- data/README.md +106 -0
- data/Rakefile +14 -0
- data/SERVER.md +95 -0
- data/bin/solargraph +0 -0
- data/bin/solargraph-runtime +5 -5
- data/lib/solargraph.rb +54 -54
- data/lib/solargraph/api_map.rb +659 -659
- data/lib/solargraph/api_map/cache.rb +49 -49
- data/lib/solargraph/api_map/source_to_yard.rb +67 -67
- data/lib/solargraph/api_map/store.rb +201 -201
- data/lib/solargraph/bundle.rb +24 -24
- data/lib/solargraph/complex_type.rb +150 -150
- data/lib/solargraph/complex_type/type_methods.rb +124 -124
- data/lib/solargraph/complex_type/unique_type.rb +44 -44
- data/lib/solargraph/core_fills.rb +37 -37
- data/lib/solargraph/diagnostics.rb +52 -52
- data/lib/solargraph/diagnostics/base.rb +20 -20
- data/lib/solargraph/diagnostics/require_not_found.rb +28 -28
- data/lib/solargraph/diagnostics/rubocop.rb +98 -98
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +46 -46
- data/lib/solargraph/diagnostics/type_not_defined.rb +108 -108
- data/lib/solargraph/diagnostics/update_errors.rb +38 -38
- data/lib/solargraph/language_server/completion_item_kinds.rb +33 -33
- data/lib/solargraph/language_server/error_codes.rb +18 -18
- data/lib/solargraph/language_server/host.rb +684 -681
- data/lib/solargraph/language_server/host/cataloger.rb +54 -79
- data/lib/solargraph/language_server/host/diagnoser.rb +80 -80
- data/lib/solargraph/language_server/host/dispatch.rb +112 -113
- data/lib/solargraph/language_server/host/sources.rb +138 -138
- data/lib/solargraph/language_server/message.rb +90 -90
- data/lib/solargraph/language_server/message/base.rb +83 -83
- data/lib/solargraph/language_server/message/completion_item/resolve.rb +40 -40
- data/lib/solargraph/language_server/message/exit_notification.rb +11 -11
- data/lib/solargraph/language_server/message/extended.rb +19 -19
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +86 -86
- data/lib/solargraph/language_server/message/extended/document.rb +18 -18
- data/lib/solargraph/language_server/message/extended/document_gems.rb +30 -30
- data/lib/solargraph/language_server/message/extended/environment.rb +20 -20
- data/lib/solargraph/language_server/message/extended/search.rb +18 -18
- data/lib/solargraph/language_server/message/initialize.rb +141 -141
- data/lib/solargraph/language_server/message/initialized.rb +23 -23
- data/lib/solargraph/language_server/message/shutdown.rb +11 -11
- data/lib/solargraph/language_server/message/text_document.rb +25 -25
- data/lib/solargraph/language_server/message/text_document/completion.rb +51 -51
- data/lib/solargraph/language_server/message/text_document/definition.rb +18 -18
- data/lib/solargraph/language_server/message/text_document/did_change.rb +13 -13
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +21 -21
- data/lib/solargraph/language_server/message/text_document/folding_range.rb +24 -24
- data/lib/solargraph/language_server/message/text_document/formatting.rb +50 -50
- data/lib/solargraph/language_server/message/text_document/hover.rb +31 -31
- data/lib/solargraph/language_server/message/text_document/on_type_formatting.rb +32 -32
- data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +9 -9
- data/lib/solargraph/language_server/message/text_document/references.rb +14 -14
- data/lib/solargraph/language_server/message/text_document/rename.rb +17 -17
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +19 -19
- data/lib/solargraph/language_server/message/workspace.rb +12 -12
- data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +29 -29
- data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +29 -27
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +24 -24
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +21 -21
- data/lib/solargraph/language_server/request.rb +22 -22
- data/lib/solargraph/language_server/symbol_kinds.rb +34 -34
- data/lib/solargraph/language_server/transport.rb +11 -11
- data/lib/solargraph/language_server/transport/adapter.rb +60 -60
- data/lib/solargraph/language_server/transport/data_reader.rb +66 -66
- data/lib/solargraph/language_server/uri_helpers.rb +25 -25
- data/lib/solargraph/library.rb +421 -419
- data/lib/solargraph/live_map.rb +126 -126
- data/lib/solargraph/live_map/cache.rb +38 -38
- data/lib/solargraph/location.rb +31 -31
- data/lib/solargraph/logging.rb +25 -25
- data/lib/solargraph/page.rb +68 -68
- data/lib/solargraph/pin.rb +50 -50
- data/lib/solargraph/pin/attribute.rb +41 -41
- data/lib/solargraph/pin/base.rb +280 -280
- data/lib/solargraph/pin/base_method.rb +76 -76
- data/lib/solargraph/pin/base_variable.rb +72 -72
- data/lib/solargraph/pin/block.rb +32 -32
- data/lib/solargraph/pin/block_parameter.rb +103 -103
- data/lib/solargraph/pin/class_variable.rb +9 -9
- data/lib/solargraph/pin/constant.rb +30 -30
- data/lib/solargraph/pin/conversions.rb +79 -79
- data/lib/solargraph/pin/documenting.rb +41 -41
- data/lib/solargraph/pin/duck_method.rb +14 -14
- data/lib/solargraph/pin/global_variable.rb +9 -9
- data/lib/solargraph/pin/instance_variable.rb +9 -9
- data/lib/solargraph/pin/keyword.rb +17 -17
- data/lib/solargraph/pin/local_variable.rb +23 -23
- data/lib/solargraph/pin/localized.rb +22 -22
- data/lib/solargraph/pin/method.rb +126 -126
- data/lib/solargraph/pin/method_alias.rb +30 -30
- data/lib/solargraph/pin/method_parameter.rb +40 -40
- data/lib/solargraph/pin/namespace.rb +54 -54
- data/lib/solargraph/pin/plugin/method.rb +25 -25
- data/lib/solargraph/pin/proxy_type.rb +35 -35
- data/lib/solargraph/pin/reference.rb +22 -22
- data/lib/solargraph/pin/reference/extend.rb +11 -11
- data/lib/solargraph/pin/reference/include.rb +11 -11
- data/lib/solargraph/pin/reference/require.rb +15 -15
- data/lib/solargraph/pin/reference/superclass.rb +11 -11
- data/lib/solargraph/pin/symbol.rb +44 -44
- data/lib/solargraph/pin/yard_pin.rb +10 -10
- data/lib/solargraph/pin/yard_pin/constant.rb +14 -14
- data/lib/solargraph/pin/yard_pin/method.rb +35 -35
- data/lib/solargraph/pin/yard_pin/namespace.rb +19 -19
- data/lib/solargraph/pin/yard_pin/yard_mixin.rb +14 -14
- data/lib/solargraph/plugin.rb +8 -8
- data/lib/solargraph/plugin/base.rb +41 -41
- data/lib/solargraph/plugin/canceler.rb +11 -11
- data/lib/solargraph/plugin/process.rb +172 -172
- data/lib/solargraph/plugin/runtime.rb +134 -134
- data/lib/solargraph/position.rb +110 -110
- data/lib/solargraph/range.rb +83 -83
- data/lib/solargraph/server_methods.rb +14 -14
- data/lib/solargraph/shell.rb +102 -102
- data/lib/solargraph/source.rb +521 -521
- data/lib/solargraph/source/chain.rb +120 -120
- data/lib/solargraph/source/chain/call.rb +107 -107
- data/lib/solargraph/source/chain/class_variable.rb +11 -11
- data/lib/solargraph/source/chain/constant.rb +30 -30
- data/lib/solargraph/source/chain/global_variable.rb +11 -11
- data/lib/solargraph/source/chain/head.rb +33 -33
- data/lib/solargraph/source/chain/instance_variable.rb +11 -11
- data/lib/solargraph/source/chain/link.rb +33 -33
- data/lib/solargraph/source/chain/literal.rb +21 -21
- data/lib/solargraph/source/chain/variable.rb +11 -11
- data/lib/solargraph/source/change.rb +77 -77
- data/lib/solargraph/source/cursor.rb +157 -157
- data/lib/solargraph/source/node_chainer.rb +96 -96
- data/lib/solargraph/source/node_methods.rb +225 -225
- data/lib/solargraph/source/source_chainer.rb +183 -183
- data/lib/solargraph/source_map.rb +169 -169
- data/lib/solargraph/source_map/clip.rb +145 -145
- data/lib/solargraph/source_map/completion.rb +21 -21
- data/lib/solargraph/source_map/mapper.rb +149 -149
- data/lib/solargraph/source_map/node_processor.rb +78 -78
- data/lib/solargraph/source_map/node_processor/alias_node.rb +19 -19
- data/lib/solargraph/source_map/node_processor/args_node.rb +28 -28
- data/lib/solargraph/source_map/node_processor/base.rb +68 -68
- data/lib/solargraph/source_map/node_processor/begin_node.rb +11 -11
- data/lib/solargraph/source_map/node_processor/block_node.rb +14 -14
- data/lib/solargraph/source_map/node_processor/casgn_node.rb +14 -14
- data/lib/solargraph/source_map/node_processor/cvasgn_node.rb +14 -14
- data/lib/solargraph/source_map/node_processor/def_node.rb +54 -54
- data/lib/solargraph/source_map/node_processor/defs_node.rb +21 -21
- data/lib/solargraph/source_map/node_processor/gvasgn_node.rb +12 -12
- data/lib/solargraph/source_map/node_processor/ivasgn_node.rb +18 -18
- data/lib/solargraph/source_map/node_processor/lvasgn_node.rb +16 -16
- data/lib/solargraph/source_map/node_processor/namespace_node.rb +26 -26
- data/lib/solargraph/source_map/node_processor/orasgn_node.rb +12 -12
- data/lib/solargraph/source_map/node_processor/sclass_node.rb +11 -11
- data/lib/solargraph/source_map/node_processor/send_node.rb +162 -162
- data/lib/solargraph/source_map/node_processor/sym_node.rb +11 -11
- data/lib/solargraph/source_map/region.rb +58 -58
- data/lib/solargraph/version.rb +3 -3
- data/lib/solargraph/views/environment.erb +53 -53
- data/lib/solargraph/workspace.rb +183 -183
- data/lib/solargraph/workspace/config.rb +170 -170
- data/lib/solargraph/yard_map.rb +298 -298
- data/lib/solargraph/yard_map/cache.rb +17 -17
- data/lib/solargraph/yard_map/core_docs.rb +163 -163
- data/lib/solargraph/yard_map/core_gen.rb +76 -76
- data/lib/yard-coregen.rb +16 -16
- data/lib/yard-solargraph.rb +18 -18
- data/solargraph.gemspec +37 -0
- data/travis-bundler.rb +10 -0
- metadata +19 -6
@@ -1,21 +1,21 @@
|
|
1
|
-
module Solargraph
|
2
|
-
class SourceMap
|
3
|
-
# The result of a completion request containing the pins that describe
|
4
|
-
# completion options and the range to be replaced.
|
5
|
-
#
|
6
|
-
class Completion
|
7
|
-
# @return [Array<Solargraph::Pin::Base>]
|
8
|
-
attr_reader :pins
|
9
|
-
|
10
|
-
# @return [Solargraph::Range]
|
11
|
-
attr_reader :range
|
12
|
-
|
13
|
-
# @param pins [Array<Solargraph::Pin::Base>]
|
14
|
-
# @param range [Solargraph::Range]
|
15
|
-
def initialize pins, range
|
16
|
-
@pins = pins
|
17
|
-
@range = range
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
1
|
+
module Solargraph
|
2
|
+
class SourceMap
|
3
|
+
# The result of a completion request containing the pins that describe
|
4
|
+
# completion options and the range to be replaced.
|
5
|
+
#
|
6
|
+
class Completion
|
7
|
+
# @return [Array<Solargraph::Pin::Base>]
|
8
|
+
attr_reader :pins
|
9
|
+
|
10
|
+
# @return [Solargraph::Range]
|
11
|
+
attr_reader :range
|
12
|
+
|
13
|
+
# @param pins [Array<Solargraph::Pin::Base>]
|
14
|
+
# @param range [Solargraph::Range]
|
15
|
+
def initialize pins, range
|
16
|
+
@pins = pins
|
17
|
+
@range = range
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,149 +1,149 @@
|
|
1
|
-
module Solargraph
|
2
|
-
class SourceMap
|
3
|
-
# The Mapper generates pins and other data for SourceMaps.
|
4
|
-
#
|
5
|
-
# This class is used internally by the SourceMap class. Users should not
|
6
|
-
# normally need to call it directly.
|
7
|
-
#
|
8
|
-
class Mapper
|
9
|
-
include Source::NodeMethods
|
10
|
-
|
11
|
-
private_class_method :new
|
12
|
-
|
13
|
-
MACRO_REGEXP = /(@\!method|@\!attribute|@\!domain|@\!macro|@\!parse)/.freeze
|
14
|
-
|
15
|
-
# Generate the data.
|
16
|
-
#
|
17
|
-
# @param source [Source]
|
18
|
-
# @return [Array]
|
19
|
-
def map source
|
20
|
-
@source = source
|
21
|
-
@filename = source.filename
|
22
|
-
@code = source.code
|
23
|
-
@comments = source.comments
|
24
|
-
@pins = NodeProcessor.process(source.node, Region.new(source: source))
|
25
|
-
process_comment_directives
|
26
|
-
locals = @pins.select{|p| [Pin::LocalVariable, Pin::MethodParameter, Pin::BlockParameter].include?(p.class)}
|
27
|
-
[@pins - locals, locals]
|
28
|
-
rescue Exception => e
|
29
|
-
Solargraph.logger.warn "Error mapping #{source.filename}: [#{e.class}] #{e.message}"
|
30
|
-
Solargraph.logger.warn e.backtrace
|
31
|
-
[[], []]
|
32
|
-
end
|
33
|
-
|
34
|
-
def unmap filename, code
|
35
|
-
s = Position.new(0, 0)
|
36
|
-
e = Position.from_offset(code, code.length)
|
37
|
-
location = Location.new(filename, Range.new(s, e))
|
38
|
-
[[Pin::Namespace.new(location, '', '', '', :class, :public)], []]
|
39
|
-
end
|
40
|
-
|
41
|
-
class << self
|
42
|
-
# @param source [Source]
|
43
|
-
# @return [Array]
|
44
|
-
def map source
|
45
|
-
return new.unmap(source.filename, source.code) unless source.parsed?
|
46
|
-
new.map source
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# @return [Array<Solargraph::Pin::Base>]
|
51
|
-
def pins
|
52
|
-
@pins ||= []
|
53
|
-
end
|
54
|
-
|
55
|
-
# @param node [Parser::AST::Node]
|
56
|
-
# @return [Solargraph::Pin::Namespace]
|
57
|
-
def namespace_for(node)
|
58
|
-
position = Position.new(node.loc.line, node.loc.column)
|
59
|
-
namespace_at(position)
|
60
|
-
end
|
61
|
-
|
62
|
-
def namespace_at(position)
|
63
|
-
@pins.select{|pin| pin.kind == Pin::NAMESPACE and pin.location.range.contain?(position)}.last
|
64
|
-
end
|
65
|
-
|
66
|
-
def process_comment source_position, comment_position, comment
|
67
|
-
return unless comment =~ MACRO_REGEXP
|
68
|
-
cmnt = remove_inline_comment_hashes(comment)
|
69
|
-
parse = Solargraph::Source.parse_docstring(cmnt)
|
70
|
-
parse.directives.each { |d| process_directive(source_position, comment_position, d) }
|
71
|
-
end
|
72
|
-
|
73
|
-
# @param position [Position]
|
74
|
-
# @param directive [YARD::Tags::Directive]
|
75
|
-
def process_directive source_position, comment_position, directive
|
76
|
-
docstring = Solargraph::Source.parse_docstring(directive.tag.text).to_docstring
|
77
|
-
location = Location.new(@filename, Range.new(comment_position, comment_position))
|
78
|
-
case directive.tag.tag_name
|
79
|
-
when 'method'
|
80
|
-
namespace = namespace_at(source_position)
|
81
|
-
gen_src = Solargraph::SourceMap.load_string("def #{directive.tag.name};end")
|
82
|
-
gen_pin = gen_src.pins.select{ |p| p.kind == Pin::METHOD }.first
|
83
|
-
return if gen_pin.nil?
|
84
|
-
@pins.push Solargraph::Pin::Method.new(location, namespace.path, gen_pin.name, docstring.all, :instance, :public, gen_pin.parameters, nil)
|
85
|
-
when 'attribute'
|
86
|
-
namespace = namespace_at(source_position)
|
87
|
-
t = (directive.tag.types.nil? || directive.tag.types.empty?) ? nil : directive.tag.types.flatten.join('')
|
88
|
-
if t.nil? || t.include?('r')
|
89
|
-
# location, namespace, name, docstring, access
|
90
|
-
pins.push Solargraph::Pin::Attribute.new(location, namespace.path, directive.tag.name, docstring.all, :reader, :instance, :public)
|
91
|
-
end
|
92
|
-
if t.nil? || t.include?('w')
|
93
|
-
pins.push Solargraph::Pin::Attribute.new(location, namespace.path, "#{directive.tag.name}=", docstring.all, :writer, :instance, :public)
|
94
|
-
end
|
95
|
-
when 'parse'
|
96
|
-
# @todo Parse and map directive.tag.text
|
97
|
-
ns = namespace_at(comment_position)
|
98
|
-
region = Region.new(source: @source, namespace: ns.path)
|
99
|
-
begin
|
100
|
-
node = Solargraph::Source.parse(directive.tag.text, @filename, comment_position.line)
|
101
|
-
NodeProcessor.process(node, region, @pins)
|
102
|
-
rescue Parser::SyntaxError => e
|
103
|
-
# @todo Handle parser errors in !parse directives
|
104
|
-
end
|
105
|
-
when 'domain'
|
106
|
-
namespace = namespace_at(source_position)
|
107
|
-
namespace.domains.concat directive.tag.types unless directive.tag.types.nil?
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def remove_inline_comment_hashes comment
|
112
|
-
ctxt = ''
|
113
|
-
num = nil
|
114
|
-
started = false
|
115
|
-
comment.lines.each { |l|
|
116
|
-
# Trim the comment and minimum leading whitespace
|
117
|
-
p = l.gsub(/^#/, '')
|
118
|
-
if num.nil? && !p.strip.empty?
|
119
|
-
num = p.index(/[^ ]/)
|
120
|
-
started = true
|
121
|
-
elsif started && !p.strip.empty?
|
122
|
-
cur = p.index(/[^ ]/)
|
123
|
-
num = cur if cur < num
|
124
|
-
end
|
125
|
-
ctxt += "#{p[num..-1]}\n" if started
|
126
|
-
}
|
127
|
-
ctxt
|
128
|
-
end
|
129
|
-
|
130
|
-
# @return [void]
|
131
|
-
def process_comment_directives
|
132
|
-
return unless @code =~ MACRO_REGEXP
|
133
|
-
used = []
|
134
|
-
@source.associated_comments.each do |line, comments|
|
135
|
-
used.concat comments
|
136
|
-
src_pos = Position.new(line, @code.lines[line].chomp.length)
|
137
|
-
com_pos = Position.new(comments.first.loc.line, comments.first.loc.column)
|
138
|
-
txt = comments.map(&:text).join("\n")
|
139
|
-
process_comment(src_pos, com_pos, txt)
|
140
|
-
end
|
141
|
-
left = @comments - used
|
142
|
-
return if left.empty?
|
143
|
-
txt = left.map(&:text).join("\n")
|
144
|
-
com_pos = Position.new(left.first.loc.line, left.first.loc.column)
|
145
|
-
process_comment(com_pos, com_pos, txt)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
1
|
+
module Solargraph
|
2
|
+
class SourceMap
|
3
|
+
# The Mapper generates pins and other data for SourceMaps.
|
4
|
+
#
|
5
|
+
# This class is used internally by the SourceMap class. Users should not
|
6
|
+
# normally need to call it directly.
|
7
|
+
#
|
8
|
+
class Mapper
|
9
|
+
include Source::NodeMethods
|
10
|
+
|
11
|
+
private_class_method :new
|
12
|
+
|
13
|
+
MACRO_REGEXP = /(@\!method|@\!attribute|@\!domain|@\!macro|@\!parse)/.freeze
|
14
|
+
|
15
|
+
# Generate the data.
|
16
|
+
#
|
17
|
+
# @param source [Source]
|
18
|
+
# @return [Array]
|
19
|
+
def map source
|
20
|
+
@source = source
|
21
|
+
@filename = source.filename
|
22
|
+
@code = source.code
|
23
|
+
@comments = source.comments
|
24
|
+
@pins = NodeProcessor.process(source.node, Region.new(source: source))
|
25
|
+
process_comment_directives
|
26
|
+
locals = @pins.select{|p| [Pin::LocalVariable, Pin::MethodParameter, Pin::BlockParameter].include?(p.class)}
|
27
|
+
[@pins - locals, locals]
|
28
|
+
rescue Exception => e
|
29
|
+
Solargraph.logger.warn "Error mapping #{source.filename}: [#{e.class}] #{e.message}"
|
30
|
+
Solargraph.logger.warn e.backtrace
|
31
|
+
[[], []]
|
32
|
+
end
|
33
|
+
|
34
|
+
def unmap filename, code
|
35
|
+
s = Position.new(0, 0)
|
36
|
+
e = Position.from_offset(code, code.length)
|
37
|
+
location = Location.new(filename, Range.new(s, e))
|
38
|
+
[[Pin::Namespace.new(location, '', '', '', :class, :public)], []]
|
39
|
+
end
|
40
|
+
|
41
|
+
class << self
|
42
|
+
# @param source [Source]
|
43
|
+
# @return [Array]
|
44
|
+
def map source
|
45
|
+
return new.unmap(source.filename, source.code) unless source.parsed?
|
46
|
+
new.map source
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [Array<Solargraph::Pin::Base>]
|
51
|
+
def pins
|
52
|
+
@pins ||= []
|
53
|
+
end
|
54
|
+
|
55
|
+
# @param node [Parser::AST::Node]
|
56
|
+
# @return [Solargraph::Pin::Namespace]
|
57
|
+
def namespace_for(node)
|
58
|
+
position = Position.new(node.loc.line, node.loc.column)
|
59
|
+
namespace_at(position)
|
60
|
+
end
|
61
|
+
|
62
|
+
def namespace_at(position)
|
63
|
+
@pins.select{|pin| pin.kind == Pin::NAMESPACE and pin.location.range.contain?(position)}.last
|
64
|
+
end
|
65
|
+
|
66
|
+
def process_comment source_position, comment_position, comment
|
67
|
+
return unless comment =~ MACRO_REGEXP
|
68
|
+
cmnt = remove_inline_comment_hashes(comment)
|
69
|
+
parse = Solargraph::Source.parse_docstring(cmnt)
|
70
|
+
parse.directives.each { |d| process_directive(source_position, comment_position, d) }
|
71
|
+
end
|
72
|
+
|
73
|
+
# @param position [Position]
|
74
|
+
# @param directive [YARD::Tags::Directive]
|
75
|
+
def process_directive source_position, comment_position, directive
|
76
|
+
docstring = Solargraph::Source.parse_docstring(directive.tag.text).to_docstring
|
77
|
+
location = Location.new(@filename, Range.new(comment_position, comment_position))
|
78
|
+
case directive.tag.tag_name
|
79
|
+
when 'method'
|
80
|
+
namespace = namespace_at(source_position)
|
81
|
+
gen_src = Solargraph::SourceMap.load_string("def #{directive.tag.name};end")
|
82
|
+
gen_pin = gen_src.pins.select{ |p| p.kind == Pin::METHOD }.first
|
83
|
+
return if gen_pin.nil?
|
84
|
+
@pins.push Solargraph::Pin::Method.new(location, namespace.path, gen_pin.name, docstring.all, :instance, :public, gen_pin.parameters, nil)
|
85
|
+
when 'attribute'
|
86
|
+
namespace = namespace_at(source_position)
|
87
|
+
t = (directive.tag.types.nil? || directive.tag.types.empty?) ? nil : directive.tag.types.flatten.join('')
|
88
|
+
if t.nil? || t.include?('r')
|
89
|
+
# location, namespace, name, docstring, access
|
90
|
+
pins.push Solargraph::Pin::Attribute.new(location, namespace.path, directive.tag.name, docstring.all, :reader, :instance, :public)
|
91
|
+
end
|
92
|
+
if t.nil? || t.include?('w')
|
93
|
+
pins.push Solargraph::Pin::Attribute.new(location, namespace.path, "#{directive.tag.name}=", docstring.all, :writer, :instance, :public)
|
94
|
+
end
|
95
|
+
when 'parse'
|
96
|
+
# @todo Parse and map directive.tag.text
|
97
|
+
ns = namespace_at(comment_position)
|
98
|
+
region = Region.new(source: @source, namespace: ns.path)
|
99
|
+
begin
|
100
|
+
node = Solargraph::Source.parse(directive.tag.text, @filename, comment_position.line)
|
101
|
+
NodeProcessor.process(node, region, @pins)
|
102
|
+
rescue Parser::SyntaxError => e
|
103
|
+
# @todo Handle parser errors in !parse directives
|
104
|
+
end
|
105
|
+
when 'domain'
|
106
|
+
namespace = namespace_at(source_position)
|
107
|
+
namespace.domains.concat directive.tag.types unless directive.tag.types.nil?
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def remove_inline_comment_hashes comment
|
112
|
+
ctxt = ''
|
113
|
+
num = nil
|
114
|
+
started = false
|
115
|
+
comment.lines.each { |l|
|
116
|
+
# Trim the comment and minimum leading whitespace
|
117
|
+
p = l.gsub(/^#/, '')
|
118
|
+
if num.nil? && !p.strip.empty?
|
119
|
+
num = p.index(/[^ ]/)
|
120
|
+
started = true
|
121
|
+
elsif started && !p.strip.empty?
|
122
|
+
cur = p.index(/[^ ]/)
|
123
|
+
num = cur if cur < num
|
124
|
+
end
|
125
|
+
ctxt += "#{p[num..-1]}\n" if started
|
126
|
+
}
|
127
|
+
ctxt
|
128
|
+
end
|
129
|
+
|
130
|
+
# @return [void]
|
131
|
+
def process_comment_directives
|
132
|
+
return unless @code =~ MACRO_REGEXP
|
133
|
+
used = []
|
134
|
+
@source.associated_comments.each do |line, comments|
|
135
|
+
used.concat comments
|
136
|
+
src_pos = Position.new(line, @code.lines[line].chomp.length)
|
137
|
+
com_pos = Position.new(comments.first.loc.line, comments.first.loc.column)
|
138
|
+
txt = comments.map(&:text).join("\n")
|
139
|
+
process_comment(src_pos, com_pos, txt)
|
140
|
+
end
|
141
|
+
left = @comments - used
|
142
|
+
return if left.empty?
|
143
|
+
txt = left.map(&:text).join("\n")
|
144
|
+
com_pos = Position.new(left.first.loc.line, left.first.loc.column)
|
145
|
+
process_comment(com_pos, com_pos, txt)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -1,78 +1,78 @@
|
|
1
|
-
module Solargraph
|
2
|
-
class SourceMap
|
3
|
-
# The processor classes used by SourceMap::Mapper to generate pins from
|
4
|
-
# parser nodes.
|
5
|
-
#
|
6
|
-
module NodeProcessor
|
7
|
-
autoload :Base, 'solargraph/source_map/node_processor/base'
|
8
|
-
autoload :BeginNode, 'solargraph/source_map/node_processor/begin_node'
|
9
|
-
autoload :DefNode, 'solargraph/source_map/node_processor/def_node'
|
10
|
-
autoload :DefsNode, 'solargraph/source_map/node_processor/defs_node'
|
11
|
-
autoload :SendNode, 'solargraph/source_map/node_processor/send_node'
|
12
|
-
autoload :NamespaceNode, 'solargraph/source_map/node_processor/namespace_node'
|
13
|
-
autoload :SclassNode, 'solargraph/source_map/node_processor/sclass_node'
|
14
|
-
autoload :ModuleNode, 'solargraph/source_map/node_processor/module_node'
|
15
|
-
autoload :IvasgnNode, 'solargraph/source_map/node_processor/ivasgn_node'
|
16
|
-
autoload :CvasgnNode, 'solargraph/source_map/node_processor/cvasgn_node'
|
17
|
-
autoload :LvasgnNode, 'solargraph/source_map/node_processor/lvasgn_node'
|
18
|
-
autoload :GvasgnNode, 'solargraph/source_map/node_processor/gvasgn_node'
|
19
|
-
autoload :CasgnNode, 'solargraph/source_map/node_processor/casgn_node'
|
20
|
-
autoload :AliasNode, 'solargraph/source_map/node_processor/alias_node'
|
21
|
-
autoload :ArgsNode, 'solargraph/source_map/node_processor/args_node'
|
22
|
-
autoload :BlockNode, 'solargraph/source_map/node_processor/block_node'
|
23
|
-
autoload :OrasgnNode, 'solargraph/source_map/node_processor/orasgn_node'
|
24
|
-
autoload :SymNode, 'solargraph/source_map/node_processor/sym_node'
|
25
|
-
|
26
|
-
class << self
|
27
|
-
@@processors ||= {}
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
# Register a processor for a node type.
|
32
|
-
#
|
33
|
-
# @param type [Symbol]
|
34
|
-
# @param cls [Class<NodeProcessor::Base>]
|
35
|
-
# @return [Class<NodeProcessor::Base>]
|
36
|
-
def register type, cls
|
37
|
-
@@processors[type] = cls
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
register :source, BeginNode
|
42
|
-
register :begin, BeginNode
|
43
|
-
register :kwbegin, BeginNode
|
44
|
-
# # @todo Is this the best way to handle rescue nodes?
|
45
|
-
register :rescue, BeginNode
|
46
|
-
register :resbody, BeginNode
|
47
|
-
register :def, DefNode
|
48
|
-
register :defs, DefsNode
|
49
|
-
register :send, SendNode
|
50
|
-
register :class, NamespaceNode
|
51
|
-
register :module, NamespaceNode
|
52
|
-
register :sclass, SclassNode
|
53
|
-
register :ivasgn, IvasgnNode
|
54
|
-
register :cvasgn, CvasgnNode
|
55
|
-
register :lvasgn, LvasgnNode
|
56
|
-
register :gvasgn, GvasgnNode
|
57
|
-
register :casgn, CasgnNode
|
58
|
-
register :alias, AliasNode
|
59
|
-
register :args, ArgsNode
|
60
|
-
register :block, BlockNode
|
61
|
-
register :or_asgn, OrasgnNode
|
62
|
-
register :sym, SymNode
|
63
|
-
|
64
|
-
# @param node [Parser::AST::Node]
|
65
|
-
# @param region [Region]
|
66
|
-
# @param pins [Array<Pin::Base>]
|
67
|
-
# @return [Array<Pin::Base>]
|
68
|
-
def self.process node, region = Region.new(nil, '', :instance, :public, []), pins = []
|
69
|
-
pins.push Pin::Namespace.new(region.source.location, '', '', nil, :class, :public) if pins.empty?
|
70
|
-
return pins unless node.is_a?(Parser::AST::Node) #&& @@processors.key?(node.type)
|
71
|
-
klass = @@processors[node.type] || BeginNode
|
72
|
-
processor = klass.new(node, region, pins)
|
73
|
-
processor.process
|
74
|
-
processor.pins
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
1
|
+
module Solargraph
|
2
|
+
class SourceMap
|
3
|
+
# The processor classes used by SourceMap::Mapper to generate pins from
|
4
|
+
# parser nodes.
|
5
|
+
#
|
6
|
+
module NodeProcessor
|
7
|
+
autoload :Base, 'solargraph/source_map/node_processor/base'
|
8
|
+
autoload :BeginNode, 'solargraph/source_map/node_processor/begin_node'
|
9
|
+
autoload :DefNode, 'solargraph/source_map/node_processor/def_node'
|
10
|
+
autoload :DefsNode, 'solargraph/source_map/node_processor/defs_node'
|
11
|
+
autoload :SendNode, 'solargraph/source_map/node_processor/send_node'
|
12
|
+
autoload :NamespaceNode, 'solargraph/source_map/node_processor/namespace_node'
|
13
|
+
autoload :SclassNode, 'solargraph/source_map/node_processor/sclass_node'
|
14
|
+
autoload :ModuleNode, 'solargraph/source_map/node_processor/module_node'
|
15
|
+
autoload :IvasgnNode, 'solargraph/source_map/node_processor/ivasgn_node'
|
16
|
+
autoload :CvasgnNode, 'solargraph/source_map/node_processor/cvasgn_node'
|
17
|
+
autoload :LvasgnNode, 'solargraph/source_map/node_processor/lvasgn_node'
|
18
|
+
autoload :GvasgnNode, 'solargraph/source_map/node_processor/gvasgn_node'
|
19
|
+
autoload :CasgnNode, 'solargraph/source_map/node_processor/casgn_node'
|
20
|
+
autoload :AliasNode, 'solargraph/source_map/node_processor/alias_node'
|
21
|
+
autoload :ArgsNode, 'solargraph/source_map/node_processor/args_node'
|
22
|
+
autoload :BlockNode, 'solargraph/source_map/node_processor/block_node'
|
23
|
+
autoload :OrasgnNode, 'solargraph/source_map/node_processor/orasgn_node'
|
24
|
+
autoload :SymNode, 'solargraph/source_map/node_processor/sym_node'
|
25
|
+
|
26
|
+
class << self
|
27
|
+
@@processors ||= {}
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
# Register a processor for a node type.
|
32
|
+
#
|
33
|
+
# @param type [Symbol]
|
34
|
+
# @param cls [Class<NodeProcessor::Base>]
|
35
|
+
# @return [Class<NodeProcessor::Base>]
|
36
|
+
def register type, cls
|
37
|
+
@@processors[type] = cls
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
register :source, BeginNode
|
42
|
+
register :begin, BeginNode
|
43
|
+
register :kwbegin, BeginNode
|
44
|
+
# # @todo Is this the best way to handle rescue nodes?
|
45
|
+
register :rescue, BeginNode
|
46
|
+
register :resbody, BeginNode
|
47
|
+
register :def, DefNode
|
48
|
+
register :defs, DefsNode
|
49
|
+
register :send, SendNode
|
50
|
+
register :class, NamespaceNode
|
51
|
+
register :module, NamespaceNode
|
52
|
+
register :sclass, SclassNode
|
53
|
+
register :ivasgn, IvasgnNode
|
54
|
+
register :cvasgn, CvasgnNode
|
55
|
+
register :lvasgn, LvasgnNode
|
56
|
+
register :gvasgn, GvasgnNode
|
57
|
+
register :casgn, CasgnNode
|
58
|
+
register :alias, AliasNode
|
59
|
+
register :args, ArgsNode
|
60
|
+
register :block, BlockNode
|
61
|
+
register :or_asgn, OrasgnNode
|
62
|
+
register :sym, SymNode
|
63
|
+
|
64
|
+
# @param node [Parser::AST::Node]
|
65
|
+
# @param region [Region]
|
66
|
+
# @param pins [Array<Pin::Base>]
|
67
|
+
# @return [Array<Pin::Base>]
|
68
|
+
def self.process node, region = Region.new(nil, '', :instance, :public, []), pins = []
|
69
|
+
pins.push Pin::Namespace.new(region.source.location, '', '', nil, :class, :public) if pins.empty?
|
70
|
+
return pins unless node.is_a?(Parser::AST::Node) #&& @@processors.key?(node.type)
|
71
|
+
klass = @@processors[node.type] || BeginNode
|
72
|
+
processor = klass.new(node, region, pins)
|
73
|
+
processor.process
|
74
|
+
processor.pins
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|