@@ -18,7 +18,7 @@ use tower_lsp::lsp_types::*;
1818use tower_lsp:: { Client , LanguageServer , LspService , Server } ;
1919use tree_sitter:: { Parser , Tree } ;
2020
21- use odoo_lsp:: config:: { Config , ModuleConfig , SymbolsConfig } ;
21+ use odoo_lsp:: config:: { Config , ModuleConfig , ReferencesConfig , SymbolsConfig } ;
2222use odoo_lsp:: index:: ModuleIndex ;
2323use odoo_lsp:: model:: ModelLocation ;
2424use odoo_lsp:: utils:: isolate:: Isolate ;
@@ -38,6 +38,7 @@ pub struct Backend {
3838 capabilities : Capabilities ,
3939 root_setup : AtomicBool ,
4040 symbols_limit : AtomicUsize ,
41+ references_limit : AtomicUsize ,
4142 isolate : Isolate ,
4243}
4344
@@ -137,6 +138,7 @@ impl LanguageServer for Backend {
137138 capabilities : _,
138139 root_setup : _,
139140 symbols_limit : _,
141+ references_limit : _,
140142 isolate : _,
141143 } = self ;
142144 document_map. remove ( path) ;
@@ -172,7 +174,7 @@ impl LanguageServer for Backend {
172174 }
173175
174176 for root in self . roots . iter ( ) {
175- match self . module_index . add_root ( & root. as_str ( ) , progress. clone ( ) ) . await {
177+ match self . module_index . add_root ( root. as_str ( ) , progress. clone ( ) ) . await {
176178 Ok ( Some ( results) ) => {
177179 info ! (
178180 "{} | {} modules | {} records | {} models | {:.2}s" ,
@@ -750,17 +752,18 @@ impl Backend {
750752 }
751753 }
752754 fn model_references ( & self , model : & str ) -> miette:: Result < Option < Vec < Location > > > {
753- let mut locations = match self . module_index . models . get ( model) {
754- Some ( entry) => entry. 1 . iter ( ) . map ( |loc| loc. 0 . clone ( ) . into ( ) ) . collect :: < Vec < _ > > ( ) ,
755- None => vec ! [ ] ,
756- } ;
757- locations. extend (
758- self . module_index
759- . records
760- . by_model ( model)
761- . map ( |record| record. location . clone ( ) . into ( ) ) ,
762- ) ;
763- Ok ( Some ( locations) )
755+ let record_locations = self
756+ . module_index
757+ . records
758+ . by_model ( model)
759+ . map ( |record| record. location . clone ( ) . into ( ) ) ;
760+ let limit = self . references_limit . load ( Relaxed ) ;
761+ if let Some ( entry) = self . module_index . models . get ( model) {
762+ let inherit_locations = entry. 1 . iter ( ) . map ( |loc| loc. 0 . clone ( ) . into ( ) ) ;
763+ Ok ( Some ( inherit_locations. chain ( record_locations) . take ( limit) . collect ( ) ) )
764+ } else {
765+ Ok ( Some ( record_locations. take ( limit) . collect ( ) ) )
766+ }
764767 }
765768 fn record_references (
766769 & self ,
@@ -775,17 +778,22 @@ impl Backend {
775778 debug ! ( "No current module to resolve the XML ID {inherit_id}" ) ;
776779 return Ok ( None ) ;
777780 } ;
781+ let limit = self . references_limit . load ( Relaxed ) ;
778782 let locations = self
779783 . module_index
780784 . records
781785 . by_inherit_id ( & inherit_id)
782- . map ( |record| record. location . clone ( ) . into ( ) ) ;
786+ . map ( |record| record. location . clone ( ) . into ( ) )
787+ . take ( limit) ;
783788 Ok ( Some ( locations. collect ( ) ) )
784789 }
785790 async fn on_change_config ( & self , config : Config ) {
786791 if let Some ( SymbolsConfig { limit : Some ( limit) } ) = config. symbols {
787792 self . symbols_limit . store ( limit as usize , Relaxed ) ;
788793 }
794+ if let Some ( ReferencesConfig { limit : Some ( limit) } ) = config. references {
795+ self . references_limit . store ( limit as usize , Relaxed ) ;
796+ }
789797 let Some ( ModuleConfig { roots : Some ( roots) , .. } ) = config. module else {
790798 return ;
791799 } ;
@@ -830,6 +838,7 @@ async fn main() {
830838 root_setup : Default :: default ( ) ,
831839 ast_map : DashMap :: new ( ) ,
832840 symbols_limit : AtomicUsize :: new ( 100 ) ,
841+ references_limit : AtomicUsize :: new ( 100 ) ,
833842 isolate : Isolate :: new ( ) ,
834843 } )
835844 . finish ( ) ;
0 commit comments