diff --git a/package.json b/package.json index 3db664e..7ee355c 100644 --- a/package.json +++ b/package.json @@ -124,6 +124,11 @@ "default": 80, "description": "Maximum amount of model/record references to retrieve at once." }, + "odoo-lsp.completions.limit": { + "type": "number", + "default": 200, + "description": "Maximum amount of completions to retrieve at once." + }, "odoo-lsp.module.roots": { "type": "array", "scope": "resource", diff --git a/src/backend.rs b/src/backend.rs index 07e27fe..02817e9 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -21,7 +21,7 @@ use tower_lsp::lsp_types::*; use tower_lsp::Client; use tree_sitter::{Parser, Tree}; -use odoo_lsp::config::{Config, ModuleConfig, ReferencesConfig, SymbolsConfig}; +use odoo_lsp::config::{CompletionsConfig, Config, ModuleConfig, ReferencesConfig, SymbolsConfig}; use odoo_lsp::index::{interner, Component, Index, Interner, ModuleName, RecordId, Symbol, SymbolSet}; use odoo_lsp::model::{Field, FieldKind, ModelEntry, ModelLocation, ModelName}; use odoo_lsp::record::Record; @@ -38,6 +38,7 @@ pub struct Backend { pub root_setup: CondVar, pub symbols_limit: AtomicUsize, pub references_limit: AtomicUsize, + pub completions_limit: AtomicUsize, } #[derive(Debug, Default)] @@ -87,8 +88,6 @@ impl Document { } impl Backend { - pub const LIMIT: usize = 80; - /// Maximum number of descendants to show in docstring. const INHERITS_LIMIT: usize = 3; @@ -752,13 +751,22 @@ impl Backend { } } pub async fn on_change_config(&self, config: Config) { - if let Some(SymbolsConfig { limit: Some(limit) }) = config.symbols { + let Config { + symbols, + references, + module, + completions, + } = config; + if let Some(SymbolsConfig { limit: Some(limit) }) = symbols { self.symbols_limit.store(limit as usize, Relaxed); } - if let Some(ReferencesConfig { limit: Some(limit) }) = config.references { + if let Some(ReferencesConfig { limit: Some(limit) }) = references { self.references_limit.store(limit as usize, Relaxed); } - let Some(ModuleConfig { roots: Some(roots), .. }) = config.module else { + if let Some(CompletionsConfig { limit: Some(limit) }) = completions { + self.completions_limit.store(limit as usize, Relaxed); + } + let Some(ModuleConfig { roots: Some(roots), .. }) = module else { return; }; if !roots.is_empty() { @@ -799,6 +807,7 @@ impl Backend { root_setup: _, symbols_limit: _, references_limit: _, + completions_limit: _, } = self; let interner = interner(); let symbols_len = interner.len(); diff --git a/src/cli.rs b/src/cli.rs index 32bb184..8c2f2e7 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -3,7 +3,7 @@ use std::{env::current_dir, fs::canonicalize, io::stdout, path::Path, process::e use globwalk::FileType; use log::{debug, warn}; use miette::{diagnostic, IntoDiagnostic}; -use odoo_lsp::config::{Config, ModuleConfig, ReferencesConfig, SymbolsConfig}; +use odoo_lsp::config::{CompletionsConfig, Config, ModuleConfig, ReferencesConfig, SymbolsConfig}; use odoo_lsp::index::{interner, Index}; use self_update::{backends::github, Status}; use serde_json::Value; @@ -294,6 +294,7 @@ pub fn init(addons_path: &[&str], output: Option<&str>) -> miette::Result<()> { }), symbols: Some(SymbolsConfig { limit: Some(80) }), references: Some(ReferencesConfig { limit: Some(80) }), + completions: Some(CompletionsConfig { limit: Some(200) }), }; let output = output.unwrap_or(".odoo_lsp"); if output == "-" { diff --git a/src/config.rs b/src/config.rs index 109e4cc..f45ed3c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -5,6 +5,7 @@ pub struct Config { pub module: Option, pub symbols: Option, pub references: Option, + pub completions: Option, } #[derive(Serialize, Deserialize, Debug, Clone)] @@ -21,3 +22,8 @@ pub struct SymbolsConfig { pub struct ReferencesConfig { pub limit: Option, } + +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct CompletionsConfig { + pub limit: Option, +} diff --git a/src/main.rs b/src/main.rs index 9d58537..16e0bab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -210,6 +210,7 @@ impl LanguageServer for Backend { root_setup: _, symbols_limit: _, references_limit: _, + completions_limit: _, } = self; document_map.remove(path); record_ranges.remove(path); @@ -782,8 +783,9 @@ async fn main() { capabilities: Default::default(), root_setup: Default::default(), ast_map: DashMap::new(), - symbols_limit: AtomicUsize::new(100), - references_limit: AtomicUsize::new(100), + symbols_limit: AtomicUsize::new(80), + references_limit: AtomicUsize::new(80), + completions_limit: AtomicUsize::new(200), }) .custom_method("odoo-lsp/statistics", Backend::statistics) .custom_method("odoo-lsp/debug/usage", |_: &Backend| async move { diff --git a/src/python.rs b/src/python.rs index b48a70d..ea2291c 100644 --- a/src/python.rs +++ b/src/python.rs @@ -5,6 +5,7 @@ use std::borrow::Cow; use std::cmp::Ordering; use std::ops::ControlFlow; use std::path::Path; +use std::sync::atomic::Ordering::Relaxed; use lasso::Spur; use log::{debug, trace, warn}; @@ -218,7 +219,7 @@ impl Backend { let contents = Cow::from(rope.clone()); let contents = contents.as_bytes(); let query = PyCompletions::query(); - let mut items = MaxVec::new(Self::LIMIT); + let mut items = MaxVec::new(self.completions_limit.load(Relaxed)); let mut early_return = None; let mut this_model = ThisModel::default(); // FIXME: This hack is necessary to drop !Send locals before await points. diff --git a/src/xml.rs b/src/xml.rs index 0880e86..f71d145 100644 --- a/src/xml.rs +++ b/src/xml.rs @@ -4,6 +4,7 @@ use crate::{Backend, Text}; use std::borrow::Cow; use std::cmp::Ordering; use std::path::Path; +use std::sync::atomic::Ordering::Relaxed; use std::sync::Arc; use lasso::Spur; @@ -205,7 +206,7 @@ impl Backend { .module_of_path(Path::new(uri.path())) .expect("must be in a module"); - let mut items = MaxVec::new(Self::LIMIT); + let mut items = MaxVec::new(self.completions_limit.load(Relaxed)); let XmlRefs { ref_at_cursor, ref_kind,