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
36 changes: 28 additions & 8 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,15 @@ jobs:
sleep 1
done

- uses: tree-sitter/setup-action@v2
- uses: actions/cache@v5
with:
install-lib: false
path: |
~/.cargo/bin/tree-sitter
~/.cargo/bin/sqlx
key: ${{ runner.os }}-tree-sitter-${{ hashFiles('rust-toolchain.toml') }}

- name: Setup tree-sitter
run: cargo install tree-sitter-cli

- name: Setup sqlx-cli
run: cargo install sqlx-cli
Expand Down Expand Up @@ -160,6 +166,7 @@ jobs:
uses: actions/checkout@v4
with:
submodules: true

- name: Free Disk Space
uses: ./.github/actions/free-disk-space
- name: Install toolchain
Expand All @@ -172,9 +179,14 @@ jobs:
- name: Setup Postgres
uses: ./.github/actions/setup-postgres

- uses: tree-sitter/setup-action@v2
- uses: actions/cache@v5
with:
install-lib: false
path: |
~/.cargo/bin/tree-sitter
key: ${{ runner.os }}-tree-sitter-${{ hashFiles('rust-toolchain.toml') }}

- name: Setup Postgres
run: cargo install tree-sitter-cli

- name: Run tests
run: cargo test --workspace
Expand Down Expand Up @@ -204,9 +216,13 @@ jobs:
uses: moonrepo/setup-rust@v1
with:
cache-base: main
- uses: tree-sitter/setup-action@v2
- uses: actions/cache@v5
with:
install-lib: false
path: |
~/.cargo/bin/tree-sitter
key: ${{ runner.os }}-tree-sitter-${{ hashFiles('rust-toolchain.toml') }}
- name: setup tree-sitter
run: cargo install tree-sitter-cli
- name: Build main binary
run: cargo build -p pgls_cli --release
- name: Setup Bun
Expand Down Expand Up @@ -259,9 +275,13 @@ jobs:
cache-base: main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: tree-sitter/setup-action@v2
- uses: actions/cache@v5
with:
install-lib: false
path: |
~/.cargo/bin/tree-sitter
key: ${{ runner.os }}-tree-sitter-${{ hashFiles('rust-toolchain.toml') }}
- name: setup tree-sitter
run: cargo install tree-sitter-cli
- name: Ensure RustFMT on nightly toolchain
run: rustup component add rustfmt --toolchain nightly
- name: echo toolchain
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,14 @@ jobs:
sudo apt-get update
sudo apt-get install -y musl-tools

- uses: tree-sitter/setup-action@v2
- uses: actions/cache@v5
with:
install-lib: false
path: |
~/.cargo/bin/tree-sitter
key: ${{ runner.os }}-tree-sitter-${{ hashFiles('rust-toolchain.toml') }}

- name: Setup tree-sitter
run: cargo install tree-sitter-cli

- name: Setup Postgres
uses: ./.github/actions/setup-postgres
Expand Down

This file was deleted.

10 changes: 6 additions & 4 deletions crates/pgls_lsp/src/handlers/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ pub fn get_completions(
let doc = session.document(&url)?;
let encoding = adapters::negotiated_encoding(session.client_capabilities().unwrap());

let completion_result = match session.workspace.get_completions(GetCompletionsParams {
path,
position: get_cursor_position(session, &url, params.text_document_position.position)?,
}) {
let position = get_cursor_position(session, &url, params.text_document_position.position)?;

let completion_result = match session
.workspace
.get_completions(GetCompletionsParams { path, position })
{
Ok(result) => result,
Err(e) => match e {
WorkspaceError::DatabaseConnectionError(_) => {
Expand Down
12 changes: 12 additions & 0 deletions crates/pgls_workspace/src/features/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ pub struct CompletionsResult {
pub(crate) items: Vec<CompletionItem>,
}

impl CompletionsResult {
pub fn with_offset(mut items: Vec<CompletionItem>, offset: TextSize) -> Self {
for item in &mut items {
if let Some(text_edit) = &mut item.completion_text {
text_edit.range += offset;
}
}

Self { items }
}
}

impl IntoIterator for CompletionsResult {
type Item = CompletionItem;
type IntoIter = <Vec<CompletionItem> as IntoIterator>::IntoIter;
Expand Down
2 changes: 1 addition & 1 deletion crates/pgls_workspace/src/workspace/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ impl Workspace for WorkspaceServer {
text: id.content().to_string(),
});

Ok(CompletionsResult { items })
Ok(CompletionsResult::with_offset(items, range.start()))
}
}
}
Expand Down
76 changes: 76 additions & 0 deletions crates/pgls_workspace/src/workspace/server.tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,3 +793,79 @@ async fn test_search_path_configuration(test_db: PgPool) {
);
}
}

#[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")]
async fn test_multi_line_completions(test_db: PgPool) {
let setup = r#"
create schema auth;

create table auth.users (
id serial primary key,
email text not null
);
"#;

test_db.execute(setup).await.expect("setup sql failed");

let mut conf = PartialConfiguration::init();
conf.merge_with(PartialConfiguration {
db: Some(PartialDatabaseConfiguration {
database: Some(
test_db
.connect_options()
.get_database()
.unwrap()
.to_string(),
),
..Default::default()
}),
..Default::default()
});

let workspace = get_test_workspace(Some(conf)).expect("Unable to create test workspace");

let path = PgLSPath::new("test.sql");

let content = r#"
select * from auth.users;

select * from auth.|;

select * from auth.users;
"#
.trim();

let position = content
.find('|')
.map(|idx| pgls_text_size::TextSize::new(idx as u32))
.expect("Unable to find cursor position in test content");

let sanitized_content = content.replace('|', "");

workspace
.open_file(OpenFileParams {
path: path.clone(),
content: sanitized_content,
version: 1,
})
.expect("Unable to open test file");

let completions = workspace
.get_completions(crate::workspace::GetCompletionsParams {
path: path.clone(),
position,
})
.expect("Unable to request completions");

assert_eq!(
completions.items.len(),
1,
"Expected one completion response"
);

assert_eq!(
completions.items[0].completion_text.as_ref().unwrap().range,
TextRange::new(position, position),
"Expected no syntax diagnostic"
);
}