How to use the vscode-html-languageservice.TextDocument function in vscode-html-languageservice

To help you get started, we’ve selected a few vscode-html-languageservice examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github runem / lit-analyzer / packages / lit-analyzer / src / analyze / document-analyzer / html / lit-html-vscode-service.ts View on Github external
wrapLineLength: 90,
			unformatted: "",
			contentUnformatted: "pre,code,textarea",
			indentInnerHtml: true,
			preserveNewLines: true,
			maxPreserveNewLines: undefined,
			indentHandlebars: false,
			endWithNewline: false,
			extraLiners: "head, body, /html",
			wrapAttributes: "auto"
		});

		const hasLeadingNewline = originalHtml.startsWith("\n");
		const hasTrailingNewline = originalHtml.endsWith("\n");

		const newHtml = `${hasLeadingNewline ? "\n" : ""}${vscode.TextDocument.applyEdits(vscTextDocument, edits)}${hasTrailingNewline ? "\n" : ""}`;

		const splitted = newHtml.split(/\[#+\]/);

		return splitted.map((newText, i) => {
			const range = ranges[i];
			return { range: { document, ...range }, newText };
		});
	}
}
github runem / lit-analyzer / packages / lit-analyzer / src / analyze / document-analyzer / html / lit-html-vscode-service.ts View on Github external
function makeVscTextDocument(htmlDocument: HtmlDocument): vscode.TextDocument {
	return vscode.TextDocument.create("untitled://embedded.html", "html", 1, htmlDocument.virtualDocument.text);
}
github runem / lit-analyzer / packages / lit-analyzer / src / analyze / document-analyzer / html / lit-html-vscode-service.ts View on Github external
format(document: HtmlDocument, settings: ts.FormatCodeSettings): LitFormatEdit[] {
		const parts = document.virtualDocument.getPartsAtOffsetRange({
			start: 0,
			end: document.virtualDocument.location.end - document.virtualDocument.location.start
		});

		const ranges = textPartsToRanges(parts);
		const originalHtml = parts.map(p => (typeof p === "string" ? p : `[#${"#".repeat(p.getText().length)}]`)).join("");
		const vscTextDocument = vscode.TextDocument.create("untitled://embedded.html", "html", 1, originalHtml);

		const edits = htmlService.format(vscTextDocument, undefined, {
			tabSize: settings.tabSize,
			insertSpaces: !!settings.convertTabsToSpaces,
			wrapLineLength: 90,
			unformatted: "",
			contentUnformatted: "pre,code,textarea",
			indentInnerHtml: true,
			preserveNewLines: true,
			maxPreserveNewLines: undefined,
			indentHandlebars: false,
			endWithNewline: false,
			extraLiners: "head, body, /html",
			wrapAttributes: "auto"
		});