diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 09c4e97fa9..5a0bd0c192 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -23,7 +23,7 @@ use crate::{ adt::VariantDef, db::{AstDatabase, DefDatabase, HirDatabase}, expr::{validation::ExprValidator, BindingAnnotation, Body, BodySourceMap, Pat, PatId}, - generics::HasGenericParams, + generics::{GenericDef, HasGenericParams}, ids::{ AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId, TypeAliasId, @@ -1121,3 +1121,9 @@ impl Local { src.map(|ast| ast.map(|it| it.cast().unwrap().to_node(&root), |it| it.to_node(&root))) } } + +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub struct GenericParam { + pub(crate) parent: GenericDef, + pub(crate) idx: u32, +} diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 806f1daed1..92d71b9e88 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -39,7 +39,7 @@ mod ty; mod impl_block; mod expr; mod lang_item; -mod generics; +pub mod generics; mod resolve; pub mod diagnostics; mod util; @@ -65,12 +65,12 @@ pub use crate::{ docs::{DocDef, Docs, Documentation}, src::{HasBodySource, HasSource}, Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, - EnumVariant, FieldSource, FnData, Function, HasBody, Local, MacroDef, Module, ModuleDef, - ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, + EnumVariant, FieldSource, FnData, Function, GenericParam, HasBody, Local, MacroDef, Module, + ModuleDef, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, }, expr::ExprScopes, from_source::FromSource, - generics::{GenericDef, GenericParam, GenericParams, HasGenericParams}, + generics::GenericDef, ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile}, impl_block::ImplBlock, resolve::ScopeDef, diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index c5fdf3bab8..fe4211819e 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -28,8 +28,8 @@ use crate::{ ids::LocationCtx, resolve::{ScopeDef, TypeNs, ValueNs}, ty::method_resolution::{self, implements_trait}, - AssocItem, Const, DefWithBody, Either, Enum, FromSource, Function, HasBody, HirFileId, Local, - MacroDef, Module, Name, Path, Resolver, Static, Struct, Ty, + AssocItem, Const, DefWithBody, Either, Enum, FromSource, Function, GenericParam, HasBody, + HirFileId, Local, MacroDef, Module, Name, Path, Resolver, Static, Struct, Ty, }; fn try_get_resolver_for_node( @@ -107,7 +107,7 @@ pub enum PathResolution { /// A local binding (only value namespace) Local(Local), /// A generic parameter - GenericParam(u32), + GenericParam(GenericParam), SelfType(crate::ImplBlock), Macro(MacroDef), AssocItem(crate::AssocItem), @@ -227,7 +227,10 @@ impl SourceAnalyzer { ) -> Option { let types = self.resolver.resolve_path_in_type_ns_fully(db, &path).map(|ty| match ty { TypeNs::SelfType(it) => PathResolution::SelfType(it), - TypeNs::GenericParam(it) => PathResolution::GenericParam(it), + TypeNs::GenericParam(idx) => PathResolution::GenericParam(GenericParam { + parent: self.resolver.generic_def().unwrap(), + idx, + }), TypeNs::AdtSelfType(it) | TypeNs::Adt(it) => PathResolution::Def(it.into()), TypeNs::EnumVariant(it) => PathResolution::Def(it.into()), TypeNs::TypeAlias(it) => PathResolution::Def(it.into()), diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index cd2ac0e8bd..6f24cfad60 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -17,8 +17,11 @@ use std::sync::Arc; use std::{fmt, iter, mem}; use crate::{ - db::HirDatabase, expr::ExprId, util::make_mut_slice, Adt, Crate, DefWithBody, GenericParams, - HasGenericParams, Mutability, Name, Trait, TypeAlias, + db::HirDatabase, + expr::ExprId, + generics::{GenericParams, HasGenericParams}, + util::make_mut_slice, + Adt, Crate, DefWithBody, Mutability, Name, Trait, TypeAlias, }; use display::{HirDisplay, HirFormatter}; @@ -342,10 +345,7 @@ impl Substs { ) } - pub fn build_for_def( - db: &impl HirDatabase, - def: impl crate::HasGenericParams, - ) -> SubstsBuilder { + pub fn build_for_def(db: &impl HirDatabase, def: impl HasGenericParams) -> SubstsBuilder { let params = def.generic_params(db); let param_count = params.count_params_including_parent(); Substs::builder(param_count) diff --git a/crates/ra_hir/src/ty/autoderef.rs b/crates/ra_hir/src/ty/autoderef.rs index 3645ee831c..872a4517d1 100644 --- a/crates/ra_hir/src/ty/autoderef.rs +++ b/crates/ra_hir/src/ty/autoderef.rs @@ -9,7 +9,7 @@ use hir_expand::name; use log::{info, warn}; use super::{traits::Solution, Canonical, Substs, Ty, TypeWalk}; -use crate::{db::HirDatabase, HasGenericParams, Resolver}; +use crate::{db::HirDatabase, generics::HasGenericParams, Resolver}; const AUTODEREF_RECURSION_LIMIT: usize = 10; diff --git a/crates/ra_hir/src/ty/infer/path.rs b/crates/ra_hir/src/ty/infer/path.rs index 865ced5a13..31ca675aac 100644 --- a/crates/ra_hir/src/ty/infer/path.rs +++ b/crates/ra_hir/src/ty/infer/path.rs @@ -5,9 +5,10 @@ use hir_def::path::PathSegment; use super::{ExprOrPatId, InferenceContext, TraitRef}; use crate::{ db::HirDatabase, + generics::HasGenericParams, resolve::{ResolveValueResult, Resolver, TypeNs, ValueNs}, ty::{method_resolution, Namespace, Substs, Ty, TypableDef, TypeWalk}, - AssocItem, Container, HasGenericParams, Name, Path, + AssocItem, Container, Name, Path, }; impl<'a, D: HirDatabase> InferenceContext<'a, D> { diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index c694952f3c..14c54b9fb4 100644 --- a/crates/ra_hir/src/ty/traits/chalk.rs +++ b/crates/ra_hir/src/ty/traits/chalk.rs @@ -16,13 +16,13 @@ use ra_db::salsa::{InternId, InternKey}; use super::{Canonical, ChalkContext, Impl, Obligation}; use crate::{ db::HirDatabase, - generics::GenericDef, + generics::{GenericDef, HasGenericParams}, ty::display::HirDisplay, ty::{ ApplicationTy, GenericPredicate, Namespace, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, }, - AssocItem, Crate, HasGenericParams, ImplBlock, Trait, TypeAlias, + AssocItem, Crate, ImplBlock, Trait, TypeAlias, }; /// This represents a trait whose name we could not resolve. diff --git a/crates/ra_ide_api/src/references/name_definition.rs b/crates/ra_ide_api/src/references/name_definition.rs index 450f7ea9b6..ccd75278ae 100644 --- a/crates/ra_ide_api/src/references/name_definition.rs +++ b/crates/ra_ide_api/src/references/name_definition.rs @@ -4,7 +4,8 @@ //! Note that the reference search is possible for not all of the classified items. use hir::{ - Adt, AssocItem, HasSource, Local, MacroDef, Module, ModuleDef, StructField, Ty, VariantDef, + Adt, AssocItem, GenericParam, HasSource, Local, MacroDef, Module, ModuleDef, StructField, Ty, + VariantDef, }; use ra_syntax::{ast, ast::VisibilityOwner}; @@ -18,7 +19,7 @@ pub enum NameKind { Def(ModuleDef), SelfType(Ty), Local(Local), - GenericParam(u32), + GenericParam(GenericParam), } #[derive(PartialEq, Eq)] diff --git a/xtask/src/main.rs b/xtask/src/main.rs index e04e45f157..16bddfb281 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -179,7 +179,7 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> { Cmd { unix: r"npm ci", windows: r"cmd.exe /c npm.cmd ci", work_dir: "./editors/code" }.run()?; Cmd { - unix: r"npm run package", + unix: r"npm run package --scripts-prepend-node-path", windows: r"cmd.exe /c npm.cmd run package", work_dir: "./editors/code", }