Skip to content

feat: put db con behind feature gate #268

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 0 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 2 additions & 14 deletions crates/pgt_completions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,18 @@ name = "pgt_completions"
repository.workspace = true
version = "0.0.0"


[dependencies]
async-std = "1.12.0"

pgt_text_size.workspace = true


pgt_schema_cache.workspace = true
pgt_text_size.workspace = true
pgt_treesitter_queries.workspace = true
schemars = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
tree-sitter.workspace = true
tree_sitter_sql.workspace = true

sqlx.workspace = true

tokio = { version = "1.41.1", features = ["full"] }

[dev-dependencies]
pgt_test_utils.workspace = true
tokio = { version = "1.41.1", features = ["full"] }

[lib]
doctest = false

[features]
schema = ["dep:schemars"]
6 changes: 2 additions & 4 deletions crates/pgt_completions/src/complete.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use pgt_text_size::TextSize;
use serde::{Deserialize, Serialize};

use crate::{
builder::CompletionBuilder,
Expand All @@ -18,10 +17,9 @@ pub struct CompletionParams<'a> {
pub tree: Option<&'a tree_sitter::Tree>,
}

#[derive(Debug, Default, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Default)]
pub struct CompletionResult {
pub(crate) items: Vec<CompletionItem>,
pub items: Vec<CompletionItem>,
}

impl IntoIterator for CompletionResult {
Expand Down
11 changes: 3 additions & 8 deletions crates/pgt_completions/src/item.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase")]
#[derive(Debug, PartialEq, Eq)]
pub enum CompletionItemKind {
Table,
Function,
Column,
}

#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug)]
pub struct CompletionItem {
pub label: String,
pub(crate) score: i32,
pub score: i32,
pub description: String,
pub preselected: bool,
pub kind: CompletionItemKind,
Expand Down
12 changes: 8 additions & 4 deletions crates/pgt_lsp/src/handlers/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ pub fn get_completions(
}

fn to_lsp_types_completion_item_kind(
pg_comp_kind: pgt_completions::CompletionItemKind,
pg_comp_kind: pgt_workspace::workspace::CompletionItemKind,
) -> lsp_types::CompletionItemKind {
match pg_comp_kind {
pgt_completions::CompletionItemKind::Function => lsp_types::CompletionItemKind::FUNCTION,
pgt_completions::CompletionItemKind::Table => lsp_types::CompletionItemKind::CLASS,
pgt_completions::CompletionItemKind::Column => lsp_types::CompletionItemKind::FIELD,
pgt_workspace::workspace::CompletionItemKind::Function => {
lsp_types::CompletionItemKind::FUNCTION
}
pgt_workspace::workspace::CompletionItemKind::Table => lsp_types::CompletionItemKind::CLASS,
pgt_workspace::workspace::CompletionItemKind::Column => {
lsp_types::CompletionItemKind::FIELD
}
}
}
11 changes: 7 additions & 4 deletions crates/pgt_workspace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@ futures = "0.3.31"
ignore = { workspace = true }
pgt_analyse = { workspace = true, features = ["serde"] }
pgt_analyser = { workspace = true }
pgt_completions = { workspace = true }
pgt_configuration = { workspace = true }
pgt_console = { workspace = true }
pgt_diagnostics = { workspace = true }
pgt_fs = { workspace = true, features = ["serde"] }
pgt_query_ext = { workspace = true }
pgt_schema_cache = { workspace = true }
pgt_statement_splitter = { workspace = true }
pgt_text_size.workspace = true
pgt_typecheck = { workspace = true }
rustc-hash = { workspace = true }
schemars = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"] }
Expand All @@ -38,11 +35,18 @@ tracing = { workspace = true, features = ["attributes", "log"]
tree-sitter.workspace = true
tree_sitter_sql.workspace = true

# these dependencies require a database connection
pgt_completions = { workspace = true, optional = true }
pgt_schema_cache = { workspace = true, optional = true }
pgt_typecheck = { workspace = true, optional = true }

biome_js_factory = { workspace = true, optional = true }
biome_js_syntax = { workspace = true, optional = true }
biome_rowan = { workspace = true, optional = true }

[features]
db-connection = ["dep:pgt_completions", "dep:pgt_schema_cache", "dep:pgt_typecheck"]
default = ["db-connection"]
schema = [
"dep:schemars",
"dep:biome_rowan",
Expand All @@ -52,7 +56,6 @@ schema = [
"pgt_diagnostics/schema",
"pgt_fs/schema",
"pgt_analyse/schema",
"pgt_completions/schema",
]

[dev-dependencies]
Expand Down
69 changes: 68 additions & 1 deletion crates/pgt_workspace/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,73 @@ pub struct GetCompletionsParams {
pub position: TextSize,
}

#[derive(Debug, Default, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct CompletionResult {
pub(crate) items: Vec<CompletionItem>,
}

#[cfg(feature = "db-connection")]
impl IntoIterator for CompletionResult {
type Item = CompletionItem;
type IntoIter = <Vec<CompletionItem> as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
self.items.into_iter()
}
}

#[cfg(feature = "db-connection")]
impl From<pgt_completions::CompletionResult> for CompletionResult {
fn from(external: pgt_completions::CompletionResult) -> Self {
CompletionResult {
items: external.items.into_iter().map(Into::into).collect(),
}
}
}

#[cfg(feature = "db-connection")]
impl From<pgt_completions::CompletionItem> for CompletionItem {
fn from(external: pgt_completions::CompletionItem) -> Self {
CompletionItem {
label: external.label,
score: external.score,
description: external.description,
preselected: external.preselected,
kind: external.kind.into(),
}
}
}

#[cfg(feature = "db-connection")]
impl From<pgt_completions::CompletionItemKind> for CompletionItemKind {
fn from(external: pgt_completions::CompletionItemKind) -> Self {
match external {
pgt_completions::CompletionItemKind::Table => CompletionItemKind::Table,
pgt_completions::CompletionItemKind::Function => CompletionItemKind::Function,
pgt_completions::CompletionItemKind::Column => CompletionItemKind::Column,
}
}
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase")]
pub enum CompletionItemKind {
Table,
Function,
Column,
}

#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct CompletionItem {
pub label: String,
pub(crate) score: i32,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: do we even need the score here?

pub description: String,
pub preselected: bool,
pub kind: CompletionItemKind,
}

#[derive(Debug, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct PullDiagnosticsResult {
Expand Down Expand Up @@ -118,7 +185,7 @@ pub trait Workspace: Send + Sync + RefUnwindSafe {
fn get_completions(
&self,
params: GetCompletionsParams,
) -> Result<pgt_completions::CompletionResult, WorkspaceError>;
) -> Result<CompletionResult, WorkspaceError>;

/// Update the global settings for this workspace
fn update_settings(&self, params: UpdateSettingsParams) -> Result<(), WorkspaceError>;
Expand Down
2 changes: 1 addition & 1 deletion crates/pgt_workspace/src/workspace/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ where
fn get_completions(
&self,
params: super::GetCompletionsParams,
) -> Result<pgt_completions::CompletionResult, WorkspaceError> {
) -> Result<super::CompletionResult, WorkspaceError> {
self.request("pgt/get_completions", params)
}
}
Loading
Loading