Skip to content

refactor block queries to remove InsertionQuery system#29

Merged
dsisco11 merged 1 commit into
masterfrom
sisco/refactor-block-queries
Jan 6, 2026
Merged

refactor block queries to remove InsertionQuery system#29
dsisco11 merged 1 commit into
masterfrom
sisco/refactor-block-queries

Conversation

@dsisco11

@dsisco11 dsisco11 commented Jan 6, 2026

Copy link
Copy Markdown
Owner

Unify InsertionQuery into BoundaryQuery API

Summary

Replaces the separate InsertionQuery system with a cleaner BoundaryQuery approach that integrates naturally with the existing query system. This simplifies the API for inserting content at block boundaries while maintaining full functionality.

Motivation

The previous InsertionQuery was a parallel system with its own types (InsertionQuery, InsertionSide, extension methods like .Before(), .After(), .InnerStart(), .InnerEnd()) that only worked with SyntaxEditor.Insert(). This created API confusion and duplicated concepts.

The new design uses BoundaryQuery as a regular INodeQuery that selects block boundaries (opener/closer), working naturally with the existing InsertBefore/InsertAfter methods.

Changes

New BoundaryQuery type:

  • Selects block boundaries (start = opener, end = closer)
  • Implements INodeQuery for consistency with the query system
  • Special handling in SyntaxEditor for empty block support

API Changes:

Old API New API
.Insert(query.Before(), text) .InsertBefore(query, text)
.Insert(query.After(), text) .InsertAfter(query, text)
.Insert(block.InnerStart(), text) .InsertAfter(block.Start(), text)
.Insert(block.InnerEnd(), text) .InsertBefore(block.End(), text)

Removed:

  • InsertionQuery record
  • InsertionSide enum
  • InsertionQueryExtensions class
  • .Before(), .After(), .InnerStart(), .InnerEnd() extension methods on query types
  • SyntaxEditor.Insert(InsertionQuery, ...) overloads

Added:

  • BoundaryQuery record implementing INodeQuery
  • BoundarySide enum (Start/End)
  • .Start() and .End() methods on BlockNodeQuery and NamedBlockQuery
  • .InnerStart(blockName) and .InnerEnd(blockName) convenience extensions for IBlockContainerNode queries

Example

// Insert at beginning of block content
editor.InsertAfter(Query.BraceBlock.First().Start(), "// first line")

// Insert at end of block content  
editor.InsertBefore(Query.BraceBlock.First().End(), "// last line")

// Insert before/after a node
editor.InsertBefore(Query.AnyIdent.First(), "prefix ")
editor.InsertAfter(Query.AnyIdent.First(), " suffix")

// For IBlockContainerNode syntax nodes (convenience methods)
editor.InsertAfter(Query.Syntax<FunctionSyntax>().Named("main").InnerStart("body"), "// start")
editor.InsertBefore(Query.Syntax<FunctionSyntax>().Named("main").InnerEnd("body"), "// end")

Testing

  • All 1461 existing tests pass
  • Updated tests in SyntaxEditorTests.cs, SyntaxNodeTests.cs, SyntaxTreeTests.cs
  • Updated E2E tests in GlslEditorTests.cs
  • Updated benchmarks in SyntaxTreeBenchmarks.cs

@dsisco11 dsisco11 merged commit 2484cfa into master Jan 6, 2026
1 check passed
@dsisco11 dsisco11 deleted the sisco/refactor-block-queries branch January 6, 2026 05:27
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.

1 participant