Skip to content

Intentions API : Highlight

Amin Yahyaabadi edited this page Jun 21, 2021 · 2 revisions

Intentions Highlight API allows you to show intentions from your package based on scopes

Defining a provider

You'll need to add this in your package.json

"providedServices": {
  "intentions:highlight": {
    "versions": {
      "2.0.0": "provideIntentions"
    }
  }
}

and you should return a provider object from provideIntentions function of your package

Note: You can return more than one providers at once by wrapping them in an array

const colorRegexp = /rgb\(\d+, ?\d+, ?\d+\)|rgba\(\d+, ?\d+, ?\d+, ?\d?\.?\d+\)|rgba\(#[0-9a-fA-F]{3,6}, ?\d?\.?\d+\)|#[0-9a-fA-F]{3,6}/g

export function activate: function() {
  console.log('activate')
}

export function provideIntentions: function() {
  // Structure of an provider object
  return {
    grammarScopes: ['source.js'],    // ['*'] also works
    getIntentions({textEditor, visibleRange}) {
      // Note: You can also return a promise
      const matches = []
      const text = textEditor.scanInBufferRange(colorRegexp, visibleRange, function(match) {
        matches.push({
          range: match.range,
          created: intentionCreated // optional
        })
      })
      return matches
    }
  }
}

export function intentionCreated({textEditor, marker, matchedText}) {
  console.log('intention overlay created')
}
Clone this wiki locally