Skip to content

Commit 2f08a67

Browse files
feat(completions): show data type for columns (#402)
1 parent a2e4640 commit 2f08a67

File tree

11 files changed

+28
-8
lines changed

11 files changed

+28
-8
lines changed

.sqlx/query-fc0a0aa6d2a06bf3103d26a0233ae86f456892fa9ce48854a8b960cdf2d11a45.json renamed to .sqlx/query-97da37af0d64378cb622cab14bb3b0ce33a0002d170200d77afeee60a7977278.json

Lines changed: 13 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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
@@ -54,6 +54,7 @@ pub struct CompletionItem {
5454
pub kind: CompletionItemKind,
5555
/// String used for sorting by LSP clients.
5656
pub sort_text: String,
57+
pub detail: Option<String>,
5758

5859
pub completion_text: Option<CompletionText>,
5960
}

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(col.type_name.to_string()),
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
@@ -22,6 +22,7 @@ pub fn complete_functions<'a>(ctx: &'a CompletionContext, builder: &mut Completi
2222
filter: CompletionFilter::from(relevance),
2323
description: format!("Schema: {}", func.schema),
2424
kind: CompletionItemKind::Function,
25+
detail: None,
2526
completion_text: Some(get_completion_text(ctx, func)),
2627
};
2728

crates/pgt_completions/src/providers/policies.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pub fn complete_policies<'a>(ctx: &CompletionContext<'a>, builder: &mut Completi
5050
description: pol.table_name.to_string(),
5151
kind: CompletionItemKind::Policy,
5252
completion_text,
53+
detail: None,
5354
};
5455

5556
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
@@ -41,7 +41,10 @@ pub fn get_completions(
4141
label: i.label,
4242
label_details: Some(CompletionItemLabelDetails {
4343
description: Some(i.description),
44-
detail: Some(format!(" {}", i.kind)),
44+
detail: i
45+
.detail
46+
.map(|s| format!(" {}", s))
47+
.or(Some(format!(" {}", i.kind))),
4548
}),
4649
preselect: Some(i.preselected),
4750
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)