Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'
};
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;
}
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);
private get htmlLanguageService(): HtmlLanguageService {
if (!this._htmlLanguageService) {
this._htmlLanguageService = getLanguageService();
}
return this._htmlLanguageService;
}
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);
}
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[] {