Skip to content

Feature request: Expose original source text for TSqlFragment (Debugger & API usability) #203

Description

@Harald-PH

Problem

Working with Microsoft.SqlServer.TransactSql.ScriptDom is unnecessarily hard in practice,
especially during debugging.

TSqlFragment objects do not expose the original source text they represent.
Instead, consumers must manually reconstruct the SQL text via:

  • FirstTokenIndex / LastTokenIndex
  • ScriptTokenStream
  • or StartOffset / FragmentLength

This makes debugging extremely cumbersome:
in Visual Studio, inspecting a fragment does not show the SQL code,
only a large object graph with token indices.

This significantly affects developer productivity and discoverability of the AST.

Current workaround (non-trivial)

Every consumer needs to implement helper code such as:

    extension(TSqlFragment node)
    {
        public string SourcePart => string.Join("",
            node
                .ScriptTokenStream
                .Skip(node.FirstTokenIndex)
                .Take(node.LastTokenIndex - node.FirstTokenIndex + 1)
                .Select(i => i.Text)
                );
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions