nitlang / nit

Nit language
http://nitlanguage.org
Apache License 2.0
242 stars 67 forks source link

src/indexing: Introduces CodeIndex #2719

Closed Morriar closed 6 years ago

Morriar commented 6 years ago

This PR introduces a new Index based on VSM: CodeIndex, which can be used to retrieve pieces of code from a code query.

Model entities are indexed by their ANode and vectorization is based on model usage such as:

Example:

# Create the index                                         
var index = new CodeIndex(toolcontext)                     
for mentity in mentities do                                
  index.index_mentity(mentity)                             
end                                                        

# Match a piece of code                                    
var matches = index.match_code("print \"Hello, World!\"")  
for match in matches do                                    
  print match                                              
end