Class: Solargraph::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/solargraph/mapper.rb

Instance Method Summary collapse

Constructor Details

#initializeMapper

Returns a new instance of Mapper.



3
4
5
6
7
8
9
# File 'lib/solargraph/mapper.rb', line 3

def initialize
  @default_api_map = Solargraph::ApiMap.new
  stub = Parser::CurrentRuby.parse(Solargraph::LiveParser.parse(nil))
  @default_api_map.merge(stub)
  @default_api_map.freeze
  @require_nodes = {}
end

Instance Method Details

#find_workspace(filename) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/solargraph/mapper.rb', line 16

def find_workspace filename
  dirname = filename
  lastname = nil
  result = nil
  until dirname == lastname
    if File.file?("#{dirname}/Gemfile")
      result = dirname
      break
    end
    lastname = dirname
    dirname = File.dirname(dirname)
  end
  result || File.dirname(filename)
end

#get(filename, text) ⇒ Object



11
12
13
14
# File 'lib/solargraph/mapper.rb', line 11

def get filename, text
  workspace = find_workspace(filename)
  CodeMap.new(text, api_map: @default_api_map, workspace: workspace, require_nodes: @require_nodes)
end