Browse documentation

replace_range

[refactoring]

Replaces a nonempty contiguous range in a loaded C# document. Exact source guards reject stale edits. Use applyChanges=false for a preview. Prefer replace_member for complete member declarations.

Unreleased tool. Available in development builds after Glider 11.0.0.

Before you use this tool

Writes files by default. Set applyChanges: false to preview the diff. Inspect the diff before application.

Try it locally in the Glider playground

Parameters

NameTypeRequiredDescription
filePathstringYesExisting loaded .cs file. Absolute or loaded-root-relative.
startLinenumberYesInclusive start line, one-based.
startColumnnumberYesInclusive start column, one-based UTF-16 units.
endLinenumberYesExclusive end line, one-based.
endColumnnumberYesExclusive end column, one-based UTF-16 units.
expectedTextstringYesNonempty exact source, including whitespace and line endings. Read get_file_contents with includeRawContent=true.
replacementTextstringYesExact replacement. Empty text deletes the range. No automatic formatting occurs.
applyChangesbooleanNoApply to disk by default. Set false to preview. Default: true
failOnErrorsbooleanNoRefuse any error in edited documents, including existing errors, or incomplete target checks. Default: false
includeDiffbooleanNoInclude the unified diff. Default: true
maxDiffCharsnumberNoMaximum diff characters. Use 0 for unlimited. Default: 50000
pathStylestringNoPath style: absolute or relative to the loaded root. Default: "absolute"
responseDetailstringNocompact returns results and actionable state. full adds diagnostic metadata under responseDiagnostics. Default: "compact"

Examples

Replace sample paths and symbol keys with values from your workspace.

Replace the digit in a line containing int x = 1;

Arguments
{
  "filePath": "Sample.cs",
  "startLine": 1,
  "startColumn": 9,
  "endLine": 1,
  "endColumn": 10,
  "expectedText": "1",
  "replacementText": "2",
  "applyChanges": false
}
Full MCP request
Full MCP request
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "replace_range",
    "arguments": {
      "filePath": "Sample.cs",
      "startLine": 1,
      "startColumn": 9,
      "endLine": 1,
      "endColumn": 10,
      "expectedText": "1",
      "replacementText": "2",
      "applyChanges": false
    }
  }
}
Illustrative response
{
  "success": true,
  "status": "preview",
  "preview": true,
  "applied": false,
  "diskWriteAttempted": false,
  "filesChanged": 0,
  "wouldChange": true,
  "filePath": "/project/OrderService.cs",
  "workspaceUpdate": "unchanged",
  "diagnostics": {
    "errorCount": 0,
    "warningCount": 0,
    "items": []
  },
  "coverage": {
    "complete": true,
    "scope": "editedDocuments",
    "targets": [
      {
        "projectId": "example-project-id",
        "projectName": "Sample",
        "checked": true,
        "reason": null
      }
    ]
  },
  "unifiedDiff": "..."
}

Response Notes

Returns oldRange, newRange, diagnostics, target coverage, and disk and workspace outcomes. Coordinates use one-based lines and UTF-16 columns with exclusive ends. The complete edited document is checked in every linked project. These checks exclude other files and dependent projects. Check project diagnostics after imports, declarations, signatures, or directives change. Apply awaits one named-file sync without reload. Never repeat a completed or uncertain write. Read bounded get_file_contents with includeRawContent=true for exact whitespace and line endings, including the final returned line terminator. A null rawContent requires a smaller window. UTF-8 and BOM-marked UTF-16 encodings are supported. Empty ranges and boundaries inside CRLF or surrogate pairs are refused. Results use top-level fields with success. Compact is the default; full adds responseDiagnostics. Both modes retain errors, coverage, partial state, and recovery advice.