@@ -31,7 +31,7 @@ def initialize(model)
3131 @graph = Saturn ::Graph . new #: Saturn::Graph
3232 @definitions = { } #: Hash[String, Array[Definition]]
3333 @references = { } #: Hash[String, Array[Model::Reference]]
34- @ignored = Set . new #: Set[Model::SymbolDef ]
34+ @ignored = Set . new #: Set[String ]
3535 end
3636
3737 # Indexing
@@ -103,26 +103,26 @@ def reference_method(name, location)
103103 ( @references [ name ] ||= [ ] ) << Model ::Reference . method ( name , location )
104104 end
105105
106- #: (Model::SymbolDef symbol_def ) -> void
107- def ignore ( symbol_def )
108- @ignored << symbol_def
106+ #: (Saturn::Definition definition ) -> void
107+ def ignore ( definition )
108+ @ignored << definition . name
109109 end
110110
111111 #: (Array[Plugins::Base] plugins) -> void
112112 def apply_plugins! ( plugins )
113- @model . symbols . each do |_full_name , symbol |
114- symbol . definitions . each do |symbol_def |
115- case symbol_def
116- when Model :: Class
117- plugins . each { |plugin | plugin . internal_on_define_class ( symbol_def ) }
118- when Model :: Module
119- plugins . each { |plugin | plugin . internal_on_define_module ( symbol_def ) }
120- when Model :: Constant
121- plugins . each { |plugin | plugin . internal_on_define_constant ( symbol_def ) }
122- when Model :: Method
123- plugins . each { |plugin | plugin . internal_on_define_method ( symbol_def ) }
124- when Model :: Attr
125- plugins . each { |plugin | plugin . internal_on_define_accessor ( symbol_def ) }
113+ @graph . declarations . each do |declaration |
114+ declaration . definitions . each do |definition |
115+ case definition
116+ when Saturn :: ClassDefinition
117+ plugins . each { |plugin | plugin . internal_on_define_class ( definition ) }
118+ when Saturn :: ModuleDefinition
119+ plugins . each { |plugin | plugin . internal_on_define_module ( definition ) }
120+ when Saturn :: ConstantDefinition
121+ plugins . each { |plugin | plugin . internal_on_define_constant ( definition ) }
122+ when Saturn :: MethodDefinition
123+ plugins . each { |plugin | plugin . internal_on_define_method ( definition ) }
124+ when Saturn :: AttrAccessorDefinition , Saturn :: AttrReaderDefinition , Saturn :: AttrWriterDefinition
125+ plugins . each { |plugin | plugin . internal_on_define_accessor ( definition ) }
126126 end
127127 end
128128 end
@@ -133,112 +133,113 @@ def apply_plugins!(plugins)
133133 # To be called once all the files have been indexed and all the definitions and references discovered.
134134 #: -> void
135135 def finalize!
136+ @graph . unresolved_references . each do |ref |
137+ case ref
138+ when Saturn ::UnresolvedConstantReference
139+ reference_constant (
140+ ref . name . split ( "::" ) . last ,
141+ saturn_location_to_spoom_location ( ref . location ) ,
142+ )
143+ when Saturn ::UnresolvedMethodReference
144+ reference_method (
145+ ref . name ,
146+ saturn_location_to_spoom_location ( ref . location ) ,
147+ )
148+ end
149+ end
150+
136151 @graph . declarations . each do |declaration |
137152 declaration . definitions . each do |definition |
138153 case definition
139154 when Saturn ::ClassDefinition
155+ name = definition . name
140156 d = Definition . new (
141157 kind : Definition ::Kind ::Class ,
142- name : declaration_name ( declaration . name ) ,
158+ name : name ,
143159 full_name : declaration . name ,
144160 location : saturn_location_to_spoom_location ( definition . location ) ,
145161 )
146- d . ignored! if @ignored . include? ( definition )
147- d . alive! if @references . key? ( d . name )
162+ d . ignored! if @ignored . include? ( name )
163+ d . alive! if @references . key? ( name )
148164 define ( d )
149165 when Saturn ::ModuleDefinition
166+ name = definition . name
150167 d = Definition . new (
151168 kind : Definition ::Kind ::Module ,
152- name : declaration_name ( declaration . name ) ,
169+ name : name ,
153170 full_name : declaration . name ,
154171 location : saturn_location_to_spoom_location ( definition . location ) ,
155172 )
156- d . ignored! if @ignored . include? ( definition )
157- d . alive! if @references . key? ( d . name )
173+ d . ignored! if @ignored . include? ( name )
174+ d . alive! if @references . key? ( name )
158175 define ( d )
159176 when Saturn ::ConstantDefinition
177+ name = definition . name
160178 d = Definition . new (
161179 kind : Definition ::Kind ::Constant ,
162- name : declaration_name ( declaration . name ) ,
180+ name : name ,
163181 full_name : declaration . name ,
164182 location : saturn_location_to_spoom_location ( definition . location ) ,
165183 )
166- d . ignored! if @ignored . include? ( definition )
167- d . alive! if @references . key? ( d . name )
184+ d . ignored! if @ignored . include? ( name )
185+ d . alive! if @references . key? ( name )
168186 define ( d )
169187 when Saturn ::MethodDefinition
188+ name = definition . name
170189 d = Definition . new (
171190 kind : Definition ::Kind ::Method ,
172- name : declaration_name ( declaration . name ) ,
191+ name : name ,
173192 full_name : declaration . name ,
174193 location : saturn_location_to_spoom_location ( definition . location ) ,
175194 )
176- d . ignored! if @ignored . include? ( definition )
177- d . alive! if @references . key? ( d . name )
195+ d . ignored! if @ignored . include? ( name )
196+ d . alive! if @references . key? ( name )
178197 define ( d )
179198 when Saturn ::AttrAccessorDefinition
180- d = if declaration . name . end_with? ( "=" )
199+ name = definition . name
200+ d = if name . end_with? ( "=" )
181201 Definition . new (
182202 kind : Definition ::Kind ::AttrWriter ,
183- name : declaration_name ( declaration . name ) ,
203+ name : name ,
184204 full_name : declaration . name ,
185205 location : saturn_location_to_spoom_location ( definition . location ) ,
186206 )
187207 else
188208 Definition . new (
189209 kind : Definition ::Kind ::AttrReader ,
190- name : declaration_name ( declaration . name ) ,
210+ name : name ,
191211 full_name : declaration . name ,
192212 location : saturn_location_to_spoom_location ( definition . location ) ,
193213 )
194214 end
195- d . ignored! if @ignored . include? ( definition )
196- d . alive! if @references . key? ( d . name )
215+ d . ignored! if @ignored . include? ( name )
216+ d . alive! if @references . key? ( name )
197217 define ( d )
198218 when Saturn ::AttrReaderDefinition
219+ name = definition . name
199220 d = Definition . new (
200221 kind : Definition ::Kind ::AttrReader ,
201- name : declaration_name ( declaration . name ) ,
222+ name : name ,
202223 full_name : declaration . name ,
203224 location : saturn_location_to_spoom_location ( definition . location ) ,
204225 )
205- d . ignored! if @ignored . include? ( definition )
206- d . alive! if @references . key? ( d . name )
226+ d . ignored! if @ignored . include? ( name )
227+ d . alive! if @references . key? ( name )
207228 define ( d )
208229 when Saturn ::AttrWriterDefinition
230+ name = definition . name
209231 d = Definition . new (
210232 kind : Definition ::Kind ::AttrWriter ,
211- name : declaration_name ( declaration . name ) ,
233+ name : name ,
212234 full_name : declaration . name ,
213235 location : saturn_location_to_spoom_location ( definition . location ) ,
214236 )
215- d . ignored! if @ignored . include? ( definition )
216- d . alive! if @references . key? ( d . name )
237+ d . ignored! if @ignored . include? ( name )
238+ d . alive! if @references . key? ( name )
217239 define ( d )
218240 end
219241 end
220242 end
221-
222- @graph . unresolved_references . each do |ref |
223- case ref
224- when Saturn ::UnresolvedConstantReference
225- reference_constant (
226- declaration_name ( ref . name ) ,
227- saturn_location_to_spoom_location ( ref . location ) ,
228- )
229- when Saturn ::UnresolvedMethodReference
230- reference_method (
231- ref . name ,
232- saturn_location_to_spoom_location ( ref . location ) ,
233- )
234- end
235- end
236- end
237-
238- # TODO
239- #: (String name) -> String
240- def declaration_name ( name )
241- name . split ( /(::|#)/ ) . last #: as !nil
242243 end
243244
244245 #: (Saturn::Location location) -> Location
@@ -247,8 +248,8 @@ def saturn_location_to_spoom_location(location)
247248 location . path ,
248249 start_line : location . start_line ,
249250 end_line : location . end_line ,
250- start_column : location . start_column ,
251- end_column : location . end_column ,
251+ start_column : location . start_column - 1 ,
252+ end_column : location . end_column - 1 ,
252253 )
253254 end
254255
0 commit comments