Skip to content

wasm draft #234

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

Closed
wants to merge 3 commits into from
Closed
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
704 changes: 555 additions & 149 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ biome_deserialize_macros = "0.6.0"
biome_string_case = "0.5.8"
bpaf = { version = "0.9.15", features = ["derive"] }
crossbeam = "0.8.4"
enumflags2 = "0.7.10"
enumflags2 = "0.7.11"
ignore = "0.4.23"
indexmap = { version = "2.6.0", features = ["serde"] }
insta = "1.31.0"
Expand All @@ -39,7 +39,6 @@ smallvec = { version = "1.13.2", features = ["union", "const_new
sqlx = { version = "0.8.2", features = ["runtime-async-std", "tls-rustls", "postgres", "json"] }
syn = "1.0.109"
termcolor = "1.4.1"
text-size = "1.1.1"
tokio = { version = "1.40.0", features = ["full"] }
toml = "0.8.19"
tower-lsp = "0.20.0"
Expand Down Expand Up @@ -75,6 +74,7 @@ pglt_query_proto_parser = { path = "./crates/pglt_query_proto_parser", versi
pglt_schema_cache = { path = "./crates/pglt_schema_cache", version = "0.0.0" }
pglt_statement_splitter = { path = "./crates/pglt_statement_splitter", version = "0.0.0" }
pglt_text_edit = { path = "./crates/pglt_text_edit", version = "0.0.0" }
pglt_text_size = { path = "./crates/pglt_text_size", version = "0.0.0" }
pglt_treesitter_queries = { path = "./crates/pglt_treesitter_queries", version = "0.0.0" }
pglt_type_resolver = { path = "./crates/pglt_type_resolver", version = "0.0.0" }
pglt_typecheck = { path = "./crates/pglt_typecheck", version = "0.0.0" }
Expand Down
2 changes: 1 addition & 1 deletion crates/pglt_analyse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ rustc-hash = { workspace = true }
biome_deserialize = { workspace = true, optional = true }
biome_deserialize_macros = { workspace = true, optional = true }
enumflags2.workspace = true
pglt_text_size.workspace = true
schemars = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"], optional = true }
text-size.workspace = true

[features]
serde = ["dep:serde", "dep:schemars", "dep:biome_deserialize", "dep:biome_deserialize_macros"]
2 changes: 1 addition & 1 deletion crates/pglt_analyse/src/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use pglt_diagnostics::{
Advices, Category, Diagnostic, DiagnosticTags, Location, LogCategory, MessageAndDescription,
Visit,
};
use pglt_text_size::TextRange;
use std::cmp::Ordering;
use std::fmt::Debug;
use text_size::TextRange;

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

Expand Down
6 changes: 0 additions & 6 deletions crates/pglt_cli/src/execute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ pub enum TraversalMode {
Dummy,
/// This mode is enabled when running the command `check`
Check {
/// The type of fixes that should be applied when analyzing a file.
///
/// It's [None] if the `check` command is called without `--apply` or `--apply-suggested`
/// arguments.
// fix_file_mode: Option<FixFileMode>,

/// An optional tuple.
/// 1. The virtual path to the file
/// 2. The content of the file
Expand Down
8 changes: 4 additions & 4 deletions crates/pglt_commands/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ version = "0.0.0"


[dependencies]
anyhow = "1.0.62"
async-std = "1.12.0"
sqlx.workspace = true
text-size.workspace = true
anyhow = "1.0.62"
async-std = "1.12.0"
pglt_text_size.workspace = true
sqlx.workspace = true

[lib]
doctest = false
Expand Down
4 changes: 3 additions & 1 deletion crates/pglt_completions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ version = "0.0.0"
[dependencies]
async-std = "1.12.0"

text-size.workspace = true
pglt_text_size.workspace = true


pglt_schema_cache.workspace = true
pglt_treesitter_queries.workspace = true
schemars = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
tree-sitter.workspace = true
Expand All @@ -35,3 +36,4 @@ pglt_test_utils.workspace = true
doctest = false

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

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

#[derive(Debug, Default, Serialize, Deserialize)]
#[derive(Debug, Default, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct CompletionResult {
pub(crate) items: Vec<CompletionItem>,
}
Expand Down
2 changes: 2 additions & 0 deletions crates/pglt_completions/src/item.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
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,
Expand Down
2 changes: 1 addition & 1 deletion crates/pglt_configuration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ pglt_analyse = { workspace = true }
pglt_analyser = { workspace = true }
pglt_console = { workspace = true }
pglt_diagnostics = { workspace = true }
pglt_text_size = { workspace = true }
rustc-hash = { workspace = true }
schemars = { workspace = true, features = ["indexmap1"], optional = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, features = ["raw_value"] }
text-size = { workspace = true }
toml = { workspace = true }

[lib]
Expand Down
4 changes: 2 additions & 2 deletions crates/pglt_console/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ version = "0.0.0"


[dependencies]
pglt_markup = { workspace = true }
text-size = { workspace = true }
pglt_markup = { workspace = true }
pglt_text_size = { workspace = true }

schemars = { workspace = true, optional = true }
serde = { workspace = true, optional = true, features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/pglt_console/src/markup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::{
io,
};

use pglt_text_size::TextSize;
use termcolor::{Color, ColorSpec};
use text_size::TextSize;

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

Expand Down
4 changes: 2 additions & 2 deletions crates/pglt_diagnostics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ version = "0.0.0"
[dependencies]
backtrace = "0.3.74"
bpaf = { workspace = true }
enumflags2 = { workspace = true }
enumflags2 = { workspace = true, features = ["serde"] }
pglt_console = { workspace = true, features = ["serde_markup"] }
pglt_diagnostics_categories = { workspace = true, features = ["serde"] }
pglt_diagnostics_macros = { workspace = true }
pglt_text_edit = { workspace = true }
pglt_text_size.workspace = true
schemars = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
termcolor = { workspace = true }
text-size.workspace = true
unicode-width = { workspace = true }

[features]
Expand Down
2 changes: 1 addition & 1 deletion crates/pglt_diagnostics/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ mod internal {

use pglt_console::{fmt, markup};
use pglt_text_edit::TextEdit;
use text_size::TextRange;
use pglt_text_size::TextRange;

use crate::{
Advices, Backtrace, Category, Diagnostic, DiagnosticTags, LineIndex, LineIndexBuf,
Expand Down
4 changes: 3 additions & 1 deletion crates/pglt_diagnostics/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ pub trait Diagnostic: Debug {
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Default,
)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase")]
/// The severity to associate to a diagnostic.
pub enum Severity {
/// Reports a hint.
Expand Down Expand Up @@ -164,6 +165,7 @@ impl Display for Severity {
/// Internal enum used to automatically generate bit offsets for [DiagnosticTags]
/// and help with the implementation of `serde` and `schemars` for tags.
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "snake_case")]
#[bitflags]
#[repr(u8)]
Expand Down
2 changes: 1 addition & 1 deletion crates/pglt_diagnostics/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,8 @@ mod tests {
use pglt_diagnostics::{DiagnosticTags, Severity};
use pglt_diagnostics_categories::{Category, category};
use pglt_text_edit::TextEdit;
use pglt_text_size::{TextRange, TextSize};
use serde_json::{from_value, json};
use text_size::{TextRange, TextSize};

use crate::{self as pglt_diagnostics};
use crate::{
Expand Down
21 changes: 21 additions & 0 deletions crates/pglt_diagnostics/src/display/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ impl<'de> serde::Deserialize<'de> for Backtrace {
}
}

#[cfg(feature = "schema")]
impl schemars::JsonSchema for Backtrace {
fn schema_name() -> String {
String::from("Backtrace")
}

fn json_schema(generator: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
<Vec<SerializedFrame>>::json_schema(generator)
}
}

/// Internal representation of a [Backtrace], can be either a native backtrace
/// instance or a vector of serialized frames.
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -292,6 +303,11 @@ pub(super) fn print_backtrace(

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

/// Serializable representation of a backtrace frame symbol.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(
feature = "schema",
derive(schemars::JsonSchema),
schemars(rename = "BacktraceSymbol")
)]
#[cfg_attr(test, derive(Eq, PartialEq))]
struct SerializedSymbol {
name: Option<String>,
Expand Down
2 changes: 1 addition & 1 deletion crates/pglt_diagnostics/src/display/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
};

use pglt_console::{fmt, markup};
use text_size::{TextLen, TextRange, TextSize};
use pglt_text_size::{TextLen, TextRange, TextSize};
use unicode_width::UnicodeWidthChar;

use crate::{
Expand Down
2 changes: 1 addition & 1 deletion crates/pglt_diagnostics/src/display_github.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::display::frame::SourceFile;
use crate::{Diagnostic, Resource, Severity, diagnostic::internal::AsDiagnostic};
use pglt_console::{MarkupBuf, fmt, markup};
use pglt_text_size::{TextRange, TextSize};
use std::io;
use text_size::{TextRange, TextSize};

/// Helper struct for printing a diagnostic as markup into any formatter
/// implementing [pglt_console::fmt::Write].
Expand Down
5 changes: 3 additions & 2 deletions crates/pglt_diagnostics/src/location.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use pglt_text_size::{TextRange, TextSize};
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use std::ops::Range;
use std::{borrow::Borrow, ops::Deref};
use text_size::{TextRange, TextSize};

/// Represents the location of a diagnostic in a resource.
#[derive(Debug, Default, Clone, Copy)]
Expand Down Expand Up @@ -39,6 +39,7 @@ impl Eq for Location<'_> {}

/// Represents the resource a diagnostic is associated with.
#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "snake_case")]
pub enum Resource<P> {
/// The diagnostic is related to the content of the command line arguments.
Expand Down Expand Up @@ -343,7 +344,7 @@ impl AsSourceCode for String {

#[cfg(test)]
mod tests {
use text_size::TextSize;
use pglt_text_size::TextSize;

use super::LineIndexBuf;

Expand Down
23 changes: 17 additions & 6 deletions crates/pglt_diagnostics/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use std::io;

use pglt_console::{MarkupBuf, fmt, markup};
use pglt_text_edit::TextEdit;
use pglt_text_size::{TextRange, TextSize};
use serde::{
Deserialize, Deserializer, Serialize, Serializer,
de::{self, SeqAccess},
};
use text_size::{TextRange, TextSize};

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

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

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

/// Implementation of [Visitor] collecting serializable [Advice] into a vector.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[cfg_attr(test, derive(Eq, PartialEq))]
struct Advices {
advices: Vec<Advice>,
Expand Down Expand Up @@ -245,7 +245,7 @@ impl super::Advices for Advices {
/// See the [Visitor] trait for additional documentation on all the supported
/// advice types.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[cfg_attr(test, derive(Eq, PartialEq))]
enum Advice {
Log(LogCategory, MarkupBuf),
Expand Down Expand Up @@ -354,12 +354,23 @@ impl<'de> Deserialize<'de> for DiagnosticTags {
}
}

#[cfg(feature = "schema")]
impl schemars::JsonSchema for DiagnosticTags {
fn schema_name() -> String {
String::from("DiagnosticTags")
}

fn json_schema(generator: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
<Vec<DiagnosticTag>>::json_schema(generator)
}
}

#[cfg(test)]
mod tests {
use std::io;

use pglt_text_size::{TextRange, TextSize};
use serde_json::{Value, json};
use text_size::{TextRange, TextSize};

use crate::{
self as pglt_diagnostics, {Advices, LogCategory, Visit},
Expand Down
2 changes: 1 addition & 1 deletion crates/pglt_diagnostics/src/suggestion.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ::serde::{Deserialize, Serialize};
use pglt_console::MarkupBuf;
use pglt_text_edit::TextEdit;
use text_size::TextRange;
use pglt_text_size::TextRange;

/// Indicates how a tool should manage this suggestion.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion crates/pglt_lexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pg_query.workspace = true
pglt_diagnostics.workspace = true
pglt_lexer_codegen.workspace = true

text-size.workspace = true
pglt_text_size.workspace = true

[dev-dependencies]
insta.workspace = true
Expand Down
Loading
Loading