Skip to content

Commit db49040

Browse files
revert things
1 parent dc54e9e commit db49040

File tree

4 files changed

+6
-67
lines changed

4 files changed

+6
-67
lines changed

crates/pgt_completions/src/item.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::fmt::Display;
2-
31
use serde::{Deserialize, Serialize};
42

53
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
@@ -12,23 +10,12 @@ pub enum CompletionItemKind {
1210
Schema,
1311
}
1412

15-
impl Display for CompletionItemKind {
16-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17-
match self {
18-
CompletionItemKind::Table => write!(f, "Table"),
19-
CompletionItemKind::Function => write!(f, "Function"),
20-
CompletionItemKind::Column => write!(f, "Column"),
21-
CompletionItemKind::Schema => write!(f, "Schema"),
22-
}
23-
}
24-
}
25-
2613
#[derive(Debug, Serialize, Deserialize)]
2714
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
2815
pub struct CompletionItem {
2916
pub label: String,
17+
pub(crate) score: i32,
3018
pub description: String,
3119
pub preselected: bool,
3220
pub kind: CompletionItemKind,
33-
pub score: i32,
3421
}

crates/pgt_completions/src/sanitization.rs

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{borrow::Cow, cmp::max};
1+
use std::borrow::Cow;
22

33
use pgt_text_size::TextSize;
44

@@ -24,7 +24,6 @@ where
2424
if cursor_inbetween_nodes(params.tree, params.position)
2525
|| cursor_prepared_to_write_token_after_last_node(params.tree, params.position)
2626
|| cursor_before_semicolon(params.tree, params.position)
27-
|| cursor_on_a_dot(&params.text, params.position)
2827
{
2928
SanitizedCompletionParams::with_adjusted_sql(params)
3029
} else {
@@ -45,13 +44,12 @@ where
4544

4645
let mut sql_iter = params.text.chars();
4746

48-
let max = max(cursor_pos + 1, params.text.len());
49-
50-
for idx in 0..max {
47+
for idx in 0..cursor_pos + 1 {
5148
match sql_iter.next() {
5249
Some(c) => {
5350
if idx == cursor_pos {
5451
sql.push_str(SANITIZED_TOKEN);
52+
sql.push(' ');
5553
}
5654
sql.push(c);
5755
}
@@ -151,11 +149,6 @@ fn cursor_prepared_to_write_token_after_last_node(
151149
cursor_pos == tree.root_node().end_byte() + 1
152150
}
153151

154-
fn cursor_on_a_dot(sql: &str, position: TextSize) -> bool {
155-
let position: usize = position.into();
156-
sql.chars().nth(position - 1).is_some_and(|c| c == '.')
157-
}
158-
159152
fn cursor_before_semicolon(tree: &tree_sitter::Tree, position: TextSize) -> bool {
160153
let mut cursor = tree.walk();
161154
let mut leaf_node = tree.root_node();
@@ -205,7 +198,7 @@ mod tests {
205198
use pgt_text_size::TextSize;
206199

207200
use crate::sanitization::{
208-
cursor_before_semicolon, cursor_inbetween_nodes, cursor_on_a_dot,
201+
cursor_before_semicolon, cursor_inbetween_nodes,
209202
cursor_prepared_to_write_token_after_last_node,
210203
};
211204

@@ -270,20 +263,6 @@ mod tests {
270263
));
271264
}
272265

273-
#[test]
274-
fn on_a_dot() {
275-
let input = "select * from private.";
276-
277-
// select * from private.| <-- on a dot
278-
assert!(cursor_on_a_dot(&input, TextSize::new(22)));
279-
280-
// select * from private|. <-- before the dot
281-
assert!(!cursor_on_a_dot(&input, TextSize::new(21)));
282-
283-
// select * from private. | <-- too far off the dot
284-
assert!(!cursor_on_a_dot(&input, TextSize::new(23)));
285-
}
286-
287266
#[test]
288267
fn test_cursor_before_semicolon() {
289268
// Idx "13" is the exlusive end of `select * from` (first space after from)

crates/pgt_lsp/src/capabilities.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub(crate) fn server_capabilities(capabilities: &ClientCapabilities) -> ServerCa
3737
// The request is used to get more information about a simple CompletionItem.
3838
resolve_provider: None,
3939

40-
trigger_characters: Some(vec![".".to_owned(), " ".to_owned()]),
40+
trigger_characters: Some(vec![".".to_owned(), ",".to_owned(), " ".to_owned()]),
4141

4242
// No character will lead to automatically inserting the selected completion-item
4343
all_commit_characters: None,

crates/pgt_treesitter_queries/src/lib.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -185,31 +185,4 @@ on sq1.id = pt.id;
185185
assert_eq!(results[0].get_schema(sql), Some("private".into()));
186186
assert_eq!(results[0].get_table(sql), "something");
187187
}
188-
189-
#[test]
190-
fn picks_it_up_without_schemas() {
191-
let sql = r#"select * from users"#;
192-
193-
let mut parser = tree_sitter::Parser::new();
194-
parser.set_language(tree_sitter_sql::language()).unwrap();
195-
196-
let tree = parser.parse(sql, None).unwrap();
197-
198-
// trust me bro
199-
200-
let mut executor = TreeSitterQueriesExecutor::new(tree.root_node(), sql);
201-
202-
executor.add_query_results::<RelationMatch>();
203-
204-
let results: Vec<&RelationMatch> = executor
205-
.get_iter(None)
206-
.filter_map(|q| q.try_into().ok())
207-
.collect();
208-
209-
println!("{:?}", results);
210-
211-
assert_eq!(results.len(), 1);
212-
assert_eq!(results[0].get_schema(sql), None);
213-
assert_eq!(results[0].get_table(sql), "users");
214-
}
215188
}

0 commit comments

Comments
 (0)