Skip to content

Commit 2cdf3e2

Browse files
committed
progress
2 parents 3469bbf + 43d262b commit 2cdf3e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+386957
-423710
lines changed

.sqlx/query-b869d517301aaf69d382f092c09d5a53712d68afd273423f9310cd793586f532.json

Lines changed: 74 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pgls_completions/src/providers/columns.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ mod tests {
5858
use crate::{
5959
CompletionItem, CompletionItemKind, complete,
6060
test_helper::{
61-
CompletionAssertion, assert_complete_results, assert_no_complete_results,
62-
get_test_deps, get_test_params,
61+
CompletionAssertion, assert_complete_results, get_test_deps, get_test_params,
6362
},
6463
};
6564

@@ -717,18 +716,6 @@ mod tests {
717716
&pool,
718717
)
719718
.await;
720-
721-
// no completions in the values list!
722-
assert_no_complete_results(
723-
format!(
724-
"insert into instruments (id, name) values ({})",
725-
QueryWithCursorPosition::cursor_marker()
726-
)
727-
.as_str(),
728-
None,
729-
&pool,
730-
)
731-
.await;
732719
}
733720

734721
#[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")]

crates/pgls_completions/src/providers/helper.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use pgls_text_size::{TextRange, TextSize};
1+
use pgls_text_size::TextRange;
22
use pgls_treesitter::TreesitterContext;
33

44
use crate::{is_sanitized_token_with_quote, remove_sanitized_token};
@@ -9,29 +9,25 @@ pub(crate) fn node_text_surrounded_by_quotes(ctx: &TreesitterContext) -> bool {
99
}
1010

1111
pub(crate) fn get_range_to_replace(ctx: &TreesitterContext) -> TextRange {
12-
match ctx.node_under_cursor.as_ref() {
13-
Some(node) => {
14-
let content = ctx.get_node_under_cursor_content().unwrap_or("".into());
15-
let content = content.as_str();
12+
let node = &ctx.node_under_cursor;
13+
let content = ctx.get_node_under_cursor_content().unwrap_or("".into());
14+
let content = content.as_str();
1615

17-
let sanitized = remove_sanitized_token(content);
18-
let length = sanitized.len();
16+
let sanitized = remove_sanitized_token(content);
17+
let length = sanitized.len();
1918

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

23-
if sanitized.starts_with('"') && sanitized.ends_with('"') {
24-
start += 1;
22+
if sanitized.starts_with('"') && sanitized.ends_with('"') {
23+
start += 1;
2524

26-
if sanitized.len() > 1 {
27-
end -= 1;
28-
}
29-
}
30-
31-
TextRange::new(start.try_into().unwrap(), end.try_into().unwrap())
25+
if sanitized.len() > 1 {
26+
end -= 1;
3227
}
33-
None => TextRange::empty(TextSize::new(0)),
3428
}
29+
30+
TextRange::new(start.try_into().unwrap(), end.try_into().unwrap())
3531
}
3632

3733
pub(crate) fn only_leading_quote(ctx: &TreesitterContext) -> bool {
@@ -45,7 +41,7 @@ pub(crate) fn with_schema_or_alias(
4541
item_name: &str,
4642
schema_or_alias_name: Option<&str>,
4743
) -> String {
48-
let is_already_prefixed_with_schema_name = ctx.schema_or_alias_name.is_some();
44+
let is_already_prefixed_with_schema_name = ctx.has_any_qualifier();
4945

5046
let with_quotes = node_text_surrounded_by_quotes(ctx);
5147
let single_leading_quote = only_leading_quote(ctx);

crates/pgls_completions/src/providers/roles.rs

Lines changed: 31 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,31 @@ mod tests {
4646
);
4747
"#;
4848

49+
fn expected_roles() -> Vec<CompletionAssertion> {
50+
vec![
51+
CompletionAssertion::LabelAndKind("anon".into(), crate::CompletionItemKind::Role),
52+
CompletionAssertion::LabelAndKind(
53+
"authenticated".into(),
54+
crate::CompletionItemKind::Role,
55+
),
56+
CompletionAssertion::LabelAndKind("owner".into(), crate::CompletionItemKind::Role),
57+
CompletionAssertion::LabelAndKind(
58+
"service_role".into(),
59+
crate::CompletionItemKind::Role,
60+
),
61+
CompletionAssertion::LabelAndKind("test_login".into(), crate::CompletionItemKind::Role),
62+
CompletionAssertion::LabelAndKind(
63+
"test_nologin".into(),
64+
crate::CompletionItemKind::Role,
65+
),
66+
]
67+
}
68+
4969
#[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")]
5070
async fn works_in_drop_role(pool: PgPool) {
5171
assert_complete_results(
5272
format!("drop role {}", QueryWithCursorPosition::cursor_marker()).as_str(),
53-
vec![
54-
CompletionAssertion::LabelAndKind("owner".into(), crate::CompletionItemKind::Role),
55-
CompletionAssertion::LabelAndKind(
56-
"test_login".into(),
57-
crate::CompletionItemKind::Role,
58-
),
59-
CompletionAssertion::LabelAndKind(
60-
"test_nologin".into(),
61-
crate::CompletionItemKind::Role,
62-
),
63-
],
73+
expected_roles(),
6474
Some(SETUP),
6575
&pool,
6676
)
@@ -71,17 +81,7 @@ mod tests {
7181
async fn works_in_alter_role(pool: PgPool) {
7282
assert_complete_results(
7383
format!("alter role {}", QueryWithCursorPosition::cursor_marker()).as_str(),
74-
vec![
75-
CompletionAssertion::LabelAndKind("owner".into(), crate::CompletionItemKind::Role),
76-
CompletionAssertion::LabelAndKind(
77-
"test_login".into(),
78-
crate::CompletionItemKind::Role,
79-
),
80-
CompletionAssertion::LabelAndKind(
81-
"test_nologin".into(),
82-
crate::CompletionItemKind::Role,
83-
),
84-
],
84+
expected_roles(),
8585
Some(SETUP),
8686
&pool,
8787
)
@@ -94,17 +94,7 @@ mod tests {
9494

9595
assert_complete_results(
9696
format!("set role {}", QueryWithCursorPosition::cursor_marker()).as_str(),
97-
vec![
98-
CompletionAssertion::LabelAndKind("owner".into(), crate::CompletionItemKind::Role),
99-
CompletionAssertion::LabelAndKind(
100-
"test_login".into(),
101-
crate::CompletionItemKind::Role,
102-
),
103-
CompletionAssertion::LabelAndKind(
104-
"test_nologin".into(),
105-
crate::CompletionItemKind::Role,
106-
),
107-
],
97+
expected_roles(),
10898
None,
10999
&pool,
110100
)
@@ -116,17 +106,7 @@ mod tests {
116106
QueryWithCursorPosition::cursor_marker()
117107
)
118108
.as_str(),
119-
vec![
120-
CompletionAssertion::LabelAndKind("owner".into(), crate::CompletionItemKind::Role),
121-
CompletionAssertion::LabelAndKind(
122-
"test_login".into(),
123-
crate::CompletionItemKind::Role,
124-
),
125-
CompletionAssertion::LabelAndKind(
126-
"test_nologin".into(),
127-
crate::CompletionItemKind::Role,
128-
),
129-
],
109+
expected_roles(),
130110
None,
131111
&pool,
132112
)
@@ -140,24 +120,14 @@ mod tests {
140120
assert_complete_results(
141121
format!(
142122
r#"create policy "my cool policy" on public.users
143-
as restrictive
123+
as restrictive
144124
for all
145125
to {}
146126
using (true);"#,
147127
QueryWithCursorPosition::cursor_marker()
148128
)
149129
.as_str(),
150-
vec![
151-
CompletionAssertion::LabelAndKind("owner".into(), crate::CompletionItemKind::Role),
152-
CompletionAssertion::LabelAndKind(
153-
"test_login".into(),
154-
crate::CompletionItemKind::Role,
155-
),
156-
CompletionAssertion::LabelAndKind(
157-
"test_nologin".into(),
158-
crate::CompletionItemKind::Role,
159-
),
160-
],
130+
expected_roles(),
161131
None,
162132
&pool,
163133
)
@@ -171,17 +141,7 @@ mod tests {
171141
QueryWithCursorPosition::cursor_marker()
172142
)
173143
.as_str(),
174-
vec![
175-
CompletionAssertion::LabelAndKind("owner".into(), crate::CompletionItemKind::Role),
176-
CompletionAssertion::LabelAndKind(
177-
"test_login".into(),
178-
crate::CompletionItemKind::Role,
179-
),
180-
CompletionAssertion::LabelAndKind(
181-
"test_nologin".into(),
182-
crate::CompletionItemKind::Role,
183-
),
184-
],
144+
expected_roles(),
185145
None,
186146
&pool,
187147
)
@@ -200,18 +160,7 @@ mod tests {
200160
QueryWithCursorPosition::cursor_marker()
201161
)
202162
.as_str(),
203-
vec![
204-
// recognizing already mentioned roles is not supported for now
205-
CompletionAssertion::LabelAndKind("owner".into(), crate::CompletionItemKind::Role),
206-
CompletionAssertion::LabelAndKind(
207-
"test_login".into(),
208-
crate::CompletionItemKind::Role,
209-
),
210-
CompletionAssertion::LabelAndKind(
211-
"test_nologin".into(),
212-
crate::CompletionItemKind::Role,
213-
),
214-
],
163+
expected_roles(),
215164
None,
216165
&pool,
217166
)
@@ -225,18 +174,7 @@ mod tests {
225174
QueryWithCursorPosition::cursor_marker()
226175
)
227176
.as_str(),
228-
vec![
229-
// recognizing already mentioned roles is not supported for now
230-
CompletionAssertion::LabelAndKind("owner".into(), crate::CompletionItemKind::Role),
231-
CompletionAssertion::LabelAndKind(
232-
"test_login".into(),
233-
crate::CompletionItemKind::Role,
234-
),
235-
CompletionAssertion::LabelAndKind(
236-
"test_nologin".into(),
237-
crate::CompletionItemKind::Role,
238-
),
239-
],
177+
expected_roles(),
240178
None,
241179
&pool,
242180
)
@@ -248,18 +186,7 @@ mod tests {
248186
QueryWithCursorPosition::cursor_marker()
249187
)
250188
.as_str(),
251-
vec![
252-
// recognizing already mentioned roles is not supported for now
253-
CompletionAssertion::LabelAndKind("owner".into(), crate::CompletionItemKind::Role),
254-
CompletionAssertion::LabelAndKind(
255-
"test_login".into(),
256-
crate::CompletionItemKind::Role,
257-
),
258-
CompletionAssertion::LabelAndKind(
259-
"test_nologin".into(),
260-
crate::CompletionItemKind::Role,
261-
),
262-
],
189+
expected_roles(),
263190
None,
264191
&pool,
265192
)
@@ -298,27 +225,7 @@ mod tests {
298225
];
299226

300227
for query in queries {
301-
assert_complete_results(
302-
query.as_str(),
303-
vec![
304-
// recognizing already mentioned roles is not supported for now
305-
CompletionAssertion::LabelAndKind(
306-
"owner".into(),
307-
crate::CompletionItemKind::Role,
308-
),
309-
CompletionAssertion::LabelAndKind(
310-
"test_login".into(),
311-
crate::CompletionItemKind::Role,
312-
),
313-
CompletionAssertion::LabelAndKind(
314-
"test_nologin".into(),
315-
crate::CompletionItemKind::Role,
316-
),
317-
],
318-
None,
319-
&pool,
320-
)
321-
.await;
228+
assert_complete_results(query.as_str(), expected_roles(), None, &pool).await;
322229
}
323230
}
324231
}

0 commit comments

Comments
 (0)