Skip to content

Commit c0e2d35

Browse files
fixed aaaaaaaaaaaaaaat
1 parent cdb4355 commit c0e2d35

File tree

2 files changed

+53
-9
lines changed

2 files changed

+53
-9
lines changed

crates/pgls_completions/src/providers/columns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn get_completion_text(ctx: &TreesitterContext, col: &Column) -> CompletionText
5252
mod tests {
5353
use sqlx::PgPool;
5454

55-
use crate::test_helper::{TestCompletionsCase, TestCompletionsSuite, assert_complete_results};
55+
use crate::test_helper::{TestCompletionsCase, TestCompletionsSuite};
5656

5757
#[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")]
5858
async fn handles_nested_queries(pool: PgPool) {

crates/pgls_completions/src/relevance/scoring.rs

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,53 @@ impl CompletionScore<'_> {
5959
CompletionRelevanceData::Role(r) => r.name.as_str().to_ascii_lowercase(),
6060
};
6161

62+
let is_case =
63+
matches!(self.data, CompletionRelevanceData::Column(_)) && content.as_str() == "u";
64+
6265
let fz_matcher = SkimMatcherV2::default();
6366

64-
let check_against = match ctx.identifier_qualifiers {
67+
let check_against = match &ctx.identifier_qualifiers {
6568
// If both qualifiers are already written out, we must check the item's name itself.
66-
(Some(_), Some(_)) => content.to_ascii_lowercase(),
69+
(Some(_), Some(_)) => name,
70+
71+
// If only one qualifier is written out, we might look at a schema, a table, or an alias.
72+
(None, Some(qualifier)) => {
73+
if self.get_schema_name().is_some_and(|s| s == qualifier) {
74+
self.get_table_name()
75+
.map(|t| format!("{}.{}", t, name))
76+
.unwrap_or(name)
77+
} else if self.get_table_name().is_some_and(|t| t == qualifier) {
78+
name
79+
} else if ctx
80+
.get_mentioned_table_for_alias(&qualifier)
81+
.is_some_and(|alias_tbl| {
82+
self.get_table_name()
83+
.is_some_and(|item_tbl| alias_tbl == item_tbl)
84+
})
85+
{
86+
name
87+
} else {
88+
// the qualifier does not match schema, table, or alias.
89+
// what the hell is it?
90+
// probably a typo.
91+
self.skip = true;
92+
String::new()
93+
}
94+
}
6795

68-
_ => self
69-
.get_table_name()
70-
.and_then(|tbl| ctx.get_used_alias_for_table(tbl))
71-
.map(|alias| format!("{}.{}", alias, name))
72-
.unwrap_or(name),
96+
// no qualifier whatsoever, we'll check the full qualified name of the item.
97+
_ => self.get_fully_qualified_name(),
7398
};
7499

75100
match fz_matcher.fuzzy_match(
76-
check_against.as_str(),
101+
check_against.to_ascii_lowercase().as_str(),
77102
content.to_ascii_lowercase().as_str(),
78103
) {
79104
Some(score) => {
105+
if is_case {
106+
println!("check {}, score {}", check_against, score);
107+
}
108+
80109
let scorei32: i32 = score
81110
.try_into()
82111
.expect("The length of the input exceeds i32 capacity");
@@ -258,6 +287,21 @@ impl CompletionScore<'_> {
258287
}
259288
}
260289

290+
fn get_fully_qualified_name(&self) -> String {
291+
match self.data {
292+
CompletionRelevanceData::Schema(s) => s.name.clone(),
293+
CompletionRelevanceData::Column(c) => {
294+
format!("{}.{}.{}", c.schema_name, c.table_name, c.name)
295+
}
296+
CompletionRelevanceData::Table(t) => format!("{}.{}", t.schema, t.name),
297+
CompletionRelevanceData::Function(f) => format!("{}.{}", f.schema, f.name),
298+
CompletionRelevanceData::Policy(p) => {
299+
format!("{}.{}.{}", p.schema_name, p.table_name, p.name)
300+
}
301+
CompletionRelevanceData::Role(r) => r.name.clone(),
302+
}
303+
}
304+
261305
fn get_table_name(&self) -> Option<&str> {
262306
match self.data {
263307
CompletionRelevanceData::Column(c) => Some(c.table_name.as_str()),

0 commit comments

Comments
 (0)