From b28a8d22436ac251ba4af5212747171421362b1e Mon Sep 17 00:00:00 2001 From: OmarTawfik <15987992+OmarTawfik@users.noreply.github.com> Date: Wed, 11 Dec 2024 08:02:19 -0800 Subject: [PATCH] -- --- .../cargo/wasm/src/runtime/config.json.jinja2 | 5 + .../wasm/src/runtime/generated/config.json | 5 + .../codegen_runtime_cargo_wasm.component.d.ts | 2 + .../nomic-foundation-slang-bindings.d.ts | 103 ++++++++++++++++++ .../nomic-foundation-slang-compilation.d.ts | 10 ++ .../bindings/generated/public_api.txt | 14 ++- .../cargo/crate/generated/public_api.txt | 3 + .../wasm/src/generated/generated/config.json | 5 + .../nomic-foundation-slang-bindings.d.ts | 103 ++++++++++++++++++ .../nomic-foundation-slang-compilation.d.ts | 10 ++ .../solidity_cargo_wasm.component.d.ts | 2 + .../wasm/src/generated/generated/config.json | 5 + .../nomic-foundation-slang-bindings.d.ts | 103 ++++++++++++++++++ .../nomic-foundation-slang-compilation.d.ts | 10 ++ .../testlang_cargo_wasm.component.d.ts | 2 + 15 files changed, 381 insertions(+), 1 deletion(-) create mode 100644 crates/codegen/runtime/npm/package/wasm/generated/interfaces/nomic-foundation-slang-bindings.d.ts create mode 100644 crates/solidity/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-bindings.d.ts create mode 100644 crates/testlang/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-bindings.d.ts diff --git a/crates/codegen/runtime/cargo/wasm/src/runtime/config.json.jinja2 b/crates/codegen/runtime/cargo/wasm/src/runtime/config.json.jinja2 index 1684a63653..3444eb9169 100644 --- a/crates/codegen/runtime/cargo/wasm/src/runtime/config.json.jinja2 +++ b/crates/codegen/runtime/cargo/wasm/src/runtime/config.json.jinja2 @@ -45,6 +45,11 @@ "as_getter": true } }, + "nomic-foundation:slang:compilation:compilation-unit.binding-graph()": { + "Function": { + "as_getter": true + } + }, "nomic-foundation:slang:compilation:file.id()": { "Function": { "as_getter": true diff --git a/crates/codegen/runtime/cargo/wasm/src/runtime/generated/config.json b/crates/codegen/runtime/cargo/wasm/src/runtime/generated/config.json index 1684a63653..3444eb9169 100644 --- a/crates/codegen/runtime/cargo/wasm/src/runtime/generated/config.json +++ b/crates/codegen/runtime/cargo/wasm/src/runtime/generated/config.json @@ -45,6 +45,11 @@ "as_getter": true } }, + "nomic-foundation:slang:compilation:compilation-unit.binding-graph()": { + "Function": { + "as_getter": true + } + }, "nomic-foundation:slang:compilation:file.id()": { "Function": { "as_getter": true diff --git a/crates/codegen/runtime/npm/package/wasm/generated/codegen_runtime_cargo_wasm.component.d.ts b/crates/codegen/runtime/npm/package/wasm/generated/codegen_runtime_cargo_wasm.component.d.ts index 20e0276643..959f0ad174 100644 --- a/crates/codegen/runtime/npm/package/wasm/generated/codegen_runtime_cargo_wasm.component.d.ts +++ b/crates/codegen/runtime/npm/package/wasm/generated/codegen_runtime_cargo_wasm.component.d.ts @@ -2,11 +2,13 @@ import { NomicFoundationSlangCst } from "./interfaces/nomic-foundation-slang-cst.js"; import { NomicFoundationSlangAst } from "./interfaces/nomic-foundation-slang-ast.js"; +import { NomicFoundationSlangBindings } from "./interfaces/nomic-foundation-slang-bindings.js"; import { NomicFoundationSlangCompilation } from "./interfaces/nomic-foundation-slang-compilation.js"; import { NomicFoundationSlangParser } from "./interfaces/nomic-foundation-slang-parser.js"; import { NomicFoundationSlangUtils } from "./interfaces/nomic-foundation-slang-utils.js"; export * as cst from "./interfaces/nomic-foundation-slang-cst.js"; export * as ast from "./interfaces/nomic-foundation-slang-ast.js"; +export * as bindings from "./interfaces/nomic-foundation-slang-bindings.js"; export * as compilation from "./interfaces/nomic-foundation-slang-compilation.js"; export * as parser from "./interfaces/nomic-foundation-slang-parser.js"; export * as utils from "./interfaces/nomic-foundation-slang-utils.js"; diff --git a/crates/codegen/runtime/npm/package/wasm/generated/interfaces/nomic-foundation-slang-bindings.d.ts b/crates/codegen/runtime/npm/package/wasm/generated/interfaces/nomic-foundation-slang-bindings.d.ts new file mode 100644 index 0000000000..5cd83321f3 --- /dev/null +++ b/crates/codegen/runtime/npm/package/wasm/generated/interfaces/nomic-foundation-slang-bindings.d.ts @@ -0,0 +1,103 @@ +// This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +export namespace NomicFoundationSlangBindings { + export { BindingGraph }; + export { Definition }; + export { Reference }; + export { UserFileLocation }; + export { BuiltInLocation }; + export { BindingLocation }; + export { BindingLocationVariant }; +} +import type { Cursor } from "./nomic-foundation-slang-cst.js"; +export { Cursor }; +/** + * Represents a location of a symbol (definition or reference) in the binding graph. + * It can either be in a user file, or a built-in in the language. + */ +export type BindingLocation = UserFileLocation | BuiltInLocation; +export enum BindingLocationVariant { + UserFileLocation = "UserFileLocation", + BuiltInLocation = "BuiltInLocation", +} + +export class BindingGraph { + /** + * If the provided cursor points at a definition `Identifier`, it will return the + * corresponding definition. Otherwise, it will return `undefined`. + */ + definitionAt(cursor: Cursor): Definition | undefined; + /** + * If the provided cursor points at a reference `Identifier`, it will return the + * corresponding reference. Otherwise, it will return `undefined`. + */ + referenceAt(cursor: Cursor): Reference | undefined; +} + +export class BuiltInLocation { + readonly bindingLocationVariant = BindingLocationVariant.BuiltInLocation; + + asBuiltInLocation(): this; + isBuiltInLocation(): this is BuiltInLocation; + + asUserFileLocation(): undefined; + isUserFileLocation(): false; +} + +export class Definition { + /** + * Returns a unique numerical identifier of the definition. + * It is only valid for the lifetime of the binding graph. + * It can change between multiple graphs, even for the same source code input. + */ + get id(): number; + /** + * Returns the location of the definition's name. + * For `contract X {}`, that is the location of the `X` `Identifier` node. + */ + get nameLocation(): BindingLocation; + /** + * Returns the location of the definition's definiens. + * For `contract X {}`, that is the location of the parent `ContractDefinition` node. + */ + get definiensLocation(): BindingLocation; +} + +export class Reference { + /** + * Returns a unique numerical identifier of the reference. + * It is only valid for the lifetime of the binding graph. + * It can change between multiple graphs, even for the same source code input. + */ + get id(): number; + /** + * Returns the location of the reference. + * For `new X()`, that is the location of the `X` `Identifier` node. + */ + get location(): BindingLocation; + /** + * Returns a list of all definitions related to this reference. + * Most references have a single definition, but some have multiple, such as when a symbol + * is imported from another file, and renamed (re-defined) in the current file. + */ + definitions(): Definition[]; +} + +export class UserFileLocation { + readonly bindingLocationVariant = BindingLocationVariant.UserFileLocation; + + asUserFileLocation(): this; + isUserFileLocation(): this is UserFileLocation; + + asBuiltInLocation(): undefined; + isBuiltInLocation(): false; + + /** + * Returns the ID of the file that contains the symbol. + */ + get fileId(): string; + /** + * Returns a cursor to the CST node that contains the symbol. + */ + get cursor(): Cursor; +} diff --git a/crates/codegen/runtime/npm/package/wasm/generated/interfaces/nomic-foundation-slang-compilation.d.ts b/crates/codegen/runtime/npm/package/wasm/generated/interfaces/nomic-foundation-slang-compilation.d.ts index d7b56a37e8..1032798ff4 100644 --- a/crates/codegen/runtime/npm/package/wasm/generated/interfaces/nomic-foundation-slang-compilation.d.ts +++ b/crates/codegen/runtime/npm/package/wasm/generated/interfaces/nomic-foundation-slang-compilation.d.ts @@ -5,6 +5,8 @@ export namespace NomicFoundationSlangCompilation { export { CompilationUnit }; export { File }; } +import type { BindingGraph } from "./nomic-foundation-slang-bindings.js"; +export { BindingGraph }; import type { Node } from "./nomic-foundation-slang-cst.js"; export { Node }; import type { Cursor } from "./nomic-foundation-slang-cst.js"; @@ -32,6 +34,14 @@ export class CompilationUnit { * Returns the file with the specified ID, if it exists. */ file(id: string): File | undefined; + /** + * Calculates name binding information for all source files within the compilation unit. + * Returns a graph that contains all found definitions and their references. + * + * Note: building this graph is an expensive operation. + * It is done lazily on the first access, and cached thereafter. + */ + get bindingGraph(): BindingGraph; } export class File { diff --git a/crates/metaslang/bindings/generated/public_api.txt b/crates/metaslang/bindings/generated/public_api.txt index 47a055df61..0e7a4e3bb8 100644 --- a/crates/metaslang/bindings/generated/public_api.txt +++ b/crates/metaslang/bindings/generated/public_api.txt @@ -7,6 +7,10 @@ pub metaslang_bindings::BindingLocation::UserFile(metaslang_bindings::UserFileLo impl metaslang_bindings::BindingLocation pub fn metaslang_bindings::BindingLocation::built_in() -> Self pub fn metaslang_bindings::BindingLocation::user_file(file_id: alloc::string::String, cursor: metaslang_cst::cursor::Cursor) -> Self +impl core::clone::Clone for metaslang_bindings::BindingLocation +pub fn metaslang_bindings::BindingLocation::clone(&self) -> metaslang_bindings::BindingLocation +impl core::fmt::Debug for metaslang_bindings::BindingLocation +pub fn metaslang_bindings::BindingLocation::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result pub enum metaslang_bindings::FileDescriptor pub metaslang_bindings::FileDescriptor::System(alloc::string::String) pub metaslang_bindings::FileDescriptor::User(alloc::string::String) @@ -32,6 +36,10 @@ pub fn metaslang_bindings::BindingGraph::lookup_definition_by_name(&self, na pub fn metaslang_bindings::BindingGraph::reference_at(&self, cursor: &metaslang_cst::cursor::Cursor) -> core::option::Option> pub fn metaslang_bindings::BindingGraph::set_context(&mut self, context: &metaslang_bindings::DefinitionHandle) pub struct metaslang_bindings::BuiltInLocation +impl core::clone::Clone for metaslang_bindings::BuiltInLocation +pub fn metaslang_bindings::BuiltInLocation::clone(&self) -> metaslang_bindings::BuiltInLocation +impl core::fmt::Debug for metaslang_bindings::BuiltInLocation +pub fn metaslang_bindings::BuiltInLocation::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result pub struct metaslang_bindings::Definition<'a, KT: metaslang_cst::kinds::KindTypes + 'static> impl<'a, KT: metaslang_cst::kinds::KindTypes + 'static> metaslang_bindings::Definition<'a, KT> pub fn metaslang_bindings::Definition<'a, KT>::definiens_location(&self) -> metaslang_bindings::BindingLocation @@ -39,7 +47,7 @@ pub fn metaslang_bindings::Definition<'a, KT>::get_cursor(&self) -> &metaslang_c pub fn metaslang_bindings::Definition<'a, KT>::get_definiens_cursor(&self) -> &metaslang_cst::cursor::Cursor pub fn metaslang_bindings::Definition<'a, KT>::get_file(&self) -> metaslang_bindings::FileDescriptor pub fn metaslang_bindings::Definition<'a, KT>::id(&self) -> usize -pub fn metaslang_bindings::Definition<'a, KT>::location(&self) -> metaslang_bindings::BindingLocation +pub fn metaslang_bindings::Definition<'a, KT>::name_location(&self) -> metaslang_bindings::BindingLocation pub fn metaslang_bindings::Definition<'a, KT>::to_handle(self) -> metaslang_bindings::DefinitionHandle impl<'a, KT: core::clone::Clone + metaslang_cst::kinds::KindTypes + 'static> core::clone::Clone for metaslang_bindings::Definition<'a, KT> pub fn metaslang_bindings::Definition<'a, KT>::clone(&self) -> metaslang_bindings::Definition<'a, KT> @@ -71,5 +79,9 @@ pub struct metaslang_bindings::UserFileLocation metaslang_bindings::UserFileLocation pub fn metaslang_bindings::UserFileLocation::cursor(&self) -> &metaslang_cst::cursor::Cursor pub fn metaslang_bindings::UserFileLocation::file_id(&self) -> &str +impl core::clone::Clone for metaslang_bindings::UserFileLocation +pub fn metaslang_bindings::UserFileLocation::clone(&self) -> metaslang_bindings::UserFileLocation +impl core::fmt::Debug for metaslang_bindings::UserFileLocation +pub fn metaslang_bindings::UserFileLocation::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result pub trait metaslang_bindings::PathResolver pub fn metaslang_bindings::PathResolver::resolve_path(&self, context_path: &str, path_to_resolve: &metaslang_cst::cursor::Cursor) -> core::option::Option diff --git a/crates/solidity/outputs/cargo/crate/generated/public_api.txt b/crates/solidity/outputs/cargo/crate/generated/public_api.txt index ef0cf06a96..f6c4d9a400 100644 --- a/crates/solidity/outputs/cargo/crate/generated/public_api.txt +++ b/crates/solidity/outputs/cargo/crate/generated/public_api.txt @@ -2,13 +2,16 @@ pub mod slang_solidity pub mod slang_solidity::bindings +pub use slang_solidity::bindings::BuiltInLocation pub use slang_solidity::bindings::PathResolver pub fn slang_solidity::bindings::create_with_resolver(version: semver::Version, resolver: alloc::rc::Rc>) -> slang_solidity::bindings::BindingGraph pub fn slang_solidity::bindings::get_binding_rules() -> &'static str pub fn slang_solidity::bindings::get_built_ins(version: &semver::Version) -> &'static str pub type slang_solidity::bindings::BindingGraph = metaslang_bindings::BindingGraph +pub type slang_solidity::bindings::BindingLocation = metaslang_bindings::location::BindingLocation pub type slang_solidity::bindings::Definition<'a> = metaslang_bindings::Definition<'a, slang_solidity::cst::KindTypes> pub type slang_solidity::bindings::Reference<'a> = metaslang_bindings::Reference<'a, slang_solidity::cst::KindTypes> +pub type slang_solidity::bindings::UserFileLocation = metaslang_bindings::location::UserFileLocation pub mod slang_solidity::compilation pub struct slang_solidity::compilation::AddFileResponse pub slang_solidity::compilation::AddFileResponse::import_paths: alloc::vec::Vec diff --git a/crates/solidity/outputs/cargo/wasm/src/generated/generated/config.json b/crates/solidity/outputs/cargo/wasm/src/generated/generated/config.json index 1684a63653..3444eb9169 100644 --- a/crates/solidity/outputs/cargo/wasm/src/generated/generated/config.json +++ b/crates/solidity/outputs/cargo/wasm/src/generated/generated/config.json @@ -45,6 +45,11 @@ "as_getter": true } }, + "nomic-foundation:slang:compilation:compilation-unit.binding-graph()": { + "Function": { + "as_getter": true + } + }, "nomic-foundation:slang:compilation:file.id()": { "Function": { "as_getter": true diff --git a/crates/solidity/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-bindings.d.ts b/crates/solidity/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-bindings.d.ts new file mode 100644 index 0000000000..5cd83321f3 --- /dev/null +++ b/crates/solidity/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-bindings.d.ts @@ -0,0 +1,103 @@ +// This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +export namespace NomicFoundationSlangBindings { + export { BindingGraph }; + export { Definition }; + export { Reference }; + export { UserFileLocation }; + export { BuiltInLocation }; + export { BindingLocation }; + export { BindingLocationVariant }; +} +import type { Cursor } from "./nomic-foundation-slang-cst.js"; +export { Cursor }; +/** + * Represents a location of a symbol (definition or reference) in the binding graph. + * It can either be in a user file, or a built-in in the language. + */ +export type BindingLocation = UserFileLocation | BuiltInLocation; +export enum BindingLocationVariant { + UserFileLocation = "UserFileLocation", + BuiltInLocation = "BuiltInLocation", +} + +export class BindingGraph { + /** + * If the provided cursor points at a definition `Identifier`, it will return the + * corresponding definition. Otherwise, it will return `undefined`. + */ + definitionAt(cursor: Cursor): Definition | undefined; + /** + * If the provided cursor points at a reference `Identifier`, it will return the + * corresponding reference. Otherwise, it will return `undefined`. + */ + referenceAt(cursor: Cursor): Reference | undefined; +} + +export class BuiltInLocation { + readonly bindingLocationVariant = BindingLocationVariant.BuiltInLocation; + + asBuiltInLocation(): this; + isBuiltInLocation(): this is BuiltInLocation; + + asUserFileLocation(): undefined; + isUserFileLocation(): false; +} + +export class Definition { + /** + * Returns a unique numerical identifier of the definition. + * It is only valid for the lifetime of the binding graph. + * It can change between multiple graphs, even for the same source code input. + */ + get id(): number; + /** + * Returns the location of the definition's name. + * For `contract X {}`, that is the location of the `X` `Identifier` node. + */ + get nameLocation(): BindingLocation; + /** + * Returns the location of the definition's definiens. + * For `contract X {}`, that is the location of the parent `ContractDefinition` node. + */ + get definiensLocation(): BindingLocation; +} + +export class Reference { + /** + * Returns a unique numerical identifier of the reference. + * It is only valid for the lifetime of the binding graph. + * It can change between multiple graphs, even for the same source code input. + */ + get id(): number; + /** + * Returns the location of the reference. + * For `new X()`, that is the location of the `X` `Identifier` node. + */ + get location(): BindingLocation; + /** + * Returns a list of all definitions related to this reference. + * Most references have a single definition, but some have multiple, such as when a symbol + * is imported from another file, and renamed (re-defined) in the current file. + */ + definitions(): Definition[]; +} + +export class UserFileLocation { + readonly bindingLocationVariant = BindingLocationVariant.UserFileLocation; + + asUserFileLocation(): this; + isUserFileLocation(): this is UserFileLocation; + + asBuiltInLocation(): undefined; + isBuiltInLocation(): false; + + /** + * Returns the ID of the file that contains the symbol. + */ + get fileId(): string; + /** + * Returns a cursor to the CST node that contains the symbol. + */ + get cursor(): Cursor; +} diff --git a/crates/solidity/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-compilation.d.ts b/crates/solidity/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-compilation.d.ts index d7b56a37e8..1032798ff4 100644 --- a/crates/solidity/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-compilation.d.ts +++ b/crates/solidity/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-compilation.d.ts @@ -5,6 +5,8 @@ export namespace NomicFoundationSlangCompilation { export { CompilationUnit }; export { File }; } +import type { BindingGraph } from "./nomic-foundation-slang-bindings.js"; +export { BindingGraph }; import type { Node } from "./nomic-foundation-slang-cst.js"; export { Node }; import type { Cursor } from "./nomic-foundation-slang-cst.js"; @@ -32,6 +34,14 @@ export class CompilationUnit { * Returns the file with the specified ID, if it exists. */ file(id: string): File | undefined; + /** + * Calculates name binding information for all source files within the compilation unit. + * Returns a graph that contains all found definitions and their references. + * + * Note: building this graph is an expensive operation. + * It is done lazily on the first access, and cached thereafter. + */ + get bindingGraph(): BindingGraph; } export class File { diff --git a/crates/solidity/outputs/npm/package/wasm/generated/solidity_cargo_wasm.component.d.ts b/crates/solidity/outputs/npm/package/wasm/generated/solidity_cargo_wasm.component.d.ts index 20e0276643..959f0ad174 100644 --- a/crates/solidity/outputs/npm/package/wasm/generated/solidity_cargo_wasm.component.d.ts +++ b/crates/solidity/outputs/npm/package/wasm/generated/solidity_cargo_wasm.component.d.ts @@ -2,11 +2,13 @@ import { NomicFoundationSlangCst } from "./interfaces/nomic-foundation-slang-cst.js"; import { NomicFoundationSlangAst } from "./interfaces/nomic-foundation-slang-ast.js"; +import { NomicFoundationSlangBindings } from "./interfaces/nomic-foundation-slang-bindings.js"; import { NomicFoundationSlangCompilation } from "./interfaces/nomic-foundation-slang-compilation.js"; import { NomicFoundationSlangParser } from "./interfaces/nomic-foundation-slang-parser.js"; import { NomicFoundationSlangUtils } from "./interfaces/nomic-foundation-slang-utils.js"; export * as cst from "./interfaces/nomic-foundation-slang-cst.js"; export * as ast from "./interfaces/nomic-foundation-slang-ast.js"; +export * as bindings from "./interfaces/nomic-foundation-slang-bindings.js"; export * as compilation from "./interfaces/nomic-foundation-slang-compilation.js"; export * as parser from "./interfaces/nomic-foundation-slang-parser.js"; export * as utils from "./interfaces/nomic-foundation-slang-utils.js"; diff --git a/crates/testlang/outputs/cargo/wasm/src/generated/generated/config.json b/crates/testlang/outputs/cargo/wasm/src/generated/generated/config.json index 1684a63653..3444eb9169 100644 --- a/crates/testlang/outputs/cargo/wasm/src/generated/generated/config.json +++ b/crates/testlang/outputs/cargo/wasm/src/generated/generated/config.json @@ -45,6 +45,11 @@ "as_getter": true } }, + "nomic-foundation:slang:compilation:compilation-unit.binding-graph()": { + "Function": { + "as_getter": true + } + }, "nomic-foundation:slang:compilation:file.id()": { "Function": { "as_getter": true diff --git a/crates/testlang/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-bindings.d.ts b/crates/testlang/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-bindings.d.ts new file mode 100644 index 0000000000..5cd83321f3 --- /dev/null +++ b/crates/testlang/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-bindings.d.ts @@ -0,0 +1,103 @@ +// This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +export namespace NomicFoundationSlangBindings { + export { BindingGraph }; + export { Definition }; + export { Reference }; + export { UserFileLocation }; + export { BuiltInLocation }; + export { BindingLocation }; + export { BindingLocationVariant }; +} +import type { Cursor } from "./nomic-foundation-slang-cst.js"; +export { Cursor }; +/** + * Represents a location of a symbol (definition or reference) in the binding graph. + * It can either be in a user file, or a built-in in the language. + */ +export type BindingLocation = UserFileLocation | BuiltInLocation; +export enum BindingLocationVariant { + UserFileLocation = "UserFileLocation", + BuiltInLocation = "BuiltInLocation", +} + +export class BindingGraph { + /** + * If the provided cursor points at a definition `Identifier`, it will return the + * corresponding definition. Otherwise, it will return `undefined`. + */ + definitionAt(cursor: Cursor): Definition | undefined; + /** + * If the provided cursor points at a reference `Identifier`, it will return the + * corresponding reference. Otherwise, it will return `undefined`. + */ + referenceAt(cursor: Cursor): Reference | undefined; +} + +export class BuiltInLocation { + readonly bindingLocationVariant = BindingLocationVariant.BuiltInLocation; + + asBuiltInLocation(): this; + isBuiltInLocation(): this is BuiltInLocation; + + asUserFileLocation(): undefined; + isUserFileLocation(): false; +} + +export class Definition { + /** + * Returns a unique numerical identifier of the definition. + * It is only valid for the lifetime of the binding graph. + * It can change between multiple graphs, even for the same source code input. + */ + get id(): number; + /** + * Returns the location of the definition's name. + * For `contract X {}`, that is the location of the `X` `Identifier` node. + */ + get nameLocation(): BindingLocation; + /** + * Returns the location of the definition's definiens. + * For `contract X {}`, that is the location of the parent `ContractDefinition` node. + */ + get definiensLocation(): BindingLocation; +} + +export class Reference { + /** + * Returns a unique numerical identifier of the reference. + * It is only valid for the lifetime of the binding graph. + * It can change between multiple graphs, even for the same source code input. + */ + get id(): number; + /** + * Returns the location of the reference. + * For `new X()`, that is the location of the `X` `Identifier` node. + */ + get location(): BindingLocation; + /** + * Returns a list of all definitions related to this reference. + * Most references have a single definition, but some have multiple, such as when a symbol + * is imported from another file, and renamed (re-defined) in the current file. + */ + definitions(): Definition[]; +} + +export class UserFileLocation { + readonly bindingLocationVariant = BindingLocationVariant.UserFileLocation; + + asUserFileLocation(): this; + isUserFileLocation(): this is UserFileLocation; + + asBuiltInLocation(): undefined; + isBuiltInLocation(): false; + + /** + * Returns the ID of the file that contains the symbol. + */ + get fileId(): string; + /** + * Returns a cursor to the CST node that contains the symbol. + */ + get cursor(): Cursor; +} diff --git a/crates/testlang/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-compilation.d.ts b/crates/testlang/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-compilation.d.ts index d7b56a37e8..1032798ff4 100644 --- a/crates/testlang/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-compilation.d.ts +++ b/crates/testlang/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-compilation.d.ts @@ -5,6 +5,8 @@ export namespace NomicFoundationSlangCompilation { export { CompilationUnit }; export { File }; } +import type { BindingGraph } from "./nomic-foundation-slang-bindings.js"; +export { BindingGraph }; import type { Node } from "./nomic-foundation-slang-cst.js"; export { Node }; import type { Cursor } from "./nomic-foundation-slang-cst.js"; @@ -32,6 +34,14 @@ export class CompilationUnit { * Returns the file with the specified ID, if it exists. */ file(id: string): File | undefined; + /** + * Calculates name binding information for all source files within the compilation unit. + * Returns a graph that contains all found definitions and their references. + * + * Note: building this graph is an expensive operation. + * It is done lazily on the first access, and cached thereafter. + */ + get bindingGraph(): BindingGraph; } export class File { diff --git a/crates/testlang/outputs/npm/package/wasm/generated/testlang_cargo_wasm.component.d.ts b/crates/testlang/outputs/npm/package/wasm/generated/testlang_cargo_wasm.component.d.ts index 20e0276643..959f0ad174 100644 --- a/crates/testlang/outputs/npm/package/wasm/generated/testlang_cargo_wasm.component.d.ts +++ b/crates/testlang/outputs/npm/package/wasm/generated/testlang_cargo_wasm.component.d.ts @@ -2,11 +2,13 @@ import { NomicFoundationSlangCst } from "./interfaces/nomic-foundation-slang-cst.js"; import { NomicFoundationSlangAst } from "./interfaces/nomic-foundation-slang-ast.js"; +import { NomicFoundationSlangBindings } from "./interfaces/nomic-foundation-slang-bindings.js"; import { NomicFoundationSlangCompilation } from "./interfaces/nomic-foundation-slang-compilation.js"; import { NomicFoundationSlangParser } from "./interfaces/nomic-foundation-slang-parser.js"; import { NomicFoundationSlangUtils } from "./interfaces/nomic-foundation-slang-utils.js"; export * as cst from "./interfaces/nomic-foundation-slang-cst.js"; export * as ast from "./interfaces/nomic-foundation-slang-ast.js"; +export * as bindings from "./interfaces/nomic-foundation-slang-bindings.js"; export * as compilation from "./interfaces/nomic-foundation-slang-compilation.js"; export * as parser from "./interfaces/nomic-foundation-slang-parser.js"; export * as utils from "./interfaces/nomic-foundation-slang-utils.js";