vscode-languageclient#TextDocument TypeScript Examples

The following examples show how to use vscode-languageclient#TextDocument. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: test-utils.ts    From ui5-language-assistant with Apache License 2.0 7 votes vote down vote up
export function getRanges(xmlSnippet: string): vscode.Range[] {
  const RANGE_START_CHAR = "⭲";
  const RANGE_END_CHAR = "⭰";

  const document = TextDocument.create("uri", "xml", 0, xmlSnippet);
  const ranges: vscode.Range[] = [];
  while (xmlSnippet.indexOf(RANGE_START_CHAR) !== -1) {
    const rangeStartIndex = xmlSnippet.indexOf(RANGE_START_CHAR);
    xmlSnippet = xmlSnippet.replace(RANGE_START_CHAR, "");
    const startPosition = document.positionAt(rangeStartIndex + 1);
    const rangeEndIndex = xmlSnippet.indexOf(RANGE_END_CHAR);
    if (rangeEndIndex === -1) {
      break;
    }

    xmlSnippet = xmlSnippet.replace(RANGE_END_CHAR, "");
    const endPosition = document.positionAt(rangeEndIndex + 1);
    const vscodeRange = new vscode.Range(
      new vscode.Position(startPosition.line, startPosition.character),
      new vscode.Position(endPosition.line, endPosition.character)
    );

    ranges.push(vscodeRange);
  }

  return ranges;
}