Skip to content

How to efficiently read a lot of code from the active editor? #2754

Discussion options

You must be logged in to vote

Hi @ryyHardy ,

I think the best way may vary depending on the content you need to read. As more code you need, more complex it may be. Either way, if you need the content from the editor instead of the disk, you should use the TextEditor API.

I wonder if the currently visible text of the editor is a good start. If yes, you could use the TextEditor.visibleRanges property and have access to the text that is being displayed to the user. Something like this:

    function getVisibleText(): string {
        const editor = window.activeTextEditor;
        if (!editor) {
            return '';
        }
        const visibleRanges = editor.visibleRanges;
        return visibleRanges.map(range => e…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ryyHardy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants