import * as vscode from 'vscode'; const document = vscode.window.activeTextEditor?.document; if (document) { const line = document.lineAt(0); const lineTokens = line.tokens; console.log(lineTokens); }
import * as vscode from 'vscode'; import { LineTokens } from 'vscode'; function parseLineTokens(lineTokens: LineTokens) { const tokens: string[] = []; let index = 0; while (index < lineTokens.getCount()) { tokens.push(lineTokens.getTokenText(index)); index += 1; } console.log(tokens); } const document = vscode.window.activeTextEditor?.document; if (document) { const line = document.lineAt(0); const lineTokens = line.tokens; parseLineTokens(lineTokens); }This code example demonstrates how to parse the line tokens for the first line of an active text editor. It uses the `getCount` and `getTokenText` methods of the `LineTokens` interface to iterate over all the tokens used in the line of code and store them in an array. This code example also imports the `LineTokens` interface from the `vscode` package library.