Skip to content

Commit

Permalink
Use the Types AST variant for completion (#1450)
Browse files Browse the repository at this point in the history
* Use the Types AST variant for completion

* Add missing snapshot
  • Loading branch information
jneem authored Jul 13, 2023
1 parent 76905f0 commit 396d8b3
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lsp/nls/src/linearization/building.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
Expand Down
3 changes: 2 additions & 1 deletion lsp/nls/src/linearization/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -43,6 +43,7 @@ pub enum TermKind {
usages: Vec<ItemId>,
value: ValueState,
},
Types(Types),
Structure,
}

Expand Down
10 changes: 10 additions & 0 deletions lsp/nls/src/linearization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions lsp/nls/src/requests/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
17 changes: 17 additions & 0 deletions lsp/nls/tests/inputs/completion-dict.ncl
Original file line number Diff line number Diff line change
@@ -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 = "." }
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: lsp/nls/tests/main.rs
expression: output
---
[foo]
[foo]

0 comments on commit 396d8b3

Please sign in to comment.