Skip to content

Commit

Permalink
feat: use custom-data package instead of downloading from GitHub (#12)
Browse files Browse the repository at this point in the history
* feat: use custom-data package instead of downloading from GitHub

* fix: use adjust out folder for extension

* fix: ci

* fix: ci

* fix: adjust structure

* fix: code

* fix: code

* fix: update tests

* fix: ci

* fix: match spec

* fix: use enum for markup kind
  • Loading branch information
Princesseuh authored Dec 13, 2024
1 parent 0727f3f commit 20082da
Show file tree
Hide file tree
Showing 11 changed files with 189 additions and 157 deletions.
28 changes: 26 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,17 @@ jobs:
with:
bins: just

- name: Download CSS custom data
run: just fetch-data
- name: Setup PNPM
uses: pnpm/action-setup@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"

- name: Install dependencies
run: just install

- name: Run Clippy
run: cargo clippy --all-targets --all-features
Expand All @@ -43,11 +52,23 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PNPM
uses: pnpm/action-setup@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"

- name: Setup Rust
uses: moonrepo/setup-rust@v1
with:
bins: just

- name: Install dependencies
run: just install

- name: Build
run: just build

Expand All @@ -73,6 +94,9 @@ jobs:
targets: wasm32-unknown-unknown
bins: wasm-bindgen-cli, just, wasm-opt

- name: Install dependencies
run: just install

- name: Build
run: just build-wasm

Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
target
packages/csslsrs/dist
**/dist
node_modules
**/generated/*
!**/generated/README.md
data

.DS_Store
167 changes: 80 additions & 87 deletions crates/csslsrs/src/css_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,122 +2,115 @@ use serde::Deserialize;
use std::sync::LazyLock;

pub(crate) static BASE_CSS_DATA: LazyLock<CssCustomData> = LazyLock::new(|| {
serde_json::from_str(include_str!("../data/css-schema.json"))
.expect("Failed to parse css-schema.json")
serde_json::from_str(include_str!(
"../../../node_modules/@vscode/web-custom-data/data/browsers.css-data.json"
))
.expect("Failed to parse css-schema.json")
});

// This is used when the user sets `include_base_css_custom_data` to false in the LanguageServiceOptions.
pub(crate) static EMPTY_CSS_DATA: CssCustomData = CssCustomData {
css: CssSection {
at_directives: AtDirectives { entry: vec![] },
pseudo_classes: PseudoClasses { entry: vec![] },
pseudo_elements: PseudoElements { entry: vec![] },
properties: Properties { entry: vec![] },
},
version: 1.1,
at_directives: None,
pseudo_classes: None,
pseudo_elements: None,
properties: None,
};

#[derive(Deserialize)]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
/// Represents any CSS data provided by the user or MDN.
/// This is used to provide completions and hover information.
pub struct CssCustomData {
pub css: CssSection,
pub version: f64,
pub properties: Option<Vec<PropertyEntry>>,
pub at_directives: Option<Vec<AtDirectiveEntry>>,
pub pseudo_classes: Option<Vec<PseudoClassEntry>>,
pub pseudo_elements: Option<Vec<PseudoElementEntry>>,
}

#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CssSection {
pub at_directives: AtDirectives,
pub pseudo_classes: PseudoClasses,
pub pseudo_elements: PseudoElements,
pub properties: Properties,
}

#[derive(Deserialize)]
pub struct AtDirectives {
pub entry: Vec<AtDirectiveEntry>,
}

#[derive(Deserialize)]
pub struct PseudoClasses {
pub entry: Vec<PseudoClassEntry>,
}

#[derive(Deserialize)]
pub struct PseudoElements {
pub entry: Vec<PseudoElementEntry>,
#[derive(Debug, Deserialize)]
pub struct PropertyEntry {
pub name: String,
pub description: Option<MarkupDescriptionOrString>,
pub status: Option<Status>,
pub browsers: Option<Vec<String>>,
pub references: Option<Vec<Reference>>,
pub relevance: Option<u8>,

// Not in the JSON schema, but found in VS Code's types and CSS data, strange.
#[serde(rename = "atRule")]
pub at_rule: Option<String>,
pub syntax: Option<String>,
pub restrictions: Option<Vec<String>>,
pub values: Option<Vec<Value>>,
}

#[derive(Deserialize)]
pub struct Properties {
pub entry: Vec<PropertyEntry>,
#[derive(Debug, Deserialize)]
pub struct Value {
pub name: String,
pub description: Option<MarkupDescriptionOrString>,
pub browsers: Option<Vec<String>>,
pub status: Option<Status>,
pub references: Option<Vec<Reference>>,
}

#[derive(Deserialize)]
#[derive(Debug, Deserialize)]
pub struct AtDirectiveEntry {
#[serde(rename = "$")]
pub attributes: AtDirectiveAttributes,
pub desc: Option<String>,
pub name: String,
pub description: Option<MarkupDescriptionOrString>,
pub status: Option<Status>,
pub browsers: Option<Vec<String>>,
pub references: Option<Vec<Reference>>,
}

#[derive(Deserialize)]
#[derive(Debug, Deserialize)]
pub struct PseudoClassEntry {
#[serde(rename = "$")]
pub attributes: PseudoClassAttributes,
pub desc: Option<String>,
pub name: String,
pub description: Option<MarkupDescriptionOrString>,
pub status: Option<Status>,
pub browsers: Option<Vec<String>>,
pub references: Option<Vec<Reference>>,
}

#[derive(Deserialize)]
#[derive(Debug, Deserialize)]
pub struct PseudoElementEntry {
#[serde(rename = "$")]
pub attributes: PseudoElementAttributes,
pub desc: Option<String>,
pub name: String,
pub description: Option<MarkupDescriptionOrString>,
pub status: Option<Status>,
pub browsers: Option<Vec<String>>,
pub references: Option<Vec<Reference>>,
}

#[derive(Deserialize)]
pub struct PropertyEntry {
#[serde(rename = "$")]
pub attributes: PropertyAttributes,
pub desc: Option<String>,
#[derive(Debug, Deserialize)]
pub struct Reference {
pub name: String,
pub url: String,
}

#[derive(Deserialize)]
pub struct AtDirectiveAttributes {
pub name: String,
pub version: Option<String>,
pub browsers: Option<String>,
#[serde(rename = "ref")]
pub ref_: Option<String>,
pub syntax: Option<String>,
#[derive(Debug, Deserialize)]
#[serde(untagged)]
pub enum MarkupDescriptionOrString {
MarkupDescription(MarkupDescription),
String(String),
}

#[derive(Deserialize)]
pub struct PseudoClassAttributes {
pub name: String,
pub version: Option<String>,
pub browsers: Option<String>,
#[serde(rename = "ref")]
pub ref_: Option<String>,
pub syntax: Option<String>,
#[derive(Debug, Deserialize)]
pub struct MarkupDescription {
pub kind: MarkupDescriptionKind,
pub value: String,
}

#[derive(Deserialize)]
pub struct PseudoElementAttributes {
pub name: String,
pub version: Option<String>,
pub browsers: Option<String>,
#[serde(rename = "ref")]
pub ref_: Option<String>,
pub syntax: Option<String>,
#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Status {
Standard,
Experimental,
Nonstandard,
Obsolete,
}

#[derive(Deserialize)]
pub struct PropertyAttributes {
pub name: String,
pub restriction: Option<String>,
pub version: Option<String>,
pub browsers: Option<String>,
#[serde(rename = "ref")]
pub ref_: Option<String>,
pub syntax: Option<String>,
#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum MarkupDescriptionKind {
Plaintext,
Markdown,
}
Loading

0 comments on commit 20082da

Please sign in to comment.