Skip to content

Search: send highlighted content over stream API

Administrator requested to merge cc/streamed-highlighting into main

Created by: camdencheek

Things that might work (this is only minimally tested):

  • Sending highlighted HTML with each chunk match. Each chunk match will now have a new field htmlDecoratedContent
  • Configuring the number of file matches that are sent pre-highlighted with the dl query param
  • Configuring the number of context lines with the dc query param

Things that definitely do not work:

  • Merging adjacent or overlapping chunks when the number of context lines is taken into account
  • Displaying the results in the UI (we still depend on line matches)

Example payload:

{
  "type": "content",
  "path": "client/web/src/enterprise/insights/components/insights-view-grid/utils/grid-layout-generator.ts",
  "repositoryID": 8,
  "repository": "github.com/sourcegraph/sourcegraph",
  "repoStars": 6532,
  "repoLastFetched": "2022-08-09T23:33:52.287003Z",
  "branches": [
    ""
  ],
  "commit": "ed4bf72a258b013c75f56b14166fc1a53457cd81",
  "chunkMatches": [
    {
      "content": "const MINIMAL_SERIES_FOR_ASIDE_LEGEND = 3",
      "htmlDecoratedContent": "<tr><td class=\"line\" data-line=\"19\"></td><td class=\"code\"><div><span class=\"hl-source hl-ts\">\n</span></div></td></tr>\n<tr><td class=\"line\" data-line=\"20\"></td><td class=\"code\"><div><span class=\"hl-source hl-ts\"><span class=\"hl-meta hl-var hl-expr hl-ts\"><span class=\"hl-storage hl-type hl-ts\">const</span> <span class=\"hl-meta hl-var-single-variable hl-expr hl-ts\"><span class=\"hl-meta hl-definition hl-variable hl-ts\"><span class=\"hl-variable hl-other hl-constant hl-ts\">MINIMAL_SERIES_FOR_ASIDE_LEGEND</span></span> </span><span class=\"hl-keyword hl-operator hl-assignment hl-ts\">=</span> <span class=\"hl-constant hl-numeric hl-decimal hl-ts\">3</span></span>\n</span></div></td></tr>\n<tr><td class=\"line\" data-line=\"21\"></td><td class=\"code\"><div><span class=\"hl-source hl-ts\"><span class=\"hl-meta hl-var hl-expr hl-ts\"><span class=\"hl-storage hl-type hl-ts\">const</span> <span class=\"hl-meta hl-var-single-variable hl-expr hl-ts\"><span class=\"hl-meta hl-definition hl-variable hl-ts\"><span class=\"hl-variable hl-other hl-constant hl-ts\">MIN_WIDTHS_LANDSCAPE_MODE</span></span><span class=\"hl-meta hl-type hl-annotation hl-ts\"><span class=\"hl-keyword hl-operator hl-type hl-annotation hl-ts\">:</span> <span class=\"hl-entity hl-name hl-type hl-ts\">Record</span><span class=\"hl-meta hl-type hl-parameters hl-ts\"><span class=\"hl-punctuation hl-definition hl-typeparameters hl-begin hl-ts\">&lt;</span></span><span class=\"hl-meta hl-type hl-parameters hl-ts\"><span class=\"hl-entity hl-name hl-type hl-ts\">BreakpointName</span><span class=\"hl-punctuation hl-separator hl-comma hl-ts\">,</span> <span class=\"hl-support hl-type hl-primitive hl-ts\">number</span></span><span class=\"hl-meta hl-type hl-parameters hl-ts\"><span class=\"hl-punctuation hl-definition hl-typeparameters hl-end hl-ts\">&gt;</span></span> </span></span><span class=\"hl-keyword hl-operator hl-assignment hl-ts\">=</span> <span class=\"hl-meta hl-objectliteral hl-ts\"><span class=\"hl-punctuation hl-definition hl-block hl-ts\">{</span> <span class=\"hl-meta hl-object hl-member hl-ts\"><span class=\"hl-meta hl-object-literal hl-key hl-ts\">xs</span></span><span class=\"hl-meta hl-object hl-member hl-ts\"><span class=\"hl-meta hl-object-literal hl-key hl-ts\"><span class=\"hl-punctuation hl-separator hl-key-value hl-ts\">:</span></span> <span class=\"hl-constant hl-numeric hl-decimal hl-ts\">1</span></span><span class=\"hl-punctuation hl-separator hl-comma hl-ts\">,</span> <span class=\"hl-meta hl-object hl-member hl-ts\"><span class=\"hl-meta hl-object-literal hl-key hl-ts\">sm</span></span><span class=\"hl-meta hl-object hl-member hl-ts\"><span class=\"hl-meta hl-object-literal hl-key hl-ts\"><span class=\"hl-punctuation hl-separator hl-key-value hl-ts\">:</span></span> <span class=\"hl-constant hl-numeric hl-decimal hl-ts\">3</span></span><span class=\"hl-punctuation hl-separator hl-comma hl-ts\">,</span> <span class=\"hl-meta hl-object hl-member hl-ts\"><span class=\"hl-meta hl-object-literal hl-key hl-ts\">md</span></span><span class=\"hl-meta hl-object hl-member hl-ts\"><span class=\"hl-meta hl-object-literal hl-key hl-ts\"><span class=\"hl-punctuation hl-separator hl-key-value hl-ts\">:</span></span> <span class=\"hl-constant hl-numeric hl-decimal hl-ts\">4</span></span><span class=\"hl-punctuation hl-separator hl-comma hl-ts\">,</span> <span class=\"hl-meta hl-object hl-member hl-ts\"><span class=\"hl-meta hl-object-literal hl-key hl-ts\">lg</span></span><span class=\"hl-meta hl-object hl-member hl-ts\"><span class=\"hl-meta hl-object-literal hl-key hl-ts\"><span class=\"hl-punctuation hl-separator hl-key-value hl-ts\">:</span></span> <span class=\"hl-constant hl-numeric hl-decimal hl-ts\">4</span> </span><span class=\"hl-punctuation hl-definition hl-block hl-ts\">}</span></span></span>\n</span></div></td></tr>",
      "contentStart": {
        "offset": 413,
        "line": 19,
        "column": 0
      },
      "ranges": [
        {
          "start": {
            "offset": 419,
            "line": 19,
            "column": 6
          },
          "end": {
            "offset": 426,
            "line": 19,
            "column": 13
          }
        }
      ]
    },
    {
      "content": "    (isSearchBasedInsight(insight) && insight.series.length > MINIMAL_SERIES_FOR_ASIDE_LEGEND)",
      "htmlDecoratedContent": "<tr><td class=\"line\" data-line=\"27\"></td><td class=\"code\"><div><span class=\"hl-source hl-ts\">    <span class=\"hl-meta hl-function-call hl-ts\"><span class=\"hl-entity hl-name hl-function hl-ts\">isComputeInsight</span></span><span class=\"hl-meta hl-brace hl-round hl-ts\">(</span><span class=\"hl-variable hl-other hl-readwrite hl-ts\">insight</span><span class=\"hl-meta hl-brace hl-round hl-ts\">)</span> <span class=\"hl-keyword hl-operator hl-logical hl-ts\">||</span>\n</span></div></td></tr>\n<tr><td class=\"line\" data-line=\"28\"></td><td class=\"code\"><div><span class=\"hl-source hl-ts\">    <span class=\"hl-meta hl-brace hl-round hl-ts\">(</span><span class=\"hl-meta hl-function-call hl-ts\"><span class=\"hl-entity hl-name hl-function hl-ts\">isSearchBasedInsight</span></span><span class=\"hl-meta hl-brace hl-round hl-ts\">(</span><span class=\"hl-variable hl-other hl-readwrite hl-ts\">insight</span><span class=\"hl-meta hl-brace hl-round hl-ts\">)</span> <span class=\"hl-keyword hl-operator hl-logical hl-ts\">&amp;&amp;</span> <span class=\"hl-variable hl-other hl-object hl-ts\">insight</span><span class=\"hl-punctuation hl-accessor hl-ts\">.</span><span class=\"hl-variable hl-other hl-object hl-property hl-ts\">series</span><span class=\"hl-punctuation hl-accessor hl-ts\">.</span><span class=\"hl-support hl-variable hl-property hl-ts\">length</span> <span class=\"hl-keyword hl-operator hl-relational hl-ts\">&gt;</span> <span class=\"hl-variable hl-other hl-constant hl-ts\">MINIMAL_SERIES_FOR_ASIDE_LEGEND</span><span class=\"hl-meta hl-brace hl-round hl-ts\">)</span>\n</span></div></td></tr>\n<tr><td class=\"line\" data-line=\"29\"></td><td class=\"code\"><div><span class=\"hl-source hl-ts\">\n</span></div></td></tr>",
      "contentStart": {
        "offset": 771,
        "line": 27,
        "column": 0
      },
      "ranges": [
        {
          "start": {
            "offset": 833,
            "line": 27,
            "column": 62
          },
          "end": {
            "offset": 840,
            "line": 27,
            "column": 69
          }
        }
      ]
    }
  ]
}

Test plan

This should not be merged as is, so no tests necessary

Merge request reports

Loading