Skip to content

Implement `getText` for extension API

Administrator requested to merge tj/getText into main

Created by: tjkandala

I wasn't able to find a method like getText from VS Code's extension API, so I implemented this POC.

Example usage:

function provideHover(document, position) {
    const word = document.getText(document.getWordRangeAtPosition(position))
    // Elided
}

Motivation

I went through the extension registry and found only two non-"hello world" extensions that registered hover providers. Both were authored by Sourcegraph contributors and implemented their own version of getText, but without the utilities available to TextDocument methods (token-highlights, string-references).

Implementing more helpers would make authoring extensions more accessible and reduce extension bundle sizes due to code reuse.

Merge request reports

Loading