find_definition
5ad7cbblibraryNo description provided.
No license · updated 3 months ago
A compile-time find-definition tool for Jai projects. It hooks into your
existing build.jai to accurately locate where a symbol is declared, using
the compiler's own type-checked AST to resolve references.
---------
Hey oh no, this looks awfully complicated just to find a definition... Well we
have to hook into the compilation because we're not going to just make our own
thing that does some section of the compilation when that's already done for us.
Maybe when the jai compiler is self-hosted we can simplify this though.
---------
integration:
1. Copy the modules/find_definition/ directory into your project's modules/
folder (or anywhere accessible).
2. Add two things to your build.jai:
a. #import the module at the top level:
#import "find_definition";
b. Add three lines inside your #run block:
#run {
// ... your existing setup ...
is_finding_def := find_def_parse_args(); // (1)
// After setting build options, before set_build_options():
if is_finding_def options.output_type = .NO_OUTPUT;
// ... set_build_options, compiler_begin_intercept, add_build_file ...
// inside your message loop:
while true {
message := compiler_wait_for_message();
if message.kind == .ERROR exit(1);
if is_finding_def find_def_handle_message(message); // (2)
if message.kind == .COMPLETE break;
}
// after the message loop:
if is_finding_def find_def_finish(); // (3)
};
The reason we intrude into your build.jai file is because we have to compile
the code, if it were a plugin then it wouldn't have access to the inner loop
or something (it didn't work as a plugin I forget exactly why), and it can't
be its own standalone program because it needs to build your project, and only
your build.jai file knows how to do that, so we have to intrude.
---------
Usage:
Find a Definition:
jai build.jai - -find_def <file>@<line>:<col>
Compiles your project, finds the symbol at the given location, and prints
the file, line, and column where that symbol is declared.
Not using it:
jai build.jai
When -find_def is not on the command line, the tool is completely
inactive. Your build works exactly as before.
---------
arguments:
<file>@<line>:<col> Location of the symbol to look up. Line and column
are 1-based. The file path is relative to your
working directory.
---------
example:
# find where a symbol is declared
jai build.jai - -find_def src/main.jai@42:10