Skip to content

Commit ca02823

Browse files
feat(completions): show data type for columns
1 parent 7ffbca6 commit ca02823

File tree

10 files changed

+15
-1
lines changed

10 files changed

+15
-1
lines changed

crates/pgt_completions/src/builder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub(crate) struct PossibleCompletionItem<'a> {
1212
pub score: CompletionScore<'a>,
1313
pub filter: CompletionFilter<'a>,
1414
pub completion_text: Option<CompletionText>,
15+
pub detail: Option<String>,
1516
}
1617

1718
pub(crate) struct CompletionBuilder<'a> {
@@ -70,6 +71,7 @@ impl<'a> CompletionBuilder<'a> {
7071
kind: item.kind,
7172
label: item.label,
7273
preselected,
74+
detail: item.detail,
7375

7476
// wonderous Rust syntax ftw
7577
sort_text: format!("{:0>padding$}", idx, padding = max_padding),

crates/pgt_completions/src/item.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pub struct CompletionItem {
5252
pub kind: CompletionItemKind,
5353
/// String used for sorting by LSP clients.
5454
pub sort_text: String,
55+
pub detail: Option<String>,
5556

5657
pub completion_text: Option<CompletionText>,
5758
}

crates/pgt_completions/src/providers/columns.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub fn complete_columns<'a>(ctx: &CompletionContext<'a>, builder: &mut Completio
2020
description: format!("Table: {}.{}", col.schema_name, col.table_name),
2121
kind: CompletionItemKind::Column,
2222
completion_text: None,
23+
detail: Some(format!("{}", col.type_name)),
2324
};
2425

2526
// autocomplete with the alias in a join clause if we find one

crates/pgt_completions/src/providers/functions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub fn complete_functions<'a>(ctx: &'a CompletionContext, builder: &mut Completi
1919
filter: CompletionFilter::from(relevance),
2020
description: format!("Schema: {}", func.schema),
2121
kind: CompletionItemKind::Function,
22+
detail: None,
2223
completion_text: get_completion_text_with_schema_or_alias(
2324
ctx,
2425
&func.name,

crates/pgt_completions/src/providers/policies.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub fn complete_policies<'a>(ctx: &CompletionContext<'a>, builder: &mut Completi
4848
description: pol.table_name.to_string(),
4949
kind: CompletionItemKind::Policy,
5050
completion_text,
51+
detail: None,
5152
};
5253

5354
builder.add_item(item);

crates/pgt_completions/src/providers/schemas.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub fn complete_schemas<'a>(ctx: &'a CompletionContext, builder: &mut Completion
1616
kind: crate::CompletionItemKind::Schema,
1717
score: CompletionScore::from(relevance.clone()),
1818
filter: CompletionFilter::from(relevance),
19+
detail: None,
1920
completion_text: None,
2021
};
2122

crates/pgt_completions/src/providers/tables.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub fn complete_tables<'a>(ctx: &'a CompletionContext, builder: &mut CompletionB
1919
filter: CompletionFilter::from(relevance),
2020
description: format!("Schema: {}", table.schema),
2121
kind: CompletionItemKind::Table,
22+
detail: None,
2223
completion_text: get_completion_text_with_schema_or_alias(
2324
ctx,
2425
&table.name,

crates/pgt_lsp/src/handlers/completions.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ pub fn get_completions(
3939
label: i.label,
4040
label_details: Some(CompletionItemLabelDetails {
4141
description: Some(i.description),
42-
detail: Some(format!(" {}", i.kind)),
42+
detail: i
43+
.detail
44+
.map(|s| format!(" {}", s))
45+
.or(Some(format!(" {}", i.kind))),
4346
}),
4447
preselect: Some(i.preselected),
4548
sort_text: Some(i.sort_text),

crates/pgt_schema_cache/src/columns.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub struct Column {
4848

4949
pub schema_name: String,
5050
pub type_id: i64,
51+
pub type_name: String,
5152
pub is_nullable: bool,
5253

5354
pub is_primary_key: bool,

crates/pgt_schema_cache/src/queries/columns.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ select
3535
ts.class_kind :: char as "class_kind!",
3636
ts.schema_name,
3737
atts.atttypid :: int8 as "type_id!",
38+
tps.typname as "type_name",
3839
not atts.attnotnull as "is_nullable!",
3940
nullif(
4041
information_schema._pg_char_max_length (atts.atttypid, atts.atttypmod),
@@ -51,6 +52,7 @@ from
5152
and atts.attnum = ix.attnum
5253
left join pg_catalog.pg_attrdef def on atts.attrelid = def.adrelid
5354
and atts.attnum = def.adnum
55+
left join pg_catalog.pg_type tps on tps.oid = atts.atttypid
5456
where
5557
-- system columns, such as `cmax` or `tableoid`, have negative `attnum`s
5658
atts.attnum >= 0

0 commit comments

Comments
 (0)