Skip to content

✨ CSS #47

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

Merged
merged 3 commits into from
Apr 4, 2025
Merged

✨ CSS #47

merged 3 commits into from
Apr 4, 2025

Conversation

NatoBoram
Copy link
Collaborator

@NatoBoram NatoBoram commented Apr 2, 2025

Here's CSS.

I'll add the changeset once the infrastructure for them is in place. It shouldn't be too hard to automate it for all the PRs with a little Bash.

Summary by CodeRabbit

  • New Features

    • Launched comprehensive CSS support that brings dynamic parsing for both CSS and SCSS files, enhancing code analysis and integration.
    • Added new methods for registering and parsing CSS languages dynamically.
  • Documentation

    • Introduced a detailed guide with clear installation steps and usage examples to streamline setup and adoption for end-users.

Copy link

coderabbitai bot commented Apr 2, 2025

Walkthrough

This pull request introduces a new CSS language package (@ast-grep/lang-css) along with accompanying type definitions, runtime exports, a testing setup, and post-installation tasks. The updates include a detailed README with installation and usage instructions, new type and constant declarations, a module that exports properties for CSS parsing, a nursery test runner to validate functionality, a package manifest with configuration details, and a postinstall script that executes setup tasks.

Changes

Files Change Summary
packages/css/README.md, packages/css/package.json Added new documentation and package manifest for @ast-grep/lang-css, including installation commands, usage instructions, build scripts, dependencies, and configuration details.
packages/css/index.d.ts, packages/css/index.js Introduced a new type (LanguageRegistration) and exported an object with properties (libraryPath, extensions, languageSymbol, expandoChar) defining the CSS parser’s configuration.
packages/css/nursery.js Added a testing setup using @ast-grep/nursery that sets up the CSS environment and verifies parser functionality by asserting the syntax tree's node type.
packages/css/postinstall.js Introduced a post-installation script that invokes the postinstall function from @ast-grep/setup-lang, ensuring necessary setup tasks are performed after package installation.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer
    participant CSS as CSS Package
    participant NAPI as @ast-grep/napi
    participant Parser as Parser Engine
    participant Tester as Nursery Test Runner

    Dev->>CSS: Import CSS language module and functions
    CSS->>NAPI: Register dynamic CSS language with registerDynamicLanguage()
    Dev->>NAPI: Call parse() with CSS code snippet
    NAPI->>Parser: Forward parsing request (using parser.so)
    Parser-->>NAPI: Return syntax tree
    NAPI-->>Dev: Deliver parsed AST
    Tester->>Parser: Parse sample CSS rule from nursery.js
    Tester-->>Tester: Assert AST root node type (e.g., 'rule_set')
Loading

Possibly related PRs

  • feat: add tree-sitter-c #35: Introduces a new language package with type definitions and dynamic registration similar to the CSS package.
  • feat: C# language #41: Adds a new language package structure for C# with analogous modifications in documentation, type definitions, and setup scripts.

Poem

I'm a rabbit on a coding spree,
Hopping through CSS with glee.
New types and tests in rhythmic flow,
Dynamic language seeds now grow.
Carrots of code—oh, what a show! 🥕🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c131376 and 38e4e3c.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • .changeset/hungry-months-know.md (1 hunks)
  • packages/css/README.md (1 hunks)
  • packages/css/index.d.ts (1 hunks)
  • packages/css/index.js (1 hunks)
  • packages/css/nursery.js (1 hunks)
  • packages/css/package.json (1 hunks)
  • packages/css/postinstall.js (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .changeset/hungry-months-know.md
🚧 Files skipped from review as they are similar to previous changes (6)
  • packages/css/postinstall.js
  • packages/css/nursery.js
  • packages/css/index.d.ts
  • packages/css/index.js
  • packages/css/README.md
  • packages/css/package.json

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@NatoBoram NatoBoram mentioned this pull request Apr 2, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (6)
packages/css/nursery.js (1)

1-16: Good test setup for basic CSS parsing

The test successfully validates that the parser can identify a CSS rule set. The setup correctly uses the nursery test framework with the appropriate configuration.

Consider expanding test coverage in the future to include more CSS constructs like:

  • Complex selectors (pseudo-classes, combinators)
  • Media queries
  • Keyframe animations
  • CSS variables
  • Nested rules (for SCSS support)

This would ensure broader syntax coverage and more robust validation.

packages/css/README.md (2)

1-2: Clarify the Package Title
The header in lines 1–2 is clear but could benefit from a slight rewording for clarity. Consider specifying that this package provides CSS language support using the NAPI approach (e.g., “ast-grep CSS language package using NAPI”).


14-24: Usage Snippet Effectiveness
The usage block (lines 14–24) effectively demonstrates how to import, register, and use the new CSS language module. To further enhance clarity, you might add a brief inline comment explaining what the method sg.root().kind() returns. This would help users quickly grasp the purpose of that call.

packages/css/package.json (3)

1-5: Provide a Package Description
The basic metadata (lines 1–5) is set up correctly; however, the "description" field is currently empty. Consider adding a brief description that clearly explains the purpose of the package (e.g., “Provides CSS language support for ast-grep with NAPI integration”).


6-12: Review Script Commands for Consistency
The scripts block (lines 6–12) appears comprehensive. Note that both "source" and "prepublishOnly" run node nursery.js source, which might be intentional. It may help to add a comment or documentation in the repository explaining the rationale behind using the same command for both to avoid any confusion in future maintenance.


21-23: Metadata Fields and Licensing
The "keywords", "author", and "license" fields (lines 21–23) are present. While the "author" field is empty, this can be filled as the project matures. Filling in the "description" and "author" fields would improve package metadata for end users and maintainers.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 002639c and c131376.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • packages/css/README.md (1 hunks)
  • packages/css/index.d.ts (1 hunks)
  • packages/css/index.js (1 hunks)
  • packages/css/nursery.js (1 hunks)
  • packages/css/package.json (1 hunks)
  • packages/css/postinstall.js (1 hunks)
🔇 Additional comments (10)
packages/css/postinstall.js (1)

1-4: Clean implementation following project patterns

The postinstall script correctly imports and uses the postinstall function from @ast-grep/setup-lang with the current directory. This follows the established pattern for language packages in ast-grep.

packages/css/index.d.ts (1)

1-10: Well-structured type definition

The LanguageRegistration type is properly defined with all the necessary properties for a language registration interface. The type properly distinguishes between required properties (libraryPath, extensions) and optional ones (marked with ?), and exports the registration constant as expected.

packages/css/index.js (1)

1-9:

❓ Verification inconclusive

Correct language registration implementation

The implementation properly exports all required properties for CSS language registration, including the library path, supported file extensions, language symbol, and expando character.

Since 'scss' is included in the extensions array, please verify that the Tree-sitter CSS parser fully supports SCSS syntax. If the parser doesn't support SCSS-specific constructs (like nesting or variables), it might be better to limit to just 'css' or document the limitations.


🏁 Script executed:

#!/bin/bash
# Check if tree-sitter-css documentation mentions SCSS support
rg -i "scss" --glob="*.md" 
# Or check if there are SCSS-specific tests
rg -i "scss" --glob="*.js" --glob="*.ts"

Length of output: 120


Language Registration Verified; SCSS Support Requires Clarification

The implementation in packages/css/index.js correctly exports the required properties for CSS language registration, including the library path, supported file extensions, language symbol, and expando character.

However, while the configuration registers both "css" and "scss", our search didn't reveal any additional tests or documentation confirming that the Tree-sitter CSS parser fully supports SCSS-specific syntax (such as nesting or variables). To ensure that the parser handles SCSS correctly, please verify whether:

  • The parser includes support for SCSS-specific constructs beyond standard CSS.
  • There are any tests or documentation updates that address potential limitations with SCSS.

If full SCSS support is not confirmed, consider either removing "scss" from the extensions array or documenting any limitations regarding SCSS.

packages/css/README.md (1)

3-12: Installation Instructions Are Clear
The installation section (lines 3–12) is well-documented and instructive. The inclusion of an inline comment for the optional installation of tree-sitter-cli is helpful. Optionally, consider mentioning any version compatibility notes for tree-sitter-cli if available.

packages/css/package.json (6)

13-20: Files Array Correctness
The "files" array (lines 13–20) properly includes all required assets for the package. This ensures that consumers of the package will get the intended files, which is great.


24-26: Dependency Declaration Review
The dependency on "@ast-grep/setup-lang": "0.0.3" (lines 24–26) is clearly defined. Please verify that this version aligns with the rest of your toolchain and intended functionality.


27-34: Peer Dependencies Validation
The configuration for peer dependencies (lines 27–34) correctly marks "tree-sitter-cli": "0.24.6" as an optional peer dependency using "peerDependenciesMeta". This is in line with best practices for handling optional external tools.


35-39: Dev Dependencies Are Appropriately Set
The dev dependencies (lines 35–39) include the necessary packages such as "@ast-grep/nursery", "tree-sitter-cli", and "tree-sitter-css", ensuring that development and testing are adequately supported.


40-43: Publish Configuration is Correct
The "publishConfig" block (lines 40–43) is set for public access with the correct registry URL. This configuration will help in the consistent publication of the package.


44-46: PNPM Configuration Confirmation
The PNPM configuration (lines 44–46) with "onlyBuiltDependencies" is correctly set to include only the built dependencies. This is a good practice to ensure that the final package is lean.

@HerringtonDarkholme HerringtonDarkholme merged commit e7a802d into ast-grep:main Apr 4, 2025
3 checks passed
@NatoBoram NatoBoram deleted the feature/css branch April 4, 2025 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants