Skip to content

Commit

Permalink
feat: request.render
Browse files Browse the repository at this point in the history
  • Loading branch information
Desdaemon committed Aug 29, 2023
1 parent f6cd07c commit b51ac1d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
4 changes: 3 additions & 1 deletion examples/two/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ class Moo(models.Model):
_name = 'moo'
_inherit = ['quux']

what = fields.Many2one(comodel_name='bar')
what = fields.Many2one(comodel_name='bar')
def foo():
request.render('generic_tax_report')
14 changes: 7 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,10 +709,10 @@ impl Backend {
current_module: &str,
items: &mut Vec<CompletionItem>,
) -> miette::Result<()> {
let range = char_range_to_lsp_range(range, rope).ok_or_else(|| diagnostic!("(complete_inherit_id) range"))?;
let range = char_range_to_lsp_range(range, rope).ok_or_else(|| diagnostic!("(complete_xml_id) range"))?;
let by_prefix = self.module_index.records.by_prefix.read().await;
fn to_completion_items(entry: &Record, current_module: &str, range: Range) -> CompletionItem {
let label = if entry.module == current_module {
fn to_completion_items(entry: &Record, current_module: &str, range: Range, scoped: bool) -> CompletionItem {
let label = if entry.module == current_module && !scoped {
entry.id.to_string()
} else {
entry.qualified_id()
Expand All @@ -732,8 +732,8 @@ impl Backend {
let completions = by_prefix.iter_prefix(needle.as_bytes()).flat_map(|(_, keys)| {
keys.iter().flat_map(|key| {
self.module_index.records.get(key.as_str()).and_then(|entry| {
(entry.module == module && entry.model.as_deref() == model_filter)
.then(|| to_completion_items(&entry, current_module, range))
(entry.module == module && (model_filter.is_none() || entry.model.as_deref() == model_filter))
.then(|| to_completion_items(&entry, current_module, range, true))
})
})
});
Expand All @@ -742,8 +742,8 @@ impl Backend {
let completions = by_prefix.iter_prefix(needle.as_bytes()).flat_map(|(_, keys)| {
keys.iter().flat_map(|key| {
self.module_index.records.get(key.as_str()).and_then(|entry| {
(entry.model.as_deref() == model_filter)
.then(|| to_completion_items(&entry, current_module, range))
(model_filter.is_none() || entry.model.as_deref() == model_filter)
.then(|| to_completion_items(&entry, current_module, range, false))
})
})
});
Expand Down
12 changes: 8 additions & 4 deletions src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,12 @@ impl Backend {
cursor.set_byte_range(range.clone());
let mut items = vec![];
'match_: for match_ in cursor.matches(query, ast.root_node(), &bytes[..]) {
let mut model_filter = None;
for capture in match_.captures {
if capture.index == 2 {
// @_request
model_filter = Some("ir.ui.view");
} else if capture.index == 4 {
// @xml_id
let range = capture.node.byte_range();
if range.contains(&offset) {
Expand All @@ -135,14 +139,14 @@ impl Backend {
let needle = Cow::from(slice.byte_slice(1..offset - relative_offset));
// remove the quotes
let range = range.contract(1).map_unit(|unit| CharOffset(rope.byte_to_char(unit)));
self.complete_xml_id(&needle, range, rope.clone(), None, &current_module, &mut items)
self.complete_xml_id(&needle, range, rope.clone(), model_filter, &current_module, &mut items)
.await?;
return Ok(Some(CompletionResponse::List(CompletionList {
is_incomplete: items.len() >= Self::LIMIT,
items,
})));
}
} else if capture.index == 3 {
} else if capture.index == 5 {
// @model
let range = capture.node.byte_range();
if range.contains(&offset) {
Expand Down Expand Up @@ -182,7 +186,7 @@ impl Backend {
cursor.set_byte_range(range);
'match_: for match_ in cursor.matches(query, ast.root_node(), &bytes[..]) {
for capture in match_.captures {
if capture.index == 2 {
if capture.index == 4 {
// @xml_id
let range = capture.node.byte_range();
if range.contains(&offset) {
Expand All @@ -195,7 +199,7 @@ impl Backend {
return self
.jump_def_inherit_id(&slice, &params.text_document_position_params.text_document.uri);
}
} else if capture.index == 3 {
} else if capture.index == 5 {
// @model
let range = capture.node.byte_range();
if range.contains(&offset) {
Expand Down
7 changes: 5 additions & 2 deletions src/queries/py_completions.scm
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
((call
[(attribute (attribute (_) (identifier) @_env) (identifier) @_ref)
(attribute (identifier) @_env (identifier) @_ref)]
(attribute (identifier) @_env (identifier) @_ref)
(attribute (identifier) @_request (identifier) @_render)]
(argument_list . (string) @xml_id))
(#eq? @_env "env")
(#eq? @_ref "ref"))
(#eq? @_ref "ref")
(#eq? @_request "request")
(#eq? @_render "render"))

((subscript
[(identifier) @_env
Expand Down

0 comments on commit b51ac1d

Please sign in to comment.