Class: Jade::CLI::Q::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/jade/cli/q.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Context

jade.json is what says where sources live and which extension gems ship the modules they import. Without it Sql.Uuid resolves against cwd and the load dies.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/jade/cli/q.rb', line 94

def initialize(file)
  project = Jade::Project.find!
  @file = project.source_relative(file)
  @source_root = project.source_root
  @registry = Jade::ModuleLoader.load(
    @source_root, @file,
    cache_dir: project.cache_path,
    tolerant: true,
  )
  @entry = @registry
    .modules
    .each_value
    .find { it.source&.uri == @file } || fail("no module at #{@file}")
end

Instance Attribute Details

#entryObject (readonly)

Returns the value of attribute entry.



89
90
91
# File 'lib/jade/cli/q.rb', line 89

def entry
  @entry
end

#fileObject (readonly)

Returns the value of attribute file.



89
90
91
# File 'lib/jade/cli/q.rb', line 89

def file
  @file
end

#registryObject (readonly)

Returns the value of attribute registry.



89
90
91
# File 'lib/jade/cli/q.rb', line 89

def registry
  @registry
end

#source_rootObject (readonly)

Returns the value of attribute source_root.



89
90
91
# File 'lib/jade/cli/q.rb', line 89

def source_root
  @source_root
end

Instance Method Details

#path_at(line, col) ⇒ Object



109
110
111
112
113
# File 'lib/jade/cli/q.rb', line 109

def path_at(line, col)
  Jade::LSP::Converters
    .position_to_offset(entry.source, line, col)
    .then { entry.ast.find_at_path(it) }
end