Skip to content

Add PLpgSQL language support#157

Merged
simianhacker merged 5 commits into
elastic:mainfrom
simianhacker:add-plpgsql-support
Apr 7, 2026
Merged

Add PLpgSQL language support#157
simianhacker merged 5 commits into
elastic:mainfrom
simianhacker:add-plpgsql-support

Conversation

@simianhacker

Copy link
Copy Markdown
Member

Summary

  • add PLpgSQL language support using @derekstride/tree-sitter-sql
  • register .sql, .pgsql, and .plpgsql extensions
  • add fixture coverage, parser tests, language tests, and snapshot coverage

Validation

  • npm run build
  • npm test
  • npm run lint

@coderabbitai

coderabbitai Bot commented Mar 20, 2026

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This pull request adds PL/pgSQL support by introducing and exporting plpgsqlConfig, registering it in the language registry, and adding @derekstride/tree-sitter-sql as a dependency. It includes symbol and export query definitions for functions, tables, types, views, and invocations, an ambient TypeScript declaration for the parser package, a PL/pgSQL fixture exercising those constructs, unit tests validating recognition/symbol/export extraction and parsing behavior, and updated Docker base images.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant Parser
    participant LanguageRegistry
    participant TreeSitterSQL
    participant PlpgsqlConfig

    User->>Parser: parseFile("tests/fixtures/plpgsql.sql")
    Parser->>LanguageRegistry: getLanguageConfig("plpgsql")
    LanguageRegistry-->>Parser: plpgsqlConfig
    Parser->>TreeSitterSQL: parse(source, plpgsqlConfig.parser)
    TreeSitterSQL-->>Parser: syntaxTree
    Parser->>PlpgsqlConfig: run symbolQueries & exportQueries on syntaxTree
    PlpgsqlConfig-->>Parser: symbols & exports
    Parser-->>User: parsed chunks with language 'plpgsql', symbols, exports
Loading
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add PLpgSQL language support' clearly summarizes the main change: introducing support for a new language (PL/pgSQL) with parser configuration and test coverage.
Description check ✅ Passed The description is directly related to the changeset, covering the addition of PL/pgSQL language support, file extensions registered, test coverage added, and validation steps performed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/unit/parser.test.ts (1)

344-369: ⚠️ Potential issue | 🟡 Minor

Duplicate test block for C fixtures.

Lines 344-369 are exact duplicates of lines 240-265 (both test "should parse C fixtures correctly" and "should extract symbols from C fixtures correctly"). This appears to be an unintentional copy-paste error.

🧹 Remove duplicate tests
-  it('should parse C fixtures correctly', () => {
-    const filePath = path.resolve(__dirname, '../fixtures/c.c');
-    const result = parser.parseFile(filePath, 'main', 'tests/fixtures/c.c');
-    expect(cleanTimestamps(result.chunks)).toMatchSnapshot();
-  });
-
-  it('should extract symbols from C fixtures correctly', () => {
-    const filePath = path.resolve(__dirname, '../fixtures/c.c');
-    const result = parser.parseFile(filePath, 'main', 'tests/fixtures/c.c');
-    const allSymbols = result.chunks.flatMap((chunk) => chunk.symbols);
-    expect(allSymbols).toEqual(
-      expect.arrayContaining([
-        expect.objectContaining({ name: 'add', kind: 'function.name' }),
-        expect.objectContaining({ name: 'test_function', kind: 'function.name' }),
-        expect.objectContaining({ name: 'main', kind: 'function.name' }),
-        expect.objectContaining({ name: 'add', kind: 'function.call' }),
-        expect.objectContaining({ name: 'printf', kind: 'function.call' }),
-        expect.objectContaining({ name: 'Point', kind: 'struct.name' }),
-        expect.objectContaining({ name: 'Data', kind: 'union.name' }),
-        expect.objectContaining({ name: 'Color', kind: 'enum.name' }),
-        expect.objectContaining({ name: 'Point_t', kind: 'type.name' }),
-        expect.objectContaining({ name: 'global_var', kind: 'variable.name' }),
-        expect.objectContaining({ name: 'point', kind: 'variable.name' }),
-      ])
-    );
-  });
-

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3a727b07-03c8-4fda-8739-1b1d143f7528

📥 Commits

Reviewing files that changed from the base of the PR and between 2d02337 and 92fc459.

⛔ Files ignored due to path filters (2)
  • package-lock.json is excluded by !**/package-lock.json
  • tests/unit/__snapshots__/parser.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (7)
  • package.json
  • src/languages/index.ts
  • src/languages/plpgsql.ts
  • src/types/tree-sitter-sql.d.ts
  • tests/fixtures/plpgsql.sql
  • tests/unit/languages.test.ts
  • tests/unit/parser.test.ts

Comment thread package.json
Comment thread src/languages/plpgsql.ts
Comment thread src/languages/plpgsql.ts
@simianhacker

Copy link
Copy Markdown
Member Author

Rebased this branch onto current upstream/main to resolve merge conflicts after Scala/HCL support landed in #155.\n\nWhat changed in the rebase:\n- preserved upstream Scala + HCL additions\n- merged in PL/pgSQL support on top\n- reran dependency install/native rebuilds under Node 22\n- revalidated build, test, and lint on the rebased branch\n\nValidation after rebase:\n- npm run build\n- npm test\n- npm run lint\n\nThis force-push only updates branch history to keep the PR mergeable against current main.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
package.json (1)

39-39: ⚠️ Potential issue | 🔴 Critical

Re-verify tree-sitter compatibility before merge.

Line 39 adds @derekstride/tree-sitter-sql, while the repo pins tree-sitter@^0.25.0 (Lines 36 and 67). If the grammar’s peer range is still ^0.21.x, this can break dependency resolution or runtime parser loading.

#!/bin/bash
# Verify published peer dependency constraints for the added parser
npm view `@derekstride/tree-sitter-sql`@0.3.11 peerDependencies --json
npm view `@derekstride/tree-sitter-sql`@0.3.11 engines --json

# Verify effective tree-sitter requirement in this repo manifest
jq '.overrides["tree-sitter"], .dependencies["tree-sitter"]' package.json

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: ASSERTIVE

Plan: Pro

Run ID: bb20f383-a6c0-428e-98ba-002c2f581ca0

📥 Commits

Reviewing files that changed from the base of the PR and between 92fc459 and fc455f6.

⛔ Files ignored due to path filters (2)
  • package-lock.json is excluded by !**/package-lock.json
  • tests/unit/__snapshots__/parser.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (7)
  • package.json
  • src/languages/index.ts
  • src/languages/plpgsql.ts
  • src/types/tree-sitter-sql.d.ts
  • tests/fixtures/plpgsql.sql
  • tests/unit/languages.test.ts
  • tests/unit/parser.test.ts

Comment thread tests/unit/parser.test.ts
@simianhacker

Copy link
Copy Markdown
Member Author

@coderabbitai review

Addressed the remaining parser-test feedback by replacing the PL/pgSQL snapshot-only assertion with targeted invariant assertions and removing the obsolete snapshot entry.

@coderabbitai

coderabbitai Bot commented Mar 20, 2026

Copy link
Copy Markdown

@simianhacker Sure! I'll review the updated changes now.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@simianhacker

Copy link
Copy Markdown
Member Author

@coderabbitai resolve

@coderabbitai

coderabbitai Bot commented Mar 20, 2026

Copy link
Copy Markdown
✅ Actions performed

Comments resolved and changes approved.

@simianhacker

Copy link
Copy Markdown
Member Author

Tested PR #157 with custom image docker.io/simianhacker/scs-indexer:pr-157 on GKE against two small open-source repos:

  • mortenbra/alexandria-plsql-utils
  • okbob/plpgsql_check

Results:

  • both full indexes completed successfully
  • both incremental CronJobs auto-enabled and ran successfully
  • both repos now appear in scs-private via list_indices
  • semantic search returns real PL/SQL / PLpgSQL code chunks from both repos

Observed indices / aliases:

  • alexandria-plsql-utils-repo
  • plpgsql_check-repo

Language detection seen in scs-private:

  • plpgsql_check-repo: plpgsql chunks present as expected
  • alexandria-plsql-utils-repo: Oracle-style PL/SQL content is also currently classified as plpgsql

Example verification:

  • plpgsql_check-repo semantic search returned multiple create or replace function ... returns trigger ... language plpgsql hits from sql/plpgsql_check_active.sql
  • alexandria-plsql-utils-repo semantic search returned Oracle-style SQL/PL content from files like setup/types.sql, demos/sms_util_pkg_demo.sql, and demos/amazon_aws_s3_pkg_demo.sql

One unrelated infra bug surfaced during testing: repo names containing _ produced invalid Kubernetes resource names. I fixed slug normalization in ai-infra so / and _ now normalize to - for K8s resource names.

Net: PR looks good from an indexing/search validation standpoint.

The @derekstride/tree-sitter-sql package downloads a glibc-linked
tree-sitter binary during install, which fails on Alpine's musl libc.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
Dockerfile (1)

32-32: 🧹 Nitpick | 🔵 Trivial

Redundant chown operation.

Lines 29-31 already copy files with --chown=indexer:nodejs, making this recursive chown unnecessary. Removing it reduces build time and image layer size.

♻️ Proposed fix to remove redundant chown
 COPY --from=builder --chown=indexer:nodejs /app/dist ./dist
 COPY --from=builder --chown=indexer:nodejs /app/node_modules ./node_modules
 COPY --from=builder --chown=indexer:nodejs /app/package*.json ./
-RUN chown -R indexer:nodejs .
 USER indexer

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8fd11bf7-838b-49dd-ad7f-1d88b6f94383

📥 Commits

Reviewing files that changed from the base of the PR and between 675472c and 53ef8a8.

📒 Files selected for processing (1)
  • Dockerfile

Comment thread Dockerfile
Comment thread Dockerfile
@simianhacker

Copy link
Copy Markdown
Member Author

CodeRabbit Review Response

Node type names (Critical — False Positive)

CodeRabbit flagged that the queries in src/languages/plpgsql.ts use incorrect node types (create_table, create_type, create_view) and should use _statement suffixes. This is incorrect. Verified against the actual @derekstride/tree-sitter-sql@0.3.11 grammar:

CREATE TABLE foo (id INT);
→ (program (statement (create_table ...)))

CREATE TYPE status AS ENUM (1);
→ (program (statement (create_type ...)))

CREATE VIEW v AS SELECT 1;
→ (program (statement (create_view ...)))

The grammar uses create_table, create_type, create_view — the existing queries are correct.

Other comments

  • Peer dep mismatch (tree-sitter ^0.21 vs ^0.25): Works in practice, latest version of package, upstream issue.
  • .sql extension: By design — conflict detection already exists via isSharedExtensionAllowed().
  • Dockerfile apt pinning / GPG verification: Trivial nitpicks, standard patterns, not worth the maintenance burden.
  • Snapshot tests: Already addressed in commit 675472c.

@simianhacker

Copy link
Copy Markdown
Member Author

@coderabbitai resolve

@coderabbitai

coderabbitai Bot commented Mar 20, 2026

Copy link
Copy Markdown
✅ Actions performed

Comments resolved and changes approved.

Comment thread tests/unit/parser.test.ts

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

stripping off comments happens all the time with rushing models. They are not all self-evident at all. Some are self-evident and should be removed others should stay. I would instruct it to not do this in your system prompt if you use those models.

These comments are also helpful for the context for next agents themselves. Let me know wdyt?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Restored.

simianhacker and others added 2 commits March 23, 2026 17:04
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The original PLpgSQL commit inadvertently removed every inline comment
from the test file. This restores the file to main's state and cleanly
re-applies only the PLpgSQL test additions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@simianhacker
simianhacker requested a review from kapral18 April 7, 2026 21:35
@simianhacker
simianhacker merged commit 21e0fa3 into elastic:main Apr 7, 2026
7 checks passed
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