How to use the vscode-html-languageservice.getLanguageService 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 onecentlin / laravel-blade-snippets-vscode / src / extension.ts View on Github external
import * as path from 'path';
import * as vscode from 'vscode';
import * as html from 'vscode-html-languageservice';
import * as lst from 'vscode-languageserver-types';
import * as nls from 'vscode-nls';
import { BladeFormattingEditProvider } from './providers/BladeFormattingEditProvider';
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, RequestType, TextDocumentPositionParams } from 'vscode-languageclient';

const service = html.getLanguageService()
const localize = nls.loadMessageBundle();

class DocumentHighlight implements vscode.DocumentHighlightProvider
{
    provideDocumentHighlights(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): vscode.DocumentHighlight[] | Thenable {
        let doc = lst.TextDocument.create(document.uri.fsPath, 'html', 1, document.getText());
        return (service.findDocumentHighlights(doc, position, service.parseHTMLDocument(doc)) as any);
    }
} // DocumentHighlight

export function activate(context: vscode.ExtensionContext) {

    let documentSelector: vscode.DocumentSelector = {
        language: 'blade',
        scheme: 'file'
    };
github microsoft / vscode-extension-samples / smart-template-strings-sample / src / extension.ts View on Github external
export function activate(context: vscode.ExtensionContext) {

    // create and keep html language service
    const service = html.getLanguageService();

    vscode.languages.registerCompletionItemProvider(['typescript', 'javascript'], {
        provideCompletionItems(doc, pos) {

            const offset = doc.offsetAt(pos);
            const source = ts.createSourceFile(doc.fileName, doc.getText(), ts.ScriptTarget.Latest, true);

            let token = (ts as any).getTokenAtPosition(source, offset)
            let template: ts.TaggedTemplateExpression;
            while (token) {
                if (token.kind === ts.SyntaxKind.TaggedTemplateExpression) {
                    template = token;
                    break;
                }
                token = token.parent;
            }
github runem / lit-analyzer / packages / lit-analyzer / src / analyze / document-analyzer / html / lit-html-vscode-service.ts View on Github external
import * as ts from "typescript";
import * as vscode from "vscode-html-languageservice";
import { HtmlDocument } from "../../parse/document/text-document/html-document/html-document";
import { textPartsToRanges } from "../../parse/document/virtual-document/virtual-document";
import { LitClosingTagInfo } from "../../types/lit-closing-tag-info";
import { LitFormatEdit } from "../../types/lit-format-edit";

const htmlService = vscode.getLanguageService();

function makeVscTextDocument(htmlDocument: HtmlDocument): vscode.TextDocument {
	return vscode.TextDocument.create("untitled://embedded.html", "html", 1, htmlDocument.virtualDocument.text);
}

function makeVscHtmlDocument(vscTextDocument: vscode.TextDocument) {
	return htmlService.parseHTMLDocument(vscTextDocument);
}

export class LitHtmlVscodeService {
	getClosingTagAtOffset(document: HtmlDocument, offset: number): LitClosingTagInfo | undefined {
		const vscTextDocument = makeVscTextDocument(document);
		const vscHtmlDocument = makeVscHtmlDocument(vscTextDocument);
		const htmlLSPosition = vscTextDocument.positionAt(offset);

		const tagComplete = htmlService.doTagComplete(vscTextDocument, htmlLSPosition, vscHtmlDocument);
github microsoft / typescript-lit-html-plugin / src / index.ts View on Github external
private get htmlLanguageService(): HtmlLanguageService {
        if (!this._htmlLanguageService) {
            this._htmlLanguageService = getLanguageService();
        }
        return this._htmlLanguageService;
    }
github dotnet / aspnetcore-tooling / src / Razor / src / Microsoft.AspNetCore.Razor.VSCode / src / Html / HtmlTagCompletionProvider.ts View on Github external
public register() {
        this.htmlLanguageService = getHtmlLanguageService();

        const onChangeRegistration = vscode.workspace.onDidChangeTextDocument(
            args => this.onDidChangeTextDocument(args.document, args.contentChanges));

        const onActiveTextEditorChange = vscode.window.onDidChangeActiveTextEditor(() => this.checkIfEnabled());

        this.checkIfEnabled();

        return vscode.Disposable.from(onChangeRegistration, onActiveTextEditorChange);
    }
github onecentlin / laravel-blade-snippets-vscode / src / providers / BladeFormattingEditProvider.ts View on Github external
import * as vscode from 'vscode';
import * as html from 'vscode-html-languageservice';
import * as lst from 'vscode-languageserver-types';
import { BladeFormatter, IBladeFormatterOptions } from "../services/BladeFormatter";

const service = html.getLanguageService()

export class BladeFormattingEditProvider implements vscode.DocumentFormattingEditProvider, vscode.DocumentRangeFormattingEditProvider 
{
    formatterOptions: IBladeFormatterOptions;
    
    provideDocumentFormattingEdits(document: vscode.TextDocument, options: vscode.FormattingOptions): vscode.TextEdit[] {
        let range = new vscode.Range(new vscode.Position(0, 0), new vscode.Position((document.lineCount - 1), Number.MAX_VALUE));
        return this.provideFormattingEdits(document, document.validateRange(range), options);
    }

    provideDocumentRangeFormattingEdits(document: vscode.TextDocument, range: vscode.Range, options: vscode.FormattingOptions): vscode.TextEdit[] {
        return this.provideFormattingEdits(document, range, options);
    }

    private provideFormattingEdits(document: vscode.TextDocument, range: vscode.Range, options: vscode.FormattingOptions): vscode.TextEdit[] {