Skip to content

Commit 71cddbc

Browse files
committed
feat: put db con behind feature gate
1 parent 407a556 commit 71cddbc

File tree

9 files changed

+226
-158
lines changed

9 files changed

+226
-158
lines changed

Cargo.lock

-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pgt_completions/Cargo.toml

+2-14
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,18 @@ name = "pgt_completions"
1010
repository.workspace = true
1111
version = "0.0.0"
1212

13-
1413
[dependencies]
1514
async-std = "1.12.0"
1615

17-
pgt_text_size.workspace = true
18-
19-
2016
pgt_schema_cache.workspace = true
17+
pgt_text_size.workspace = true
2118
pgt_treesitter_queries.workspace = true
22-
schemars = { workspace = true, optional = true }
23-
serde = { workspace = true, features = ["derive"] }
24-
serde_json = { workspace = true }
2519
tree-sitter.workspace = true
2620
tree_sitter_sql.workspace = true
2721

28-
sqlx.workspace = true
29-
30-
tokio = { version = "1.41.1", features = ["full"] }
31-
3222
[dev-dependencies]
3323
pgt_test_utils.workspace = true
24+
tokio = { version = "1.41.1", features = ["full"] }
3425

3526
[lib]
3627
doctest = false
37-
38-
[features]
39-
schema = ["dep:schemars"]

crates/pgt_completions/src/complete.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use pgt_text_size::TextSize;
2-
use serde::{Deserialize, Serialize};
32

43
use crate::{
54
builder::CompletionBuilder,
@@ -18,10 +17,9 @@ pub struct CompletionParams<'a> {
1817
pub tree: Option<&'a tree_sitter::Tree>,
1918
}
2019

21-
#[derive(Debug, Default, Serialize, Deserialize)]
22-
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
20+
#[derive(Debug, Default)]
2321
pub struct CompletionResult {
24-
pub(crate) items: Vec<CompletionItem>,
22+
pub items: Vec<CompletionItem>,
2523
}
2624

2725
impl IntoIterator for CompletionResult {

crates/pgt_completions/src/item.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
use serde::{Deserialize, Serialize};
2-
3-
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
4-
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
5-
#[serde(rename_all = "camelCase")]
1+
#[derive(Debug, PartialEq, Eq)]
62
pub enum CompletionItemKind {
73
Table,
84
Function,
95
Column,
106
}
117

12-
#[derive(Debug, Serialize, Deserialize)]
13-
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
8+
#[derive(Debug)]
149
pub struct CompletionItem {
1510
pub label: String,
16-
pub(crate) score: i32,
11+
pub score: i32,
1712
pub description: String,
1813
pub preselected: bool,
1914
pub kind: CompletionItemKind,

crates/pgt_lsp/src/handlers/completions.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,15 @@ pub fn get_completions(
6262
}
6363

6464
fn to_lsp_types_completion_item_kind(
65-
pg_comp_kind: pgt_completions::CompletionItemKind,
65+
pg_comp_kind: pgt_workspace::workspace::CompletionItemKind,
6666
) -> lsp_types::CompletionItemKind {
6767
match pg_comp_kind {
68-
pgt_completions::CompletionItemKind::Function => lsp_types::CompletionItemKind::FUNCTION,
69-
pgt_completions::CompletionItemKind::Table => lsp_types::CompletionItemKind::CLASS,
70-
pgt_completions::CompletionItemKind::Column => lsp_types::CompletionItemKind::FIELD,
68+
pgt_workspace::workspace::CompletionItemKind::Function => {
69+
lsp_types::CompletionItemKind::FUNCTION
70+
}
71+
pgt_workspace::workspace::CompletionItemKind::Table => lsp_types::CompletionItemKind::CLASS,
72+
pgt_workspace::workspace::CompletionItemKind::Column => {
73+
lsp_types::CompletionItemKind::FIELD
74+
}
7175
}
7276
}

crates/pgt_workspace/Cargo.toml

+7-4
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@ futures = "0.3.31"
1818
ignore = { workspace = true }
1919
pgt_analyse = { workspace = true, features = ["serde"] }
2020
pgt_analyser = { workspace = true }
21-
pgt_completions = { workspace = true }
2221
pgt_configuration = { workspace = true }
2322
pgt_console = { workspace = true }
2423
pgt_diagnostics = { workspace = true }
2524
pgt_fs = { workspace = true, features = ["serde"] }
2625
pgt_query_ext = { workspace = true }
27-
pgt_schema_cache = { workspace = true }
2826
pgt_statement_splitter = { workspace = true }
2927
pgt_text_size.workspace = true
30-
pgt_typecheck = { workspace = true }
3128
rustc-hash = { workspace = true }
3229
schemars = { workspace = true, optional = true }
3330
serde = { workspace = true, features = ["derive"] }
@@ -38,11 +35,18 @@ tracing = { workspace = true, features = ["attributes", "log"]
3835
tree-sitter.workspace = true
3936
tree_sitter_sql.workspace = true
4037

38+
# these dependencies require a database connection
39+
pgt_completions = { workspace = true, optional = true }
40+
pgt_schema_cache = { workspace = true, optional = true }
41+
pgt_typecheck = { workspace = true, optional = true }
42+
4143
biome_js_factory = { workspace = true, optional = true }
4244
biome_js_syntax = { workspace = true, optional = true }
4345
biome_rowan = { workspace = true, optional = true }
4446

4547
[features]
48+
db-connection = ["dep:pgt_completions", "dep:pgt_schema_cache", "dep:pgt_typecheck"]
49+
default = ["db-connection"]
4650
schema = [
4751
"dep:schemars",
4852
"dep:biome_rowan",
@@ -52,7 +56,6 @@ schema = [
5256
"pgt_diagnostics/schema",
5357
"pgt_fs/schema",
5458
"pgt_analyse/schema",
55-
"pgt_completions/schema",
5659
]
5760

5861
[dev-dependencies]

crates/pgt_workspace/src/workspace.rs

+68-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,73 @@ pub struct GetCompletionsParams {
5353
pub position: TextSize,
5454
}
5555

56+
#[derive(Debug, Default, Serialize, Deserialize)]
57+
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
58+
pub struct CompletionResult {
59+
pub(crate) items: Vec<CompletionItem>,
60+
}
61+
62+
#[cfg(feature = "db-connection")]
63+
impl IntoIterator for CompletionResult {
64+
type Item = CompletionItem;
65+
type IntoIter = <Vec<CompletionItem> as IntoIterator>::IntoIter;
66+
fn into_iter(self) -> Self::IntoIter {
67+
self.items.into_iter()
68+
}
69+
}
70+
71+
#[cfg(feature = "db-connection")]
72+
impl From<pgt_completions::CompletionResult> for CompletionResult {
73+
fn from(external: pgt_completions::CompletionResult) -> Self {
74+
CompletionResult {
75+
items: external.items.into_iter().map(Into::into).collect(),
76+
}
77+
}
78+
}
79+
80+
#[cfg(feature = "db-connection")]
81+
impl From<pgt_completions::CompletionItem> for CompletionItem {
82+
fn from(external: pgt_completions::CompletionItem) -> Self {
83+
CompletionItem {
84+
label: external.label,
85+
score: external.score,
86+
description: external.description,
87+
preselected: external.preselected,
88+
kind: external.kind.into(),
89+
}
90+
}
91+
}
92+
93+
#[cfg(feature = "db-connection")]
94+
impl From<pgt_completions::CompletionItemKind> for CompletionItemKind {
95+
fn from(external: pgt_completions::CompletionItemKind) -> Self {
96+
match external {
97+
pgt_completions::CompletionItemKind::Table => CompletionItemKind::Table,
98+
pgt_completions::CompletionItemKind::Function => CompletionItemKind::Function,
99+
pgt_completions::CompletionItemKind::Column => CompletionItemKind::Column,
100+
}
101+
}
102+
}
103+
104+
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
105+
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
106+
#[serde(rename_all = "camelCase")]
107+
pub enum CompletionItemKind {
108+
Table,
109+
Function,
110+
Column,
111+
}
112+
113+
#[derive(Debug, Serialize, Deserialize)]
114+
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
115+
pub struct CompletionItem {
116+
pub label: String,
117+
pub(crate) score: i32,
118+
pub description: String,
119+
pub preselected: bool,
120+
pub kind: CompletionItemKind,
121+
}
122+
56123
#[derive(Debug, serde::Serialize, serde::Deserialize)]
57124
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
58125
pub struct PullDiagnosticsResult {
@@ -118,7 +185,7 @@ pub trait Workspace: Send + Sync + RefUnwindSafe {
118185
fn get_completions(
119186
&self,
120187
params: GetCompletionsParams,
121-
) -> Result<pgt_completions::CompletionResult, WorkspaceError>;
188+
) -> Result<CompletionResult, WorkspaceError>;
122189

123190
/// Update the global settings for this workspace
124191
fn update_settings(&self, params: UpdateSettingsParams) -> Result<(), WorkspaceError>;

crates/pgt_workspace/src/workspace/client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ where
127127
fn get_completions(
128128
&self,
129129
params: super::GetCompletionsParams,
130-
) -> Result<pgt_completions::CompletionResult, WorkspaceError> {
130+
) -> Result<super::CompletionResult, WorkspaceError> {
131131
self.request("pgt/get_completions", params)
132132
}
133133
}

0 commit comments

Comments
 (0)