Skip to content

search: use chunk matches to render multiline streamed results

Warren Gifford requested to merge rvt/src-cli-chunk22 into main

Created by: rvantonder

This switches src search -stream 'query' to use the chunk match result type.

This means:

  • Accurate result counts for patterns that match across newlines

  • Multiline/structural search highlighting is now accurate (previously structural search was highlighting was broken)

New JSON schema for src search -stream -json 'query'

new schema
{
  "type": "content",
  "path": ".golangci.yml",
  "repository": "github.com/sourcegraph/sourcegraph",
  "branches": [
    ""
  ],
  "commit": "994c2bc9fd0d5a5baaa6ed1664b3fa7bfa96e4aa",
  "chunkMatches": [
    {
      "content": "    - sheets.go",
      "contentStart": {
        "offset": 3092,
        "line": 98,
        "column": 0
      },
      "ranges": [
        {
          "start": {
            "offset": 3098,
            "line": 98,
            "column": 6
          },
          "end": {
            "offset": 3107,
            "line": 98,
            "column": 15
          }
        }
      ]
    },
    {
      "content": "    - slack.go",
      "contentStart": {
        "offset": 3108,
        "line": 99,
        "column": 0
      },
      "ranges": [
        {
          "start": {
            "offset": 3114,
            "line": 99,
            "column": 6
          },
          "end": {
            "offset": 3122,
            "line": 99,
            "column": 14
          }
        }
      ]
    }
  ]
}
old schema
{
  "type": "content",
  "path": ".golangci.yml",
  "repository": "github.com/sourcegraph/sourcegraph",
  "branches": [
    ""
  ],
  "commit": "477f4cf74b6deef0f78ba5ec316fd299bddc621c",
  "lineMatches": [
    {
      "line": "    - sheets.go",
      "lineNumber": 98,
      "offsetAndLengths": [
        [
          6,
          9
        ]
      ]
    },
    {
      "line": "    - slack.go",
      "lineNumber": 99,
      "offsetAndLengths": [
        [
          6,
          8
        ]
      ]
    }
  ]
}

PR details:

I am making the decision to remove line matches entirely for this option, because otherwise we can never move away from line matches/preview to adopt chunk matches as the only source of truth, which we really should do. It is possible that this could break clients/consumers that expect line matches for the -stream -json option, and the changelog is updated accordingly.

Maybe this should be a major version bump, but looks like we keep src-cli releases in tandem with Sourcegraph? Or is this minor enough that we can ship this with a minor src release (to what extent have we encouraged using search -stream? consumers could in theory remove -stream and revert to using GQL to regain "old" behavior). If we don't feel comfortable with removing LineMatches in this PR, I would prefer holding out until 4.0 release so I can have the opportunity to piggy back on the "breaking change" version bump.

I think the follow up we want is:

  • make search -stream the default search
  • update the GQL search command to be an option like search -gql instead (only useful for clients who want to get JSON I imagine).

Test plan

Updates tests

Merge request reports

Loading