This PR implements "go to definition" and "go to declaration" functionality for name nodes only. Future PRs will add support for attributes, module names in import statements, keyword argument names, etc. This PR: * Registers a declaration and definition request handler for the language server. * Splits out the `goto_type_definition` into its own module. The `goto` module contains functionality that is common to `goto_type_definition`, `goto_declaration` and `goto_definition`. * Roughs in a new module `stub_mapping` that is not yet implemented. It will be responsible for mapping a definition in a stub file to its corresponding definition(s) in an implementation (source) file. * Adds a new IDE support function `definitions_for_name` that collects all of the definitions associated with a name and resolves any imports (recursively) to find the original definitions associated with that name. * Adds a new `VisibleAncestorsIter` stuct that iterates up the scope hierarchy but skips scopes that are not visible to starting scope. --------- Co-authored-by: UnboundVariable <unbound@gmail.com>
68 lines
2.1 KiB
Rust
68 lines
2.1 KiB
Rust
use std::hash::BuildHasherDefault;
|
|
|
|
use rustc_hash::FxHasher;
|
|
|
|
use crate::lint::{LintRegistry, LintRegistryBuilder};
|
|
use crate::suppression::{INVALID_IGNORE_COMMENT, UNKNOWN_RULE, UNUSED_IGNORE_COMMENT};
|
|
pub use db::Db;
|
|
pub use module_name::ModuleName;
|
|
pub use module_resolver::{
|
|
KnownModule, Module, SearchPathValidationError, SearchPaths, resolve_module,
|
|
system_module_search_paths,
|
|
};
|
|
pub use program::{
|
|
Program, ProgramSettings, PythonVersionFileSource, PythonVersionSource,
|
|
PythonVersionWithSource, SearchPathSettings,
|
|
};
|
|
pub use python_platform::PythonPlatform;
|
|
pub use semantic_model::{Completion, CompletionKind, HasType, NameKind, SemanticModel};
|
|
pub use site_packages::{PythonEnvironment, SitePackagesPaths, SysPrefixPathOrigin};
|
|
pub use types::definitions_for_name;
|
|
pub use types::ide_support::ResolvedDefinition;
|
|
pub use util::diagnostics::add_inferred_python_version_hint_to_diagnostic;
|
|
|
|
pub mod ast_node_ref;
|
|
mod db;
|
|
mod dunder_all;
|
|
pub mod lint;
|
|
pub(crate) mod list;
|
|
mod module_name;
|
|
mod module_resolver;
|
|
mod node_key;
|
|
pub(crate) mod place;
|
|
mod program;
|
|
mod python_platform;
|
|
pub mod semantic_index;
|
|
mod semantic_model;
|
|
pub(crate) mod site_packages;
|
|
mod suppression;
|
|
pub mod types;
|
|
mod unpack;
|
|
mod util;
|
|
|
|
#[cfg(feature = "testing")]
|
|
pub mod pull_types;
|
|
|
|
type FxOrderSet<V> = ordermap::set::OrderSet<V, BuildHasherDefault<FxHasher>>;
|
|
type FxIndexMap<K, V> = indexmap::IndexMap<K, V, BuildHasherDefault<FxHasher>>;
|
|
type FxIndexSet<V> = indexmap::IndexSet<V, BuildHasherDefault<FxHasher>>;
|
|
|
|
/// Returns the default registry with all known semantic lints.
|
|
pub fn default_lint_registry() -> &'static LintRegistry {
|
|
static REGISTRY: std::sync::LazyLock<LintRegistry> = std::sync::LazyLock::new(|| {
|
|
let mut registry = LintRegistryBuilder::default();
|
|
register_lints(&mut registry);
|
|
registry.build()
|
|
});
|
|
|
|
®ISTRY
|
|
}
|
|
|
|
/// Register all known semantic lints.
|
|
pub fn register_lints(registry: &mut LintRegistryBuilder) {
|
|
types::register_lints(registry);
|
|
registry.register_lint(&UNUSED_IGNORE_COMMENT);
|
|
registry.register_lint(&UNKNOWN_RULE);
|
|
registry.register_lint(&INVALID_IGNORE_COMMENT);
|
|
}
|