Skip to content

Commit 30a1ca0

Browse files
still not there
1 parent dc1bc13 commit 30a1ca0

File tree

3 files changed

+20
-33
lines changed

3 files changed

+20
-33
lines changed

crates/pgt_completions/src/providers/functions.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use pgt_treesitter::TreesitterContext;
44
use crate::{
55
CompletionItemKind, CompletionText,
66
builder::{CompletionBuilder, PossibleCompletionItem},
7-
providers::helper::{get_range_to_replace, with_closed_quote},
7+
providers::helper::get_range_to_replace,
88
relevance::{CompletionRelevanceData, filtering::CompletionFilter, scoring::CompletionScore},
99
};
1010

@@ -35,8 +35,7 @@ pub fn complete_functions<'a>(
3535
}
3636

3737
fn get_completion_text(ctx: &TreesitterContext, func: &Function) -> CompletionText {
38-
let closed_quote = with_closed_quote(ctx, &func.name);
39-
let mut text = with_schema_or_alias(ctx, closed_quote.as_str(), Some(func.schema.as_str()));
38+
let mut text = with_schema_or_alias(ctx, func.name.as_str(), Some(func.schema.as_str()));
4039

4140
let range = get_range_to_replace(ctx);
4241

crates/pgt_completions/src/providers/helper.rs

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ pub(crate) fn get_range_to_replace(ctx: &TreesitterContext) -> TextRange {
1717
let sanitized = remove_sanitized_token(content);
1818
let length = sanitized.len();
1919

20-
let start = node.start_byte();
21-
let end = start + length;
20+
let mut start = node.start_byte();
21+
let mut end = start + length;
2222

23-
// let compl_text_in_quotes =
24-
// completion_text.starts_with('"') && completion_text.ends_with('"');
25-
26-
// if compl_text_in_quotes && sanitized == r#""""# {
27-
// return TextRange::new(start.try_into().unwrap(), end.try_into().unwrap());
28-
// }
23+
if node_text_surrounded_by_quotes(ctx) {
24+
start -= 1;
25+
end -= 1;
26+
}
2927

3028
TextRange::new(start.try_into().unwrap(), end.try_into().unwrap())
3129
}
@@ -39,33 +37,24 @@ pub(crate) fn with_schema_or_alias(
3937
schema_or_alias_name: Option<&str>,
4038
) -> String {
4139
let is_already_prefixed_with_schema_name = ctx.schema_or_alias_name.is_some();
40+
4241
let with_quotes = node_text_surrounded_by_quotes(ctx);
4342

43+
let node_under_cursor_txt = ctx.get_node_under_cursor_content().unwrap_or("".into());
44+
let node_under_cursor_txt = node_under_cursor_txt.as_str();
45+
let is_quote_sanitized = is_sanitized_token_with_quote(node_under_cursor_txt);
46+
4447
if schema_or_alias_name.is_none_or(|s| s == "public") || is_already_prefixed_with_schema_name {
45-
if with_quotes {
46-
format!(r#""{}""#, item_name).to_string()
47-
} else {
48-
item_name.to_string()
49-
}
48+
item_name.to_string()
5049
} else {
5150
let schema_or_als = schema_or_alias_name.unwrap();
5251

53-
if with_quotes {
54-
format!(r#""{}"."{}""#, schema_or_als.replace('"', ""), item_name).to_string()
52+
if is_quote_sanitized {
53+
format!(r#"{}"."{}""#, schema_or_als.replace('"', ""), item_name).to_string()
54+
} else if with_quotes {
55+
format!(r#"{}"."{}"#, schema_or_als.replace('"', ""), item_name).to_string()
5556
} else {
5657
format!("{}.{}", schema_or_als, item_name).to_string()
5758
}
5859
}
5960
}
60-
61-
pub(crate) fn with_closed_quote(ctx: &TreesitterContext, item_name: &str) -> String {
62-
let mut with_closed = String::from(item_name);
63-
64-
if let Some(content) = ctx.get_node_under_cursor_content() {
65-
if is_sanitized_token_with_quote(content.as_str()) {
66-
with_closed.push('"');
67-
}
68-
}
69-
70-
with_closed
71-
}

crates/pgt_completions/src/providers/tables.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
CompletionText,
66
builder::{CompletionBuilder, PossibleCompletionItem},
77
item::CompletionItemKind,
8-
providers::helper::{get_range_to_replace, with_closed_quote},
8+
providers::helper::get_range_to_replace,
99
relevance::{CompletionRelevanceData, filtering::CompletionFilter, scoring::CompletionScore},
1010
};
1111

@@ -44,8 +44,7 @@ pub fn complete_tables<'a>(
4444
}
4545

4646
fn get_completion_text(ctx: &TreesitterContext, table: &Table) -> CompletionText {
47-
let closed_quote = with_closed_quote(ctx, &table.name);
48-
let text = with_schema_or_alias(ctx, closed_quote.as_str(), Some(table.schema.as_str()));
47+
let text = with_schema_or_alias(ctx, table.name.as_str(), Some(table.schema.as_str()));
4948

5049
let range = get_range_to_replace(ctx);
5150

0 commit comments

Comments
 (0)