Skip to content

Commit

Permalink
feat: allow configuring completion limits
Browse files Browse the repository at this point in the history
  • Loading branch information
Desdaemon committed May 2, 2024
1 parent 531e69c commit 8895160
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 11 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 15 additions & 6 deletions src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)]
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -799,6 +807,7 @@ impl Backend {
root_setup: _,
symbols_limit: _,
references_limit: _,
completions_limit: _,
} = self;
let interner = interner();
let symbols_len = interner.len();
Expand Down
3 changes: 2 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 == "-" {
Expand Down
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub struct Config {
pub module: Option<ModuleConfig>,
pub symbols: Option<SymbolsConfig>,
pub references: Option<ReferencesConfig>,
pub completions: Option<CompletionsConfig>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand All @@ -21,3 +22,8 @@ pub struct SymbolsConfig {
pub struct ReferencesConfig {
pub limit: Option<u32>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct CompletionsConfig {
pub limit: Option<u32>,
}
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion src/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8895160

Please sign in to comment.