Skip to content

Commit 4f6a06c

Browse files
committed
feat: wasm attempt 2
1 parent 1e42b89 commit 4f6a06c

File tree

21 files changed

+964
-96
lines changed

21 files changed

+964
-96
lines changed

Cargo.lock

Lines changed: 70 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ rust-version = "1.85.0"
1717
anyhow = "1.0.92"
1818
biome_deserialize = "0.6.0"
1919
biome_deserialize_macros = "0.6.0"
20+
biome_js_factory = "0.5.7"
21+
biome_js_syntax = "0.5.7"
22+
biome_rowan = "0.5.7"
2023
biome_string_case = "0.5.8"
2124
bpaf = { version = "0.9.15", features = ["derive"] }
2225
crossbeam = "0.8.4"
23-
enumflags2 = "0.7.10"
26+
enumflags2 = "0.7.11"
2427
ignore = "0.4.23"
2528
indexmap = { version = "2.6.0", features = ["serde"] }
2629
insta = "1.31.0"
@@ -39,7 +42,6 @@ sqlx = { version = "0.8.2", features = ["runtime-async-std",
3942
syn = "1.0.109"
4043
termcolor = "1.4.1"
4144
tokio = { version = "1.40.0", features = ["full"] }
42-
toml = "0.8.19"
4345
tower-lsp = "0.20.0"
4446
tracing = { version = "0.1.40", default-features = false, features = ["std"] }
4547
tracing-subscriber = "0.3.18"

crates/pglt_completions/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pglt_text_size.workspace = true
1919

2020
pglt_schema_cache.workspace = true
2121
pglt_treesitter_queries.workspace = true
22+
schemars = { workspace = true, optional = true }
2223
serde = { workspace = true, features = ["derive"] }
2324
serde_json = { workspace = true }
2425
tree-sitter.workspace = true
@@ -33,3 +34,6 @@ pglt_test_utils.workspace = true
3334

3435
[lib]
3536
doctest = false
37+
38+
[features]
39+
schema = ["dep:schemars"]

crates/pglt_completions/src/complete.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub struct CompletionParams<'a> {
1919
}
2020

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

crates/pglt_completions/src/item.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
use serde::{Deserialize, Serialize};
22

33
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
4+
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
5+
#[serde(rename_all = "camelCase")]
46
pub enum CompletionItemKind {
57
Table,
68
Function,
79
Column,
810
}
911

1012
#[derive(Debug, Serialize, Deserialize)]
13+
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1114
pub struct CompletionItem {
1215
pub label: String,
1316
pub(crate) score: i32,

crates/pglt_diagnostics/src/diagnostic.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ pub trait Diagnostic: Debug {
118118
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Default,
119119
)]
120120
#[serde(rename_all = "camelCase")]
121+
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
121122
/// The severity to associate to a diagnostic.
122123
pub enum Severity {
123124
/// Reports a hint.
@@ -165,6 +166,7 @@ impl Display for Severity {
165166
/// and help with the implementation of `serde` and `schemars` for tags.
166167
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
167168
#[serde(rename_all = "camelCase")]
169+
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
168170
#[bitflags]
169171
#[repr(u8)]
170172
pub(super) enum DiagnosticTag {

crates/pglt_diagnostics/src/display/backtrace.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ impl<'de> serde::Deserialize<'de> for Backtrace {
9191
}
9292
}
9393

94+
#[cfg(feature = "schema")]
95+
impl schemars::JsonSchema for Backtrace {
96+
fn schema_name() -> String {
97+
String::from("Backtrace")
98+
}
99+
100+
fn json_schema(r#gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
101+
<Vec<SerializedFrame>>::json_schema(r#gen)
102+
}
103+
}
104+
94105
/// Internal representation of a [Backtrace], can be either a native backtrace
95106
/// instance or a vector of serialized frames.
96107
#[derive(Clone, Debug)]
@@ -292,6 +303,11 @@ pub(super) fn print_backtrace(
292303

293304
/// Serializable representation of a backtrace frame.
294305
#[derive(Clone, Debug, Serialize, Deserialize)]
306+
#[cfg_attr(
307+
feature = "schema",
308+
derive(schemars::JsonSchema),
309+
schemars(rename = "BacktraceFrame")
310+
)]
295311
#[cfg_attr(test, derive(Eq, PartialEq))]
296312
struct SerializedFrame {
297313
ip: u64,
@@ -309,6 +325,11 @@ impl From<&'_ backtrace::BacktraceFrame> for SerializedFrame {
309325

310326
/// Serializable representation of a backtrace frame symbol.
311327
#[derive(Clone, Debug, Serialize, Deserialize)]
328+
#[cfg_attr(
329+
feature = "schema",
330+
derive(schemars::JsonSchema),
331+
schemars(rename = "BacktraceSymbol")
332+
)]
312333
#[cfg_attr(test, derive(Eq, PartialEq))]
313334
struct SerializedSymbol {
314335
name: Option<String>,

crates/pglt_diagnostics/src/location.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl Eq for Location<'_> {}
3939

4040
/// Represents the resource a diagnostic is associated with.
4141
#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)]
42+
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
4243
#[serde(rename_all = "camelCase")]
4344
pub enum Resource<P> {
4445
/// The diagnostic is related to the content of the command line arguments.

crates/pglt_diagnostics/src/serde.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::{
1616
/// Serializable representation for a [Diagnostic](super::Diagnostic).
1717
#[derive(Clone, Debug, Serialize, Deserialize)]
1818
#[cfg_attr(not(target_arch = "wasm32"), serde(rename_all = "camelCase"))]
19+
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1920
#[cfg_attr(test, derive(Eq, PartialEq))]
2021
pub struct Diagnostic {
2122
category: Option<&'static Category>,
@@ -138,6 +139,7 @@ impl<D: super::Diagnostic + ?Sized> std::fmt::Display for PrintDescription<'_, D
138139

139140
#[derive(Clone, Debug, Serialize, Deserialize)]
140141
#[cfg_attr(not(target_arch = "wasm32"), serde(rename_all = "camelCase"))]
142+
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
141143
#[cfg_attr(test, derive(Eq, PartialEq))]
142144
struct Location {
143145
path: Option<Resource<String>>,
@@ -160,6 +162,7 @@ impl From<super::Location<'_>> for Location {
160162
/// Implementation of [Visitor] collecting serializable [Advice] into a vector.
161163
#[derive(Clone, Debug, Serialize, Deserialize)]
162164
#[serde(rename_all = "camelCase")]
165+
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
163166
#[cfg_attr(test, derive(Eq, PartialEq))]
164167
struct Advices {
165168
advices: Vec<Advice>,
@@ -246,6 +249,7 @@ impl super::Advices for Advices {
246249
/// advice types.
247250
#[derive(Clone, Debug, Serialize, Deserialize)]
248251
#[serde(rename_all = "camelCase")]
252+
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
249253
#[cfg_attr(test, derive(Eq, PartialEq))]
250254
enum Advice {
251255
Log(LogCategory, MarkupBuf),
@@ -354,6 +358,17 @@ impl<'de> Deserialize<'de> for DiagnosticTags {
354358
}
355359
}
356360

361+
#[cfg(feature = "schema")]
362+
impl schemars::JsonSchema for DiagnosticTags {
363+
fn schema_name() -> String {
364+
String::from("DiagnosticTags")
365+
}
366+
367+
fn json_schema(r#gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
368+
<Vec<DiagnosticTag>>::json_schema(r#gen)
369+
}
370+
}
371+
357372
#[cfg(test)]
358373
mod tests {
359374
use std::io;

crates/pglt_lsp/src/handlers/completions.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,23 @@ pub fn get_completions(
2626
pglt_lsp_converters::negotiated_encoding(client_capabilities),
2727
)?;
2828

29-
let completion_result = match session
30-
.workspace
31-
.get_completions(workspace::CompletionParams {
32-
path,
33-
position: offset,
34-
}) {
35-
Ok(result) => result,
36-
Err(e) => match e {
37-
WorkspaceError::DatabaseConnectionError(_) => {
38-
return Ok(lsp_types::CompletionResponse::Array(vec![]));
39-
}
40-
_ => {
41-
return Err(e.into());
42-
}
43-
},
44-
};
29+
let completion_result =
30+
match session
31+
.workspace
32+
.get_completions(workspace::GetCompletionsParams {
33+
path,
34+
position: offset,
35+
}) {
36+
Ok(result) => result,
37+
Err(e) => match e {
38+
WorkspaceError::DatabaseConnectionError(_) => {
39+
return Ok(lsp_types::CompletionResponse::Array(vec![]));
40+
}
41+
_ => {
42+
return Err(e.into());
43+
}
44+
},
45+
};
4546

4647
let items: Vec<CompletionItem> = completion_result
4748
.into_iter()

crates/pglt_wasm/Cargo.toml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
[package]
3+
authors.workspace = true
4+
categories.workspace = true
5+
description = "<DESCRIPTION>"
6+
edition.workspace = true
7+
homepage.workspace = true
8+
keywords.workspace = true
9+
license.workspace = true
10+
name = "pglt_wasm"
11+
repository.workspace = true
12+
version = "0.0.0"
13+
14+
[dependencies]
15+
js-sys = "0.3.72"
16+
pglt_console = { workspace = true }
17+
pglt_diagnostics = { workspace = true }
18+
pglt_workspace = { workspace = true }
19+
serde = { workspace = true }
20+
serde-wasm-bindgen = "0.6.5"
21+
wasm-bindgen = { version = "0.2.95", features = ["serde-serialize"] }
22+
23+
# The `console_error_panic_hook` crate provides better debugging of panics by
24+
# logging them with `console.error`. This is great for development, but requires
25+
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
26+
# code size when deploying.
27+
console_error_panic_hook = { version = "0.1.7", optional = true }
28+
29+
[build-dependencies]
30+
biome_js_factory = { workspace = true }
31+
biome_rowan = { workspace = true }
32+
pglt_workspace = { workspace = true, features = ["schema"] }
33+
quote = "1.0.14"
34+
35+
[package.metadata.wasm-pack.profile.profiling]
36+
wasm-opt = false

0 commit comments

Comments
 (0)