1
1
mirror of https://github.com/tweag/nickel.git synced 2024-11-12 23:44:28 +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:
jneem 2023-07-13 17:04:18 +02:00 committed by GitHub
parent 76905f0a58
commit 396d8b384c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 2 deletions

View File

@ -90,7 +90,7 @@ impl<'b> Building<'b> {
TermKind::Record(_) => (),
// unreachable()!: add_usage can only called on let binding, functions and record
// 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::RecordField { ref mut usages, .. } => usages.push(usage),
};

View File

@ -21,7 +21,7 @@ impl ResolutionState for Resolved {}
/// 3. Records, listing their fields
/// 4. wildcard (Structure) for any other kind of term.
/// Can be extended later to represent Contracts, Records, etc.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq)]
pub enum TermKind {
Declaration {
id: Ident,
@ -43,6 +43,7 @@ pub enum TermKind {
usages: Vec<ItemId>,
value: ValueState,
},
Types(Types),
Structure,
}

View File

@ -493,6 +493,16 @@ impl<'a> Linearizer for AnalysisHost<'a> {
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 => {
debug!("Add wildcard item: {:?}", other);

View File

@ -186,6 +186,7 @@ fn find_fields_from_term_kind(
TermKind::Usage(UsageState::Resolved(new_id)) => {
find_fields_from_term_kind(new_id, path, info)
}
TermKind::Types(ref ty) => find_fields_from_type(ty, path, info),
_ => Vec::new(),
};
result.into_iter().chain(contract_result).collect()

View 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 = "." }

View File

@ -0,0 +1,7 @@
---
source: lsp/nls/tests/main.rs
expression: output
---
[foo]
[foo]