module

Hecr::LSP::Css

:class ⇄ CSS-modules support: parsing class selectors out of a .module.css file, finding the static class tokens inside a :class attribute, resolving the styles module a template is paired with, and detecting the completion context. hecr never depends on a CSS shard, so the LSP reads the .module.css directly — the same file the provider (lightening_css_modules) compiles at build time.

Constants

CONST = /[A-Z][A-Za-z0-9_]*(?:::[A-Z][A-Za-z0-9_]*)*/
NAME_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-"
PAIRING = /\.styles\s+"([^"]+)"\s*,\s*name:\s*([A-Z][A-Za-z0-9_]*(?:::[A-Z][A-Za-z0-9_]*)*)/
QUALIFIED = /(#{CONST})\.([a-z_][a-zA-Z0-9_]*[?!]?)/
STYLES_DIRECTIVE = /<%@\s*styles\s+(.+?)\s*%>/

Instance methods

class_def_at(css : String, line : Int32, character : Int32) : ClassDef | Nil

The class selector whose name span contains a 0-based position.

Source
class_defs(css : String) : Array(ClassDef)

Class selectors declared in a stylesheet. Declaration blocks are consumed whole (so composes: references and property values never count), strings and comments are skipped, and at-rule blocks (@media { … }) are descended into so nested selectors are seen.

Source
class_names(css : String) : Array(String)
Source
class_tokens(line : String) : Array(Token)

Static class-name tokens (and their spans) in every :class value on a line: the whole of a quoted :class="a b", and the string literals inside :class={[...]} ("a", cond && "b") — exactly what the compiler resolves against the styles module. Bare expressions are runtime lookups and are skipped.

Source
completing?(before_cursor : String) : Bool

Is the cursor inside a :class value, positioned to complete a class name? True inside an unclosed quoted value, or inside an unclosed string literal within :class={ … }.

Source
pairings(crystal_source : String) : Array(Pairing)
Source
qualified_completion(before_cursor : String) : String | Nil

If the cursor sits right after Module. inside an open :class={ … } (outside any string), the module to complete class names from.

Source
qualified_token_at(line : String, character : Int32) : QualifiedToken | Nil
Source
qualified_tokens(line : String) : Array(QualifiedToken)

Module-qualified tokens in every :class={…} value on a line, scanning only the parts outside string literals (so they aren't matched inside a bare "a.b" token).

Source
styles_spec(template_source : String) : String | Nil

The raw argument of a <%@ styles … %> directive: a quoted path ("./ui.module.css") or a module constant (ThemeStyles).

Source
token_at(line : String, character : Int32) : Token | Nil
Source

Nested types