- Notifications
You must be signed in to change notification settings - Fork102
fix: sql fn params#366
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
17 commits Select commitHold shift + click to select a range
beeb661
fix: sql fn params
psteinroe9b6c7aa
save progress
psteinroeba83202
add ts query
psteinroee032c3f
progress
psteinroe896bfb1
progress
psteinroe9f9cf9b
just tests missing now
psteinroe733c8f2
chore: merge main
psteinroec794aae
Update crates/pgt_workspace/src/workspace/server/sql_function.rs
psteinroe4b0e3b6
Update crates/pgt_treesitter_queries/src/lib.rs
psteinroe971fd7f
fix: test
psteinroe8c4145a
fix: test
psteinroe324fc87
fix: review
psteinroeca280ab
merge main
psteinroef187306
fix: review
psteinroec55a2d8
fix: review
psteinroe266a217
use arc for schema cache
psteinroea9c5040
Merge branch 'main' into fix/fn-params
psteinroeFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletionsCargo.lock
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
1 change: 1 addition & 0 deletionscrates/pgt_completions/src/context/mod.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -270,6 +270,7 @@ impl<'a> CompletionContext<'a> { | ||
.insert(Some(WrappingClause::Select), new); | ||
} | ||
} | ||
_ => {} | ||
}; | ||
} | ||
} | ||
1 change: 1 addition & 0 deletionscrates/pgt_schema_cache/src/lib.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletionscrates/pgt_schema_cache/src/types.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
35 changes: 32 additions & 3 deletionscrates/pgt_treesitter_queries/src/lib.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletionscrates/pgt_treesitter_queries/src/queries/mod.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletionscrates/pgt_treesitter_queries/src/queries/parameters.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use std::sync::LazyLock; | ||
use crate::{Query, QueryResult}; | ||
use super::QueryTryFrom; | ||
static TS_QUERY: LazyLock<tree_sitter::Query> = LazyLock::new(|| { | ||
static QUERY_STR: &str = r#" | ||
[ | ||
(field | ||
(identifier)) @reference | ||
(field | ||
(object_reference) | ||
"." (identifier)) @reference | ||
(parameter) @parameter | ||
] | ||
"#; | ||
tree_sitter::Query::new(tree_sitter_sql::language(), QUERY_STR).expect("Invalid TS Query") | ||
}); | ||
#[derive(Debug)] | ||
pub struct ParameterMatch<'a> { | ||
pub(crate) node: tree_sitter::Node<'a>, | ||
} | ||
impl ParameterMatch<'_> { | ||
pub fn get_path(&self, sql: &str) -> String { | ||
self.node | ||
.utf8_text(sql.as_bytes()) | ||
.expect("Failed to get path from ParameterMatch") | ||
.to_string() | ||
} | ||
pub fn get_range(&self) -> tree_sitter::Range { | ||
self.node.range() | ||
} | ||
pub fn get_byte_range(&self) -> std::ops::Range<usize> { | ||
let range = self.node.range(); | ||
range.start_byte..range.end_byte | ||
} | ||
} | ||
impl<'a> TryFrom<&'a QueryResult<'a>> for &'a ParameterMatch<'a> { | ||
type Error = String; | ||
fn try_from(q: &'a QueryResult<'a>) -> Result<Self, Self::Error> { | ||
match q { | ||
QueryResult::Parameter(r) => Ok(r), | ||
#[allow(unreachable_patterns)] | ||
_ => Err("Invalid QueryResult type".into()), | ||
} | ||
} | ||
} | ||
impl<'a> QueryTryFrom<'a> for ParameterMatch<'a> { | ||
type Ref = &'a ParameterMatch<'a>; | ||
} | ||
impl<'a> Query<'a> for ParameterMatch<'a> { | ||
fn execute(root_node: tree_sitter::Node<'a>, stmt: &'a str) -> Vec<crate::QueryResult<'a>> { | ||
let mut cursor = tree_sitter::QueryCursor::new(); | ||
let matches = cursor.matches(&TS_QUERY, root_node, stmt.as_bytes()); | ||
matches | ||
.filter_map(|m| { | ||
let captures = m.captures; | ||
// We expect exactly one capture for a parameter | ||
if captures.len() != 1 { | ||
return None; | ||
} | ||
Some(QueryResult::Parameter(ParameterMatch { | ||
node: captures[0].node, | ||
})) | ||
}) | ||
.collect() | ||
} | ||
} |
19 changes: 10 additions & 9 deletionscrates/pgt_typecheck/Cargo.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
21 changes: 13 additions & 8 deletionscrates/pgt_typecheck/src/diagnostics.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
20 changes: 18 additions & 2 deletionscrates/pgt_typecheck/src/lib.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.