Understand any codebase instantly. System intelligence for codebases, built for humans and AI.
TypeScript aiai-memoryclaude-codeclicode-analysiscode-mappingcode-memorycodebase-understandingcodexdeveloper-toolsllmopenclawpersistent-memoryprogram-analysissoftware-architecturesystem-intelligencesystem-mapping
feat(parser): add CSS parser support (.css, .scss, .sass, .less) (closes #130) (#258)
Joseph Mikhailf62effa03473
diff --git a/core-ingestion/package.json b/core-ingestion/package.jsonindex b8064d34..cde65139 100644--- a/core-ingestion/package.json+++ b/core-ingestion/package.json@@ -38,6 +38,7 @@"@tree-sitter-grammars/tree-sitter-xml": "^0.7.0","@tree-sitter-grammars/tree-sitter-zig": "^1.1.2","tree-sitter-bash": "^0.21.0",+ "tree-sitter-css": "^0.25.0","tree-sitter-elixir": "^0.3.5","tree-sitter-haskell": "^0.23.1","tree-sitter-html": "^0.23.2",diff --git a/core-ingestion/src/__tests__/queries.css.test.ts b/core-ingestion/src/__tests__/queries.css.test.tsnew file mode 100644index 00000000..e79afaec--- /dev/null+++ b/core-ingestion/src/__tests__/queries.css.test.ts@@ -0,0 +1,37 @@+import { describe, it, expect } from 'vitest';+import { parseFile } from '../index.js';+import { SupportedLanguages } from '../languages.js';++const c = parseFile('/repo/a.css', '.x{}\n');+const describeFn = c && c.language === SupportedLanguages.CSS ? describe : describe.skip;++describeFn('CSS queries', () => {+ it('detects CSS by .css / .scss', () => {+ expect(parseFile('/r/main.css', '.x{}')!.language).toBe(SupportedLanguages.CSS);+ expect(parseFile('/r/main.scss', '.x{}')!.language).toBe(SupportedLanguages.CSS);+ });++ it('emits IMPORTS for @import string and url()', () => {+ const result = parseFile('/r/main.css', `+@import "base.css";+@import url('theme/dark.css');+`);+ expect(result).not.toBeNull();+ const imports = result!.relationships+ .filter(r => r.predicate === 'IMPORTS')+ .map(r => r.importRaw ?? r.dstName);+ expect(imports).toEqual(expect.arrayContaining(['base.css', 'theme/dark.css']));+ });++ it('captures class/id selectors and keyframes', () => {+ const result = parseFile('/r/app.css', `+.btn { color: red; }+#header { width: 100%; }+.card .title { font-weight: bold; }+@keyframes spin { from { opacity: 0; } }+`);+ expect(result).not.toBeNull();+ const names = result!.entities.map(e => e.name);+ expect(names).toEqual(expect.arrayContaining(['btn', 'header', 'card', 'title', 'spin']));+ });+});diff --git a/core-ingestion/src/index.ts b/core-ingestion/src/index.tsindex c122b9c0..7e1911f8 100644--- a/core-ingestion/src/index.ts+++ b/core-ingestion/src/index.ts@@ -65,6 +65,15 @@ catch (e: any) {process.stderr.write('[tree-sitter-lua load failed] ' + e + '\n');}}+// tree-sitter-css ships ESM bindings with top-level await — load via import().+let Css: any = null;+// @ts-ignore+try { const c = await import('tree-sitter-css'); Css = c.default ?? c; }+catch (e: any) {+ if (e?.code !== 'ERR_MODULE_NOT_FOUND' && e?.code !== 'MODULE_NOT_FOUND') {+ process.stderr.write('[tree-sitter-css load failed] ' + e + '\n');+ }+}import { SupportedLanguages, languageFromPath } from './languages.js';import { LANGUAGE_QUERIES } from './queries.js';@@ -192,6 +201,7 @@ const GRAMMAR_MAP: Partial<Record<SupportedLanguages, any>> = {...(Html ? { [SupportedLanguages.HTML]: Html } : {}),...(Xml ? { [SupportedLanguages.XML]: Xml } : {}),...(Hcl ? { [SupportedLanguages.HCL]: Hcl } : {}),+ ...(Css ? { [SupportedLanguages.CSS]: Css } : {}),};// Capture key prefix → NodeKind stringdiff --git a/core-ingestion/src/languages.ts b/core-ingestion/src/languages.tsindex 5f130e75..66c8b1d8 100644--- a/core-ingestion/src/languages.ts+++ b/core-ingestion/src/languages.ts@@ -30,6 +30,7 @@ export enum SupportedLanguages {HTML = 'html',XML = 'xml',HCL = 'hcl',+ CSS = 'css',}const EXT_MAP: Record<string, SupportedLanguages> = {@@ -96,6 +97,10 @@ const EXT_MAP: Record<string, SupportedLanguages> = {'.tf': SupportedLanguages.HCL,'.tfvars': SupportedLanguages.HCL,'.hcl': SupportedLanguages.HCL,+ '.css': SupportedLanguages.CSS,+ '.scss': SupportedLanguages.CSS,+ '.sass': SupportedLanguages.CSS,+ '.less': SupportedLanguages.CSS,};export function languageFromPath(filePath: string): SupportedLanguages | null {diff --git a/core-ingestion/src/queries.ts b/core-ingestion/src/queries.tsindex ad87cf27..ef1e61f8 100644--- a/core-ingestion/src/queries.ts+++ b/core-ingestion/src/queries.ts@@ -1605,6 +1605,20 @@ export const R_QUERIES = `(#eq? @_src "source")) @import`;+// CSS. @import (string or url(...)) as stylesheet imports; class and id selectors+// as definitions (repeats of the same name fold to one node per file); @keyframes+// animation names as definitions.+export const CSS_QUERIES = `+(import_statement (string_value (string_content) @import.source)) @import+(import_statement+ (call_expression (function_name) @_f (arguments (string_value (string_content) @import.source)))+ (#eq? @_f "url")) @import++(class_selector (class_name) @name) @definition.class+(id_selector (id_name) @name) @definition.class+(keyframes_statement (keyframes_name) @name) @definition.const+`;+// HCL / Terraform. Each labeled block (resource/data/variable/output/module/// provider) is a definition named by its primary (last) label; a module's// `source` attribute is an import to the referenced module.@@ -1768,5 +1782,6 @@ export const LANGUAGE_QUERIES: Record<SupportedLanguages, string> = {[SupportedLanguages.HTML]: HTML_QUERIES,[SupportedLanguages.XML]: XML_QUERIES,[SupportedLanguages.HCL]: HCL_QUERIES,+ [SupportedLanguages.CSS]: CSS_QUERIES,};