Skip to content

Commit 6c2008d

Browse files
mmahroussfda-odoo
authored andcommitted
[IMP} Complete slices to complete incomplete subscripts
1 parent 1e9eff3 commit 6c2008d

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

server/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ clap = { version = "4.5.43", features = ["derive"] }
1616
glob = "0.3.2"
1717
regex = "1.11.1"
1818
ropey = "1.6.1"
19-
ruff_python_ast = { git = "https://github.com/astral-sh/ruff", tag = "0.14.2", version = "0.0.0" }
20-
ruff_python_parser = { git = "https://github.com/astral-sh/ruff", tag = "0.14.2", version = "0.0.0" }
21-
ruff_text_size = { git = "https://github.com/astral-sh/ruff", tag = "0.14.2", version = "0.0.0" }
19+
ruff_python_ast = { git = "https://github.com/astral-sh/ruff", tag = "0.14.3", version = "0.0.0" }
20+
ruff_python_parser = { git = "https://github.com/astral-sh/ruff", tag = "0.14.3", version = "0.0.0" }
21+
ruff_text_size = { git = "https://github.com/astral-sh/ruff", tag = "0.14.3", version = "0.0.0" }
2222
lsp-server = { git = "https://github.com/rust-lang/rust-analyzer", tag = "2025-08-04", version = "0.7.6" }
2323
serde = "1.0.219"
2424
serde_json = "1.0.142"

server/src/features/completion.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use std::collections::{HashMap, HashSet};
33
use std::{cell::RefCell, rc::Rc};
44
use itertools::Itertools;
55
use lsp_types::{CompletionItem, CompletionItemKind, CompletionItemLabelDetails, CompletionList, CompletionResponse, MarkupContent};
6-
use ruff_python_ast::{Decorator, ExceptHandler, Expr, ExprAttribute, ExprIf, ExprName, ExprSubscript, ExprYield, Stmt, StmtGlobal, StmtImport, StmtImportFrom, StmtNonlocal};
6+
use ruff_python_ast::{Decorator, ExceptHandler, Expr, ExprAttribute, ExprIf, ExprName, ExprSlice, ExprSubscript, ExprYield, Stmt, StmtGlobal, StmtImport, StmtImportFrom, StmtNonlocal};
77
use ruff_text_size::{Ranged, TextSize};
88

9-
use crate::constants::{BuildStatus, BuildSteps, OYarn, SymType};
9+
use crate::constants::{OYarn, SymType};
1010
use crate::core::evaluation::{Context, ContextValue, Evaluation, EvaluationSymbol, EvaluationSymbolPtr, EvaluationSymbolWeak};
1111
use crate::core::import_resolver;
1212
use crate::core::odoo::SyncOdoo;
@@ -406,7 +406,7 @@ fn complete_expr(expr: &Expr, session: &mut SessionInfo, file: &Rc<RefCell<Symbo
406406
Expr::Name(expr_name) => complete_name_expression(session, file, expr_name, offset, is_param, expected_type),
407407
Expr::List(expr_list) => complete_list(session, file, expr_list, offset, is_param, expected_type),
408408
Expr::Tuple(expr_tuple) => complete_tuple(session, file, expr_tuple, offset, is_param, expected_type),
409-
Expr::Slice(_) => None,
409+
Expr::Slice(expr_slice) => complete_slice(session, file, expr_slice, offset, is_param, expected_type),
410410
Expr::IpyEscapeCommand(_) => None,
411411
}
412412
}
@@ -945,6 +945,19 @@ pub fn _complete_list_or_tuple(session: &mut SessionInfo, file: &Rc<RefCell<Symb
945945
None
946946
}
947947

948+
fn complete_slice(session: &mut SessionInfo, file: &Rc<RefCell<Symbol>>, expr_slice: &ExprSlice, offset: usize, is_param: bool, expected_type: &Vec<ExpectedType>) -> Option<CompletionResponse> {
949+
// And incomplete subscript is always a slice, so self.env["ffff is a slice with ffff as lower
950+
if expr_slice.lower.is_some() && offset > expr_slice.lower.as_ref().unwrap().range().start().to_usize() && offset <= expr_slice.lower.as_ref().unwrap().range().end().to_usize() {
951+
return complete_expr( expr_slice.lower.as_ref().unwrap(), session, file, offset, is_param, expected_type);
952+
}
953+
if expr_slice.upper.is_some() && offset > expr_slice.upper.as_ref().unwrap().range().start().to_usize() && offset <= expr_slice.upper.as_ref().unwrap().range().end().to_usize() {
954+
return complete_expr( expr_slice.upper.as_ref().unwrap(), session, file, offset, is_param, &vec![]);
955+
}
956+
if expr_slice.step.is_some() && offset > expr_slice.step.as_ref().unwrap().range().start().to_usize() && offset <= expr_slice.step.as_ref().unwrap().range().end().to_usize() {
957+
return complete_expr( expr_slice.step.as_ref().unwrap(), session, file, offset, is_param, &vec![]);
958+
}
959+
None
960+
}
948961
/* *********************************************************************
949962
**************************** Common utils ******************************
950963
********************************************************************** */

0 commit comments

Comments
 (0)