Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions crates/squawk_ide/src/code_actions/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ fn apply_code_action_(
};
let offset = fixture.marker().offset_before();
let db = fixture.db();
let file = fixture.file();
let file = offset.file_id;

let mut actions = vec![];
f(db, InFile::new(file, offset), &mut actions);
f(db, offset, &mut actions);

assert!(
!actions.is_empty(),
Expand Down Expand Up @@ -110,10 +110,9 @@ fn code_action_not_applicable_(
};
let offset = fixture.marker().offset_before();
let db = fixture.db();
let file = fixture.file();

let mut actions = vec![];
f(db, InFile::new(file, offset), &mut actions);
f(db, offset, &mut actions);
actions.is_empty()
}

Expand Down
7 changes: 4 additions & 3 deletions crates/squawk_ide/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ pub struct CompletionItem {
#[cfg(test)]
mod tests {
use super::completion;
use crate::file::InFile;

use crate::test_utils::Fixture;
use insta::assert_snapshot;
use tabled::builder::Builder;
Expand All @@ -949,7 +949,7 @@ mod tests {
fn completions(sql: &str) -> String {
let fixture = Fixture::new_allow_errors(sql);
let offset = fixture.marker().offset();
let items = completion(fixture.db(), InFile::new(fixture.file(), offset));
let items = completion(fixture.db(), offset);
assert!(
!items.is_empty(),
"No completions found. If this was intended, use `completions_not_found` instead."
Expand All @@ -960,7 +960,7 @@ mod tests {
fn completions_not_found(sql: &str) {
let fixture = Fixture::new_allow_errors(sql);
let offset = fixture.marker().offset();
let items = completion(fixture.db(), InFile::new(fixture.file(), offset));
let items = completion(fixture.db(), offset);
assert_eq!(
items,
vec![],
Expand Down Expand Up @@ -1143,6 +1143,7 @@ select $0 from t;
#[test]
fn completion_after_select_create_table_inherits_builtin() {
assert_snapshot!(completions("
-- include-builtins
create table t ()
inherits (information_schema.sql_features);
select $0 from t;
Expand Down
38 changes: 35 additions & 3 deletions crates/squawk_ide/src/db.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use ::line_index::LineIndex;
use salsa::Database as Db;
#[cfg(test)]
use salsa::Setter;
use salsa::Storage;
use squawk_syntax::{Parse, SourceFile};
use std::sync::Arc;
Expand All @@ -26,20 +28,50 @@ pub fn line_index(db: &dyn Db, file: File) -> LineIndex {

#[inline]
pub(crate) fn list_files(db: &dyn Db, file: File) -> impl Iterator<Item = File> {
[file, builtins_file(db)].into_iter()
[Some(file), include_builtins(db).then(|| builtins_file(db))]
.into_iter()
.flatten()
}

#[salsa::tracked]
pub fn bind(db: &dyn Db, file: File) -> Binder {
pub(crate) fn bind(db: &dyn Db, file: File) -> Binder {
let result = parse(db, file);
let source_file = result.tree();
binder::bind(&source_file)
}

#[salsa::input(singleton)]
pub(crate) struct Config {
// currently only used for improve test runtime by skipping builtins
pub(crate) include_builtins: bool,
}

#[salsa::tracked]
pub(crate) fn include_builtins(db: &dyn Db) -> bool {
Config::get(db).include_builtins(db)
}

#[salsa::db]
#[derive(Clone, Default)]
#[derive(Clone)]
pub struct Database {
storage: Storage<Self>,
}

impl Default for Database {
fn default() -> Self {
let db = Self {
storage: Storage::default(),
};
Config::new(&db, true);
db
}
}

#[cfg(test)]
pub(crate) fn set_include_builtins(db: &mut dyn Db, include_builtins: bool) {
Config::get(db)
.set_include_builtins(db)
.to(include_builtins);
}

impl salsa::Database for Database {}
6 changes: 3 additions & 3 deletions crates/squawk_ide/src/expand_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,11 @@ mod tests {
fn expand(sql: &str) -> Vec<String> {
let fixture = Fixture::new(sql);
let offset = fixture.marker().offset();
let sql = fixture.file().content(fixture.db()).clone();
let tree = crate::db::parse(fixture.db(), fixture.file()).tree();
let sql = offset.file_id.content(fixture.db()).clone();
let tree = crate::db::parse(fixture.db(), offset.file_id).tree();
let root = tree.syntax();

let mut range = TextRange::empty(offset);
let mut range = TextRange::empty(offset.value);
let mut results = vec![];

for _ in 0..20 {
Expand Down
13 changes: 7 additions & 6 deletions crates/squawk_ide/src/find_references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn find_references(db: &dyn Db, position: InFile<TextSize>) -> Vec<Location>
mod test {
use crate::builtins::builtins_file;
use crate::db::File;
use crate::file::InFile;

use crate::find_references::find_references;
use crate::test_utils::Fixture;
use annotate_snippets::{AnnotationKind, Level, Renderer, Snippet, renderer::DecorStyle};
Expand All @@ -57,9 +57,9 @@ mod test {
let offset = marker.offset_before();
let query_span = marker.range();
let db = fixture.db();
let current_file = fixture.file();
let current_file = offset.file_id;

let references = find_references(db, InFile::new(current_file, offset));
let references = find_references(db, offset);

let mut file_paths = FxHashMap::default();
file_paths.insert(current_file, "current.sql");
Expand Down Expand Up @@ -380,17 +380,18 @@ drop table foo_bar;
#[test]
fn builtin_function_references() {
assert_snapshot!(find_refs("
-- include-builtins
select now$0();
select now();
"), @"
╭▸ current.sql:2:8
╭▸ current.sql:3:8
2 │ select now();
3 │ select now();
│ ┬─┬
│ │ │
│ │ 0. query
│ 1. reference
3 │ select now();
4 │ select now();
│ ─── 2. reference
╰╴

Expand Down
26 changes: 15 additions & 11 deletions crates/squawk_ide/src/goto_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fn find_following_commit_or_rollback(db: &dyn Db, position: InFile<TextSize>) ->
mod test {
use crate::builtins::builtins_file;
use crate::db::File;
use crate::file::InFile;

use crate::goto_definition::goto_definition;
use crate::test_utils::Fixture;
use annotate_snippets::{AnnotationKind, Level, Renderer, Snippet, renderer::DecorStyle};
Expand All @@ -158,9 +158,9 @@ mod test {
let offset = marker.offset_before();
let source_span = marker.range();
let db = fixture.db();
let current_file = fixture.file();
let current_file = offset.file_id;

let results = goto_definition(db, InFile::new(current_file, offset));
let results = goto_definition(db, offset);
if results.is_empty() {
return None;
}
Expand Down Expand Up @@ -866,11 +866,12 @@ alter policy p on t
#[test]
fn goto_builtin_now() {
assert_snapshot!(goto("
-- include-builtins
select now$0();
"), @"
╭▸ current.sql:2:10
╭▸ current.sql:3:10
2 │ select now();
3 │ select now();
│ ─ 1. source
╰╴

Expand All @@ -884,11 +885,12 @@ select now$0();
#[test]
fn goto_current_timestamp() {
assert_snapshot!(goto("
-- include-builtins
select current_timestamp$0;
"), @"
╭▸ current.sql:2:24
╭▸ current.sql:3:24
2 │ select current_timestamp;
3 │ select current_timestamp;
│ ─ 1. source
╰╴

Expand Down Expand Up @@ -1010,12 +1012,13 @@ select current_timestamp$0 from t;
#[test]
fn goto_current_timestamp_in_where() {
assert_snapshot!(goto("
-- include-builtins
create table t(created_at timestamptz);
select * from t where current_timestamp$0 > t.created_at;
"), @"
╭▸ current.sql:3:39
╭▸ current.sql:4:39
3 │ select * from t where current_timestamp > t.created_at;
4 │ select * from t where current_timestamp > t.created_at;
│ ─ 1. source
╰╴

Expand Down Expand Up @@ -2162,13 +2165,14 @@ inherits (foo.bar, bar$0, buzz);
#[test]
fn goto_create_table_inherits_builtin() {
assert_snapshot!(goto("
-- include-builtins
create table t ()
inherits (information_schema.sql_features);
select feature_name$0 from t;
"), @"
╭▸ current.sql:4:19
╭▸ current.sql:5:19
4 │ select feature_name from t;
5 │ select feature_name from t;
│ ─ 1. source
╰╴

Expand Down
Loading
Loading