mirror of
https://github.com/tweag/nickel.git
synced 2024-10-06 16:18:08 +03:00
Use the Types AST variant for completion (#1450)
* Use the Types AST variant for completion * Add missing snapshot
This commit is contained in:
parent
76905f0a58
commit
396d8b384c
@ -90,7 +90,7 @@ impl<'b> Building<'b> {
|
|||||||
TermKind::Record(_) => (),
|
TermKind::Record(_) => (),
|
||||||
// unreachable()!: add_usage can only called on let binding, functions and record
|
// unreachable()!: add_usage can only called on let binding, functions and record
|
||||||
// fields, only referring to items which support usages.
|
// fields, only referring to items which support usages.
|
||||||
TermKind::Structure | TermKind::Usage(_) => unreachable!(),
|
TermKind::Types(_) | TermKind::Structure | TermKind::Usage(_) => unreachable!(),
|
||||||
TermKind::Declaration { ref mut usages, .. }
|
TermKind::Declaration { ref mut usages, .. }
|
||||||
| TermKind::RecordField { ref mut usages, .. } => usages.push(usage),
|
| TermKind::RecordField { ref mut usages, .. } => usages.push(usage),
|
||||||
};
|
};
|
||||||
|
@ -21,7 +21,7 @@ impl ResolutionState for Resolved {}
|
|||||||
/// 3. Records, listing their fields
|
/// 3. Records, listing their fields
|
||||||
/// 4. wildcard (Structure) for any other kind of term.
|
/// 4. wildcard (Structure) for any other kind of term.
|
||||||
/// Can be extended later to represent Contracts, Records, etc.
|
/// Can be extended later to represent Contracts, Records, etc.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum TermKind {
|
pub enum TermKind {
|
||||||
Declaration {
|
Declaration {
|
||||||
id: Ident,
|
id: Ident,
|
||||||
@ -43,6 +43,7 @@ pub enum TermKind {
|
|||||||
usages: Vec<ItemId>,
|
usages: Vec<ItemId>,
|
||||||
value: ValueState,
|
value: ValueState,
|
||||||
},
|
},
|
||||||
|
Types(Types),
|
||||||
Structure,
|
Structure,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -493,6 +493,16 @@ impl<'a> Linearizer for AnalysisHost<'a> {
|
|||||||
metadata: self.meta.take(),
|
metadata: self.meta.take(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Term::Types(t) => {
|
||||||
|
lin.push(LinearizationItem {
|
||||||
|
env: self.env.clone(),
|
||||||
|
id,
|
||||||
|
pos,
|
||||||
|
ty,
|
||||||
|
kind: TermKind::Types(t.clone()),
|
||||||
|
metadata: self.meta.take(),
|
||||||
|
});
|
||||||
|
}
|
||||||
other => {
|
other => {
|
||||||
debug!("Add wildcard item: {:?}", other);
|
debug!("Add wildcard item: {:?}", other);
|
||||||
|
|
||||||
|
@ -186,6 +186,7 @@ fn find_fields_from_term_kind(
|
|||||||
TermKind::Usage(UsageState::Resolved(new_id)) => {
|
TermKind::Usage(UsageState::Resolved(new_id)) => {
|
||||||
find_fields_from_term_kind(new_id, path, info)
|
find_fields_from_term_kind(new_id, path, info)
|
||||||
}
|
}
|
||||||
|
TermKind::Types(ref ty) => find_fields_from_type(ty, path, info),
|
||||||
_ => Vec::new(),
|
_ => Vec::new(),
|
||||||
};
|
};
|
||||||
result.into_iter().chain(contract_result).collect()
|
result.into_iter().chain(contract_result).collect()
|
||||||
|
17
lsp/nls/tests/inputs/completion-dict.ncl
Normal file
17
lsp/nls/tests/inputs/completion-dict.ncl
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
### /input-inline.ncl
|
||||||
|
let x | { _ : { foo : Number | default = 1 } } = {} in
|
||||||
|
x.PATH.
|
||||||
|
### /input-assign.ncl
|
||||||
|
let Dict = { _ : { foo : Number | default = 1 } } in
|
||||||
|
let x | Dict = {} in
|
||||||
|
x.PATH.
|
||||||
|
### [[request]]
|
||||||
|
### type = "Completion"
|
||||||
|
### textDocument.uri = "file:///input-inline.ncl"
|
||||||
|
### position = { line = 1, character = 7 }
|
||||||
|
### context = { triggerKind = 2, triggerCharacter = "." }
|
||||||
|
### [[request]]
|
||||||
|
### type = "Completion"
|
||||||
|
### textDocument.uri = "file:///input-assign.ncl"
|
||||||
|
### position = { line = 2, character = 7 }
|
||||||
|
### context = { triggerKind = 2, triggerCharacter = "." }
|
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
source: lsp/nls/tests/main.rs
|
||||||
|
expression: output
|
||||||
|
---
|
||||||
|
[foo]
|
||||||
|
[foo]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user