Skip to content

Commit 79d21e9

Browse files
committed
wasm playground
1 parent 682337b commit 79d21e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1980
-261
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ biome_deserialize_macros = "0.6.0"
2020
biome_string_case = "0.5.8"
2121
bpaf = { version = "0.9.15", features = ["derive"] }
2222
crossbeam = "0.8.4"
23-
enumflags2 = "0.7.10"
23+
enumflags2 = "0.7.11"
2424
ignore = "0.4.23"
2525
indexmap = { version = "2.6.0", features = ["serde"] }
2626
insta = "1.31.0"
@@ -39,7 +39,6 @@ smallvec = { version = "1.13.2", features = ["union", "const_new
3939
sqlx = { version = "0.8.2", features = ["runtime-async-std", "tls-rustls", "postgres", "json"] }
4040
syn = "1.0.109"
4141
termcolor = "1.4.1"
42-
text-size = "1.1.1"
4342
tokio = { version = "1.40.0", features = ["full"] }
4443
toml = "0.8.19"
4544
tower-lsp = "0.20.0"
@@ -75,6 +74,7 @@ pglt_query_proto_parser = { path = "./crates/pglt_query_proto_parser", versi
7574
pglt_schema_cache = { path = "./crates/pglt_schema_cache", version = "0.0.0" }
7675
pglt_statement_splitter = { path = "./crates/pglt_statement_splitter", version = "0.0.0" }
7776
pglt_text_edit = { path = "./crates/pglt_text_edit", version = "0.0.0" }
77+
pglt_text_size = { path = "./crates/pglt_text_size", version = "0.0.0" }
7878
pglt_treesitter_queries = { path = "./crates/pglt_treesitter_queries", version = "0.0.0" }
7979
pglt_type_resolver = { path = "./crates/pglt_type_resolver", version = "0.0.0" }
8080
pglt_typecheck = { path = "./crates/pglt_typecheck", version = "0.0.0" }

crates/pglt_analyse/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ rustc-hash = { workspace = true }
2222
biome_deserialize = { workspace = true, optional = true }
2323
biome_deserialize_macros = { workspace = true, optional = true }
2424
enumflags2.workspace = true
25+
pglt_text_size.workspace = true
2526
schemars = { workspace = true, optional = true }
2627
serde = { workspace = true, features = ["derive"], optional = true }
27-
text-size.workspace = true
2828

2929
[features]
3030
serde = ["dep:serde", "dep:schemars", "dep:biome_deserialize", "dep:biome_deserialize_macros"]

crates/pglt_analyse/src/rule.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use pglt_diagnostics::{
55
Advices, Category, Diagnostic, DiagnosticTags, Location, LogCategory, MessageAndDescription,
66
Visit,
77
};
8+
use pglt_text_size::TextRange;
89
use std::cmp::Ordering;
910
use std::fmt::Debug;
10-
use text_size::TextRange;
1111

1212
use crate::{categories::RuleCategory, context::RuleContext, registry::RegistryVisitor};
1313

crates/pglt_cli/src/execute/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,6 @@ pub enum TraversalMode {
8585
Dummy,
8686
/// This mode is enabled when running the command `check`
8787
Check {
88-
/// The type of fixes that should be applied when analyzing a file.
89-
///
90-
/// It's [None] if the `check` command is called without `--apply` or `--apply-suggested`
91-
/// arguments.
92-
// fix_file_mode: Option<FixFileMode>,
93-
9488
/// An optional tuple.
9589
/// 1. The virtual path to the file
9690
/// 2. The content of the file

crates/pglt_commands/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ version = "0.0.0"
1212

1313

1414
[dependencies]
15-
anyhow = "1.0.62"
16-
async-std = "1.12.0"
17-
sqlx.workspace = true
18-
text-size.workspace = true
15+
anyhow = "1.0.62"
16+
async-std = "1.12.0"
17+
pglt_text_size.workspace = true
18+
sqlx.workspace = true
1919

2020
[lib]
2121
doctest = false

crates/pglt_completions/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ version = "0.0.0"
1414
[dependencies]
1515
async-std = "1.12.0"
1616

17-
text-size.workspace = true
17+
pglt_text_size.workspace = true
1818

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
@@ -35,3 +36,4 @@ pglt_test_utils.workspace = true
3536
doctest = false
3637

3738
[features]
39+
schema = ["dep:schemars"]

crates/pglt_completions/src/complete.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use pglt_text_size::TextSize;
12
use serde::{Deserialize, Serialize};
2-
use text_size::TextSize;
33

44
use crate::{
55
builder::CompletionBuilder,
@@ -18,7 +18,8 @@ pub struct CompletionParams<'a> {
1818
pub tree: Option<&'a tree_sitter::Tree>,
1919
}
2020

21-
#[derive(Debug, Default, Serialize, Deserialize)]
21+
#[derive(Debug, Default, Deserialize, Serialize)]
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
use serde::{Deserialize, Serialize};
22

33
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
4+
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
45
pub enum CompletionItemKind {
56
Table,
67
Function,
78
Column,
89
}
910

1011
#[derive(Debug, Serialize, Deserialize)]
12+
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1113
pub struct CompletionItem {
1214
pub label: String,
1315
pub(crate) score: i32,

crates/pglt_configuration/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ pglt_analyse = { workspace = true }
2020
pglt_analyser = { workspace = true }
2121
pglt_console = { workspace = true }
2222
pglt_diagnostics = { workspace = true }
23+
pglt_text_size = { workspace = true }
2324
rustc-hash = { workspace = true }
2425
schemars = { workspace = true, features = ["indexmap1"], optional = true }
2526
serde = { workspace = true, features = ["derive"] }
2627
serde_json = { workspace = true, features = ["raw_value"] }
27-
text-size = { workspace = true }
2828
toml = { workspace = true }
2929

3030
[lib]

crates/pglt_console/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ version = "0.0.0"
1212

1313

1414
[dependencies]
15-
pglt_markup = { workspace = true }
16-
text-size = { workspace = true }
15+
pglt_markup = { workspace = true }
16+
pglt_text_size = { workspace = true }
1717

1818
schemars = { workspace = true, optional = true }
1919
serde = { workspace = true, optional = true, features = ["derive"] }

crates/pglt_console/src/markup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::{
44
io,
55
};
66

7+
use pglt_text_size::TextSize;
78
use termcolor::{Color, ColorSpec};
8-
use text_size::TextSize;
99

1010
use crate::fmt::{Display, Formatter, MarkupElements, Write};
1111

crates/pglt_diagnostics/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ version = "0.0.0"
1414
[dependencies]
1515
backtrace = "0.3.74"
1616
bpaf = { workspace = true }
17-
enumflags2 = { workspace = true }
17+
enumflags2 = { workspace = true, features = ["serde"] }
1818
pglt_console = { workspace = true, features = ["serde_markup"] }
1919
pglt_diagnostics_categories = { workspace = true, features = ["serde"] }
2020
pglt_diagnostics_macros = { workspace = true }
2121
pglt_text_edit = { workspace = true }
22+
pglt_text_size.workspace = true
2223
schemars = { workspace = true, optional = true }
2324
serde = { workspace = true, features = ["derive"] }
2425
serde_json = { workspace = true }
2526
termcolor = { workspace = true }
26-
text-size.workspace = true
2727
unicode-width = { workspace = true }
2828

2929
[features]

crates/pglt_diagnostics/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ mod internal {
251251

252252
use pglt_console::{fmt, markup};
253253
use pglt_text_edit::TextEdit;
254-
use text_size::TextRange;
254+
use pglt_text_size::TextRange;
255255

256256
use crate::{
257257
Advices, Backtrace, Category, Diagnostic, DiagnosticTags, LineIndex, LineIndexBuf,

crates/pglt_diagnostics/src/diagnostic.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ pub trait Diagnostic: Debug {
117117
#[derive(
118118
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Default,
119119
)]
120-
#[serde(rename_all = "snake_case")]
120+
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
121+
#[serde(rename_all = "camelCase")]
121122
/// The severity to associate to a diagnostic.
122123
pub enum Severity {
123124
/// Reports a hint.
@@ -164,6 +165,7 @@ impl Display for Severity {
164165
/// Internal enum used to automatically generate bit offsets for [DiagnosticTags]
165166
/// and help with the implementation of `serde` and `schemars` for tags.
166167
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
168+
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
167169
#[serde(rename_all = "snake_case")]
168170
#[bitflags]
169171
#[repr(u8)]

crates/pglt_diagnostics/src/display.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,8 @@ mod tests {
669669
use pglt_diagnostics::{DiagnosticTags, Severity};
670670
use pglt_diagnostics_categories::{Category, category};
671671
use pglt_text_edit::TextEdit;
672+
use pglt_text_size::{TextRange, TextSize};
672673
use serde_json::{from_value, json};
673-
use text_size::{TextRange, TextSize};
674674

675675
use crate::{self as pglt_diagnostics};
676676
use crate::{

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(generator: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
101+
<Vec<SerializedFrame>>::json_schema(generator)
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/display/frame.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{
77
};
88

99
use pglt_console::{fmt, markup};
10-
use text_size::{TextLen, TextRange, TextSize};
10+
use pglt_text_size::{TextLen, TextRange, TextSize};
1111
use unicode_width::UnicodeWidthChar;
1212

1313
use crate::{

crates/pglt_diagnostics/src/display_github.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::display::frame::SourceFile;
22
use crate::{Diagnostic, Resource, Severity, diagnostic::internal::AsDiagnostic};
33
use pglt_console::{MarkupBuf, fmt, markup};
4+
use pglt_text_size::{TextRange, TextSize};
45
use std::io;
5-
use text_size::{TextRange, TextSize};
66

77
/// Helper struct for printing a diagnostic as markup into any formatter
88
/// implementing [pglt_console::fmt::Write].

crates/pglt_diagnostics/src/location.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
use pglt_text_size::{TextRange, TextSize};
12
use serde::{Deserialize, Serialize};
23
use std::fmt::Debug;
34
use std::ops::Range;
45
use std::{borrow::Borrow, ops::Deref};
5-
use text_size::{TextRange, TextSize};
66

77
/// Represents the location of a diagnostic in a resource.
88
#[derive(Debug, Default, Clone, Copy)]
@@ -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 = "snake_case")]
4344
pub enum Resource<P> {
4445
/// The diagnostic is related to the content of the command line arguments.
@@ -343,7 +344,7 @@ impl AsSourceCode for String {
343344

344345
#[cfg(test)]
345346
mod tests {
346-
use text_size::TextSize;
347+
use pglt_text_size::TextSize;
347348

348349
use super::LineIndexBuf;
349350

crates/pglt_diagnostics/src/serde.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use std::io;
22

33
use pglt_console::{MarkupBuf, fmt, markup};
44
use pglt_text_edit::TextEdit;
5+
use pglt_text_size::{TextRange, TextSize};
56
use serde::{
67
Deserialize, Deserializer, Serialize, Serializer,
78
de::{self, SeqAccess},
89
};
9-
use text_size::{TextRange, TextSize};
1010

1111
use crate::{
1212
Advices as _, Backtrace, Category, DiagnosticTags, LogCategory, Resource, Severity, SourceCode,
@@ -15,7 +15,7 @@ use crate::{
1515

1616
/// Serializable representation for a [Diagnostic](super::Diagnostic).
1717
#[derive(Clone, Debug, Serialize, Deserialize)]
18-
#[cfg_attr(not(target_arch = "wasm32"), serde(rename_all = "snake_case"))]
18+
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1919
#[cfg_attr(test, derive(Eq, PartialEq))]
2020
pub struct Diagnostic {
2121
category: Option<&'static Category>,
@@ -137,7 +137,7 @@ impl<D: super::Diagnostic + ?Sized> std::fmt::Display for PrintDescription<'_, D
137137
}
138138

139139
#[derive(Clone, Debug, Serialize, Deserialize)]
140-
#[cfg_attr(not(target_arch = "wasm32"), serde(rename_all = "snake_case"))]
140+
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
141141
#[cfg_attr(test, derive(Eq, PartialEq))]
142142
struct Location {
143143
path: Option<Resource<String>>,
@@ -159,7 +159,7 @@ impl From<super::Location<'_>> for Location {
159159

160160
/// Implementation of [Visitor] collecting serializable [Advice] into a vector.
161161
#[derive(Clone, Debug, Serialize, Deserialize)]
162-
#[serde(rename_all = "snake_case")]
162+
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
163163
#[cfg_attr(test, derive(Eq, PartialEq))]
164164
struct Advices {
165165
advices: Vec<Advice>,
@@ -245,7 +245,7 @@ impl super::Advices for Advices {
245245
/// See the [Visitor] trait for additional documentation on all the supported
246246
/// advice types.
247247
#[derive(Clone, Debug, Serialize, Deserialize)]
248-
#[serde(rename_all = "snake_case")]
248+
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
249249
#[cfg_attr(test, derive(Eq, PartialEq))]
250250
enum Advice {
251251
Log(LogCategory, MarkupBuf),
@@ -354,12 +354,23 @@ impl<'de> Deserialize<'de> for DiagnosticTags {
354354
}
355355
}
356356

357+
#[cfg(feature = "schema")]
358+
impl schemars::JsonSchema for DiagnosticTags {
359+
fn schema_name() -> String {
360+
String::from("DiagnosticTags")
361+
}
362+
363+
fn json_schema(generator: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
364+
<Vec<DiagnosticTag>>::json_schema(generator)
365+
}
366+
}
367+
357368
#[cfg(test)]
358369
mod tests {
359370
use std::io;
360371

372+
use pglt_text_size::{TextRange, TextSize};
361373
use serde_json::{Value, json};
362-
use text_size::{TextRange, TextSize};
363374

364375
use crate::{
365376
self as pglt_diagnostics, {Advices, LogCategory, Visit},

crates/pglt_diagnostics/src/suggestion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use ::serde::{Deserialize, Serialize};
22
use pglt_console::MarkupBuf;
33
use pglt_text_edit::TextEdit;
4-
use text_size::TextRange;
4+
use pglt_text_size::TextRange;
55

66
/// Indicates how a tool should manage this suggestion.
77
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]

crates/pglt_lexer/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pg_query.workspace = true
1818
pglt_diagnostics.workspace = true
1919
pglt_lexer_codegen.workspace = true
2020

21-
text-size.workspace = true
21+
pglt_text_size.workspace = true
2222

2323
[dev-dependencies]
2424
insta.workspace = true

0 commit comments

Comments
 (0)