@@ -2,24 +2,27 @@ use std::{fmt::Display, ops::Deref, sync::Arc};
22
33use dashmap:: DashMap ;
44use intmap:: IntMap ;
5- use lasso:: { Key , Spur } ;
5+ use lasso:: Spur ;
66use qp_trie:: { wrapper:: BString , Trie } ;
77use tokio:: sync:: RwLock ;
88use tower_lsp:: lsp_types:: Range ;
99
10- use crate :: { utils:: MinLoc , ImStr } ;
10+ use crate :: {
11+ utils:: { ByteOffset , MinLoc } ,
12+ ImStr ,
13+ } ;
1114
1215#[ derive( Clone , Debug ) ]
1316pub struct Model {
1417 pub model : ModelId ,
1518 pub range : Range ,
16- pub fields : Vec < ( Spur , Field ) > ,
19+ pub byte_range : std :: ops :: Range < ByteOffset > ,
1720}
1821
1922#[ derive( Clone , Debug ) ]
2023pub enum ModelId {
2124 Base ( ImStr ) ,
22- Inherit { inherits : Vec < ImStr > , has_primary : bool } ,
25+ Inherit ( Vec < ImStr > ) ,
2326}
2427
2528#[ derive( Default , Clone ) ]
@@ -32,7 +35,7 @@ pub struct ModelIndex {
3235pub struct ModelEntry {
3336 pub base : Option < ModelLocation > ,
3437 pub descendants : Vec < ModelLocation > ,
35- pub fields : IntMap < Field > ,
38+ pub fields : Option < IntMap < Field > > ,
3639}
3740
3841#[ derive( Clone , Debug ) ]
@@ -42,7 +45,7 @@ pub enum Field {
4245}
4346
4447#[ derive( Clone ) ]
45- pub struct ModelLocation ( pub MinLoc ) ;
48+ pub struct ModelLocation ( pub MinLoc , pub std :: ops :: Range < ByteOffset > ) ;
4649
4750impl Display for ModelLocation {
4851 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
@@ -85,27 +88,23 @@ impl ModelIndex {
8588 ModelId :: Base ( base) => {
8689 by_prefix. insert_str ( & base, base. clone ( ) ) ;
8790 let mut entry = self . entry ( base. clone ( ) ) . or_default ( ) ;
88- entry. base = Some ( ModelLocation ( MinLoc {
89- path : path. clone ( ) ,
90- range : item. range ,
91- } ) ) ;
92- for ( field, type_) in item. fields {
93- entry. fields . insert ( field. into_usize ( ) as u64 , type_) ;
94- }
95- }
96- ModelId :: Inherit { inherits, has_primary } => {
97- if has_primary {
98- let primary = & inherits[ 0 ] ;
99- let mut entry = self . entry ( primary. clone ( ) ) . or_default ( ) ;
100- for ( field, type_) in item. fields {
101- entry. fields . insert ( field. into_usize ( ) as u64 , type_) ;
102- }
103- }
104- for inherit in inherits {
105- self . entry ( inherit) . or_default ( ) . descendants . push ( ModelLocation ( MinLoc {
91+ entry. base = Some ( ModelLocation (
92+ MinLoc {
10693 path : path. clone ( ) ,
10794 range : item. range ,
108- } ) ) ;
95+ } ,
96+ item. byte_range ,
97+ ) ) ;
98+ }
99+ ModelId :: Inherit ( inherits) => {
100+ for inherit in inherits {
101+ self . entry ( inherit) . or_default ( ) . descendants . push ( ModelLocation (
102+ MinLoc {
103+ path : path. clone ( ) ,
104+ range : item. range ,
105+ } ,
106+ item. byte_range . clone ( ) ,
107+ ) ) ;
109108 }
110109 }
111110 }
0 commit comments