Skip to content

feat(completions): show data type for columns #402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/pgt_completions/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub(crate) struct PossibleCompletionItem<'a> {
pub score: CompletionScore<'a>,
pub filter: CompletionFilter<'a>,
pub completion_text: Option<CompletionText>,
pub detail: Option<String>,
}

pub(crate) struct CompletionBuilder<'a> {
Expand Down Expand Up @@ -70,6 +71,7 @@ impl<'a> CompletionBuilder<'a> {
kind: item.kind,
label: item.label,
preselected,
detail: item.detail,

// wonderous Rust syntax ftw
sort_text: format!("{:0>padding$}", idx, padding = max_padding),
Expand Down
1 change: 1 addition & 0 deletions crates/pgt_completions/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub struct CompletionItem {
pub kind: CompletionItemKind,
/// String used for sorting by LSP clients.
pub sort_text: String,
pub detail: Option<String>,

pub completion_text: Option<CompletionText>,
}
1 change: 1 addition & 0 deletions crates/pgt_completions/src/providers/columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub fn complete_columns<'a>(ctx: &CompletionContext<'a>, builder: &mut Completio
description: format!("Table: {}.{}", col.schema_name, col.table_name),
kind: CompletionItemKind::Column,
completion_text: None,
detail: Some(col.type_name.to_string()),
};

// autocomplete with the alias in a join clause if we find one
Expand Down
1 change: 1 addition & 0 deletions crates/pgt_completions/src/providers/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub fn complete_functions<'a>(ctx: &'a CompletionContext, builder: &mut Completi
filter: CompletionFilter::from(relevance),
description: format!("Schema: {}", func.schema),
kind: CompletionItemKind::Function,
detail: None,
completion_text: Some(get_completion_text(ctx, func)),
};

Expand Down
1 change: 1 addition & 0 deletions crates/pgt_completions/src/providers/policies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub fn complete_policies<'a>(ctx: &CompletionContext<'a>, builder: &mut Completi
description: pol.table_name.to_string(),
kind: CompletionItemKind::Policy,
completion_text,
detail: None,
};

builder.add_item(item);
Expand Down
1 change: 1 addition & 0 deletions crates/pgt_completions/src/providers/schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub fn complete_schemas<'a>(ctx: &'a CompletionContext, builder: &mut Completion
kind: crate::CompletionItemKind::Schema,
score: CompletionScore::from(relevance.clone()),
filter: CompletionFilter::from(relevance),
detail: None,
completion_text: None,
};

Expand Down
1 change: 1 addition & 0 deletions crates/pgt_completions/src/providers/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub fn complete_tables<'a>(ctx: &'a CompletionContext, builder: &mut CompletionB
filter: CompletionFilter::from(relevance),
description: format!("Schema: {}", table.schema),
kind: CompletionItemKind::Table,
detail: None,
completion_text: get_completion_text_with_schema_or_alias(
ctx,
&table.name,
Expand Down
5 changes: 4 additions & 1 deletion crates/pgt_lsp/src/handlers/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ pub fn get_completions(
label: i.label,
label_details: Some(CompletionItemLabelDetails {
description: Some(i.description),
detail: Some(format!(" {}", i.kind)),
detail: i
.detail
.map(|s| format!(" {}", s))
.or(Some(format!(" {}", i.kind))),
}),
preselect: Some(i.preselected),
sort_text: Some(i.sort_text),
Expand Down
1 change: 1 addition & 0 deletions crates/pgt_schema_cache/src/columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub struct Column {

pub schema_name: String,
pub type_id: i64,
pub type_name: String,
pub is_nullable: bool,

pub is_primary_key: bool,
Expand Down
2 changes: 2 additions & 0 deletions crates/pgt_schema_cache/src/queries/columns.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ select
ts.class_kind :: char as "class_kind!",
ts.schema_name,
atts.atttypid :: int8 as "type_id!",
tps.typname as "type_name",
not atts.attnotnull as "is_nullable!",
nullif(
information_schema._pg_char_max_length (atts.atttypid, atts.atttypmod),
Expand All @@ -51,6 +52,7 @@ from
and atts.attnum = ix.attnum
left join pg_catalog.pg_attrdef def on atts.attrelid = def.adrelid
and atts.attnum = def.adnum
left join pg_catalog.pg_type tps on tps.oid = atts.atttypid
where
-- system columns, such as `cmax` or `tableoid`, have negative `attnum`s
atts.attnum >= 0
Expand Down