Skip to content
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
14 changes: 14 additions & 0 deletions crates/squawk_ide/src/code_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,12 @@ fn add_explicit_alias(
return None;
}

if let Some(ast::Expr::FieldExpr(field_expr)) = target.expr()
&& field_expr.star_token().is_some()
{
return None;
}

let alias = ColumnName::from_target(target.clone()).and_then(|c| c.0.to_string())?;

let expr_end = target.expr().map(|e| e.syntax().text_range().end())?;
Expand Down Expand Up @@ -1513,6 +1519,14 @@ select myschema.f$0();"
));
}

#[test]
fn add_explicit_alias_not_applicable_qualified_star() {
assert!(code_action_not_applicable(
add_explicit_alias,
"with t as (select 1 a) select t.*$0 from t;"
));
}

#[test]
fn add_explicit_alias_literal() {
assert_snapshot!(apply_code_action(
Expand Down
80 changes: 48 additions & 32 deletions crates/squawk_ide/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ fn select_completions(
&& let Some(select) = ast::Select::cast(parent)
&& let Some(from_clause) = select.from_clause()
{
completions.push(CompletionItem {
label: "*".to_string(),
kind: CompletionItemKind::Operator,
detail: None,
insert_text: None,
insert_text_format: None,
trigger_completion_after_insert: false,
sort_text: None,
});
for table_ptr in resolve::table_ptrs_from_clause(&binder, &from_clause) {
let table_node = table_ptr.to_node(file.syntax());
match resolve::find_table_source(&table_node) {
Expand Down Expand Up @@ -488,6 +497,7 @@ pub enum CompletionItemKind {
Schema,
Type,
Snippet,
Operator,
}

impl CompletionItemKind {
Expand All @@ -499,6 +509,7 @@ impl CompletionItemKind {
Self::Type => "1",
Self::Snippet => "1",
Self::Function => "2",
Self::Operator => "8",
Self::Schema => "9",
}
}
Expand Down Expand Up @@ -696,6 +707,7 @@ select $0 from t;
b | Column | int |
t | Table | |
f() | Function | public.f() returns text |
* | Operator | |
public | Schema | |
pg_catalog | Schema | |
pg_temp | Schema | |
Expand All @@ -710,9 +722,10 @@ select $0 from t;
create table t (c int);
select t.$0 from t;
"), @r"
label | kind | detail | insert_text
-------+--------+--------+-------------
c | Column | int |
label | kind | detail | insert_text
-------+----------+--------+-------------
c | Column | int |
* | Operator | |
");
}

Expand All @@ -722,14 +735,15 @@ select t.$0 from t;
with t as (select 1 a)
select $0 from t;
"), @r"
label | kind | detail | insert_text
--------------------+--------+---------+-------------
a | Column | integer |
public | Schema | |
pg_catalog | Schema | |
pg_temp | Schema | |
pg_toast | Schema | |
information_schema | Schema | |
label | kind | detail | insert_text
--------------------+----------+---------+-------------
a | Column | integer |
* | Operator | |
public | Schema | |
pg_catalog | Schema | |
pg_temp | Schema | |
pg_toast | Schema | |
information_schema | Schema | |
");
}

Expand All @@ -739,16 +753,17 @@ select $0 from t;
with t as (values (1, 'foo', false))
select $0 from t;
"), @r"
label | kind | detail | insert_text
--------------------+--------+---------+-------------
column1 | Column | integer |
column2 | Column | text |
column3 | Column | boolean |
public | Schema | |
pg_catalog | Schema | |
pg_temp | Schema | |
pg_toast | Schema | |
information_schema | Schema | |
label | kind | detail | insert_text
--------------------+----------+---------+-------------
column1 | Column | integer |
column2 | Column | text |
column3 | Column | boolean |
* | Operator | |
public | Schema | |
pg_catalog | Schema | |
pg_temp | Schema | |
pg_toast | Schema | |
information_schema | Schema | |
");
}

Expand All @@ -757,17 +772,18 @@ select $0 from t;
assert_snapshot!(completions("
select $0 from (values (1, 'foo', 1.5, false));
"), @r"
label | kind | detail | insert_text
--------------------+--------+---------+-------------
column1 | Column | integer |
column2 | Column | text |
column3 | Column | numeric |
column4 | Column | boolean |
public | Schema | |
pg_catalog | Schema | |
pg_temp | Schema | |
pg_toast | Schema | |
information_schema | Schema | |
label | kind | detail | insert_text
--------------------+----------+---------+-------------
column1 | Column | integer |
column2 | Column | text |
column3 | Column | numeric |
column4 | Column | boolean |
* | Operator | |
public | Schema | |
pg_catalog | Schema | |
pg_temp | Schema | |
pg_toast | Schema | |
information_schema | Schema | |
");
}

Expand Down
1 change: 1 addition & 0 deletions crates/squawk_server/src/lsp_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub(crate) fn completion_item(
CompletionItemKind::Function => lsp_types::CompletionItemKind::FUNCTION,
CompletionItemKind::Type => lsp_types::CompletionItemKind::CLASS,
CompletionItemKind::Snippet => lsp_types::CompletionItemKind::SNIPPET,
CompletionItemKind::Operator => lsp_types::CompletionItemKind::OPERATOR,
};

let sort_text = Some(item.sort_text());
Expand Down
1 change: 1 addition & 0 deletions crates/squawk_wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ pub fn completion(content: String, line: u32, col: u32) -> Result<JsValue, Error
squawk_ide::completion::CompletionItemKind::Schema => "schema",
squawk_ide::completion::CompletionItemKind::Type => "type",
squawk_ide::completion::CompletionItemKind::Snippet => "snippet",
squawk_ide::completion::CompletionItemKind::Operator => "operator",
}
.to_string(),
detail: item.detail,
Expand Down
Loading