Repository navigation
fix(completions): quote names that need it when inserting them #981
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
base: main
Are you sure you want to change the base?
Changes from all commits
2c9062d
0052cce
6b228a1
6b24240
e3cc5ce
0aff6ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| use pgls_catalog::{Column, Snapshot}; | ||
| use pgls_catalog::{Column, NamePosition, Snapshot, identifier_name}; | ||
| use pgls_treesitter::TreesitterContext; | ||
|
|
||
| use crate::{ | ||
|
|
@@ -8,7 +8,7 @@ use crate::{ | |
| relevance::{CompletionRelevanceData, filtering::CompletionFilter, scoring::CompletionScore}, | ||
| }; | ||
|
|
||
| use super::helper::with_schema_or_alias; | ||
| use super::helper::{Qualifier, with_schema_or_alias}; | ||
|
|
||
| pub fn complete_columns<'a>( | ||
| ctx: &TreesitterContext<'a>, | ||
|
|
@@ -35,9 +35,17 @@ pub fn complete_columns<'a>( | |
| } | ||
|
|
||
| fn get_completion_text(ctx: &TreesitterContext, col: &Column) -> CompletionText { | ||
| let alias = ctx.get_used_alias_for_table(col.table_name.as_str()); | ||
|
|
||
| let with_schema_or_alias = with_schema_or_alias(ctx, col.name.as_str(), alias.as_deref()); | ||
| // The alias as a name, which is quoted again if needed. | ||
| let alias = ctx | ||
| .get_used_alias_for_table(col.table_name.as_str()) | ||
| .map(|alias| identifier_name(&alias)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example, when both tables have an id column: select | from users "public" join other o on "public".id = o.idThis previously inserted Maybe we could distinguish schema prefixes from aliases and only omit |
||
|
|
||
| let with_schema_or_alias = with_schema_or_alias( | ||
| ctx, | ||
| col.name.as_str(), | ||
| alias.as_deref().map(Qualifier::Alias), | ||
| NamePosition::ColId, | ||
| ); | ||
|
|
||
| let range = get_range_to_replace(ctx); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although
operatoris an unreserved keyword,quote_identifier("operator", NamePosition::TypeFunctionName)returnsoperator, and completing such a function producesoperator().``pgls_query::parse("SELECT operator()")
fails, whereas both SELECT "operator"()and `SELECT public.operator()` parse successfully.Maybe we could account for this ambiguity when emitting unqualified function names and add a parser round-trip test. Keyword classification alone does not catch this case.