vscode-html-languageservice
Advanced tools
Comparing version 2.1.11 to 3.0.0-next.0
@@ -0,1 +1,7 @@ | ||
NEXT (3.0.0) | ||
================== | ||
* Added API `htmlLanguageService.getSelectionRanges` returning selection ranges for a set of positions | ||
* New API `newHTMLDataProvider` | ||
* generate es6 | ||
2.1.3 / 2018-04-16 | ||
@@ -2,0 +8,0 @@ ================== |
// copied from js-beautify/js/lib/beautify-css.js | ||
// version: 1.9.0-beta5 | ||
// version: 1.9.0 | ||
/* AUTO-GENERATED. DO NOT MODIFY. */ | ||
@@ -4,0 +4,0 @@ /* |
import { TextDocument, Position, CompletionList, Hover, Range, SymbolInformation, TextEdit, DocumentHighlight, DocumentLink, FoldingRange } from 'vscode-languageserver-types'; | ||
import { Scanner, HTMLDocument, CompletionConfiguration, ICompletionParticipant, HTMLFormatConfiguration, DocumentContext, IHTMLDataProvider } from './htmlLanguageTypes'; | ||
import { Scanner, HTMLDocument, CompletionConfiguration, ICompletionParticipant, HTMLFormatConfiguration, DocumentContext, IHTMLDataProvider, SelectionRange, HTMLDataV1 } from './htmlLanguageTypes'; | ||
import { HTMLDataProvider } from './languageFacts'; | ||
export * from './htmlLanguageTypes'; | ||
export * from 'vscode-languageserver-types'; | ||
export { HTMLDataProvider } from './languageFacts'; | ||
export interface LanguageService { | ||
@@ -20,3 +20,3 @@ createScanner(input: string, initialOffset?: number): Scanner; | ||
}): FoldingRange[]; | ||
getSelectionRanges(document: TextDocument, position: Position): Range[]; | ||
getSelectionRanges(document: TextDocument, positions: Position[]): SelectionRange[][]; | ||
} | ||
@@ -27,1 +27,2 @@ export interface LanguageServiceOptions { | ||
export declare function getLanguageService(options?: LanguageServiceOptions): LanguageService; | ||
export declare function newHTMLDataProvider(id: string, customData: HTMLDataV1): HTMLDataProvider; |
@@ -15,9 +15,8 @@ /*--------------------------------------------------------------------------------------------- | ||
import { getFoldingRanges } from './services/htmlFolding'; | ||
import { handleCustomDataProviders } from './languageFacts'; | ||
import { handleCustomDataProviders, HTMLDataProvider } from './languageFacts'; | ||
import { getSelectionRanges } from './services/htmlSelectionRange'; | ||
export * from './htmlLanguageTypes'; | ||
export * from 'vscode-languageserver-types'; | ||
export { HTMLDataProvider } from './languageFacts'; | ||
export function getLanguageService(options) { | ||
var htmlCompletion = new HTMLCompletion(); | ||
const htmlCompletion = new HTMLCompletion(); | ||
if (options && options.customDataProviders) { | ||
@@ -27,16 +26,19 @@ handleCustomDataProviders(options.customDataProviders); | ||
return { | ||
createScanner: createScanner, | ||
parseHTMLDocument: function (document) { return parse(document.getText()); }, | ||
createScanner, | ||
parseHTMLDocument: document => parse(document.getText()), | ||
doComplete: htmlCompletion.doComplete.bind(htmlCompletion), | ||
setCompletionParticipants: htmlCompletion.setCompletionParticipants.bind(htmlCompletion), | ||
doHover: doHover, | ||
format: format, | ||
findDocumentHighlights: findDocumentHighlights, | ||
findDocumentLinks: findDocumentLinks, | ||
findDocumentSymbols: findDocumentSymbols, | ||
getFoldingRanges: getFoldingRanges, | ||
getSelectionRanges: getSelectionRanges, | ||
doHover, | ||
format, | ||
findDocumentHighlights, | ||
findDocumentLinks, | ||
findDocumentSymbols, | ||
getFoldingRanges, | ||
getSelectionRanges, | ||
doTagComplete: htmlCompletion.doTagComplete.bind(htmlCompletion), | ||
}; | ||
} | ||
export function newHTMLDataProvider(id, customData) { | ||
return new HTMLDataProvider(id, customData); | ||
} | ||
//# sourceMappingURL=htmlLanguageService.js.map |
import { TextDocument, Position, Range } from 'vscode-languageserver-types'; | ||
/** | ||
* Enum of known selection range kinds | ||
*/ | ||
export declare enum SelectionRangeKind { | ||
/** | ||
* Empty Kind. | ||
*/ | ||
Empty = "", | ||
/** | ||
* The statment kind, its value is `statement`, possible extensions can be | ||
* `statement.if` etc | ||
*/ | ||
Statement = "statement", | ||
/** | ||
* The declaration kind, its value is `declaration`, possible extensions can be | ||
* `declaration.function`, `declaration.class` etc. | ||
*/ | ||
Declaration = "declaration" | ||
} | ||
/** | ||
* Represents a selection range | ||
*/ | ||
export interface SelectionRange { | ||
/** | ||
* Range of the selection. | ||
*/ | ||
range: Range; | ||
/** | ||
* Describes the kind of the selection range such as `statemet' or 'declaration'. See | ||
* [SelectionRangeKind](#SelectionRangeKind) for an enumeration of standardized kinds. | ||
*/ | ||
kind: string; | ||
} | ||
export interface HTMLFormatConfiguration { | ||
@@ -3,0 +36,0 @@ tabSize?: number; |
@@ -6,2 +6,23 @@ /*--------------------------------------------------------------------------------------------- | ||
'use strict'; | ||
// #region Proposed types, remove once added to vscode-languageserver-types | ||
/** | ||
* Enum of known selection range kinds | ||
*/ | ||
export var SelectionRangeKind; | ||
(function (SelectionRangeKind) { | ||
/** | ||
* Empty Kind. | ||
*/ | ||
SelectionRangeKind["Empty"] = ""; | ||
/** | ||
* The statment kind, its value is `statement`, possible extensions can be | ||
* `statement.if` etc | ||
*/ | ||
SelectionRangeKind["Statement"] = "statement"; | ||
/** | ||
* The declaration kind, its value is `declaration`, possible extensions can be | ||
* `declaration.function`, `declaration.class` etc. | ||
*/ | ||
SelectionRangeKind["Declaration"] = "declaration"; | ||
})(SelectionRangeKind || (SelectionRangeKind = {})); | ||
export var TokenType; | ||
@@ -8,0 +29,0 @@ (function (TokenType) { |
@@ -7,6 +7,6 @@ /*--------------------------------------------------------------------------------------------- | ||
import { getHTML5DataProvider } from './data/html5'; | ||
export var builtinDataProviders = [ | ||
export const builtinDataProviders = [ | ||
getHTML5DataProvider() | ||
]; | ||
var customDataProviders = []; | ||
const customDataProviders = []; | ||
export function getAllDataProviders() { | ||
@@ -16,3 +16,3 @@ return builtinDataProviders.concat(customDataProviders); | ||
export function handleCustomDataProviders(providers) { | ||
providers.forEach(function (p) { | ||
providers.forEach(p => { | ||
customDataProviders.push(p); | ||
@@ -19,0 +19,0 @@ }); |
@@ -14,7 +14,8 @@ /*--------------------------------------------------------------------------------------------- | ||
tags: HTML5_TAGS, | ||
globalAttributes: HTML5_GLOBAL_ATTRIBUTES.concat(HTML5_EVENTS), | ||
globalAttributes: [...HTML5_GLOBAL_ATTRIBUTES, ...HTML5_EVENTS], | ||
valueSets: HTML5_VALUE_MAP | ||
}); | ||
} | ||
export var HTML5_GLOBAL_ATTRIBUTES = ARIA_ATTRIBUTES.concat([ | ||
export const HTML5_GLOBAL_ATTRIBUTES = [ | ||
...ARIA_ATTRIBUTES, | ||
{ | ||
@@ -91,4 +92,4 @@ name: 'accesskey' | ||
} | ||
]); | ||
export var HTML5_VALUE_MAP = [ | ||
]; | ||
export const HTML5_VALUE_MAP = [ | ||
{ | ||
@@ -95,0 +96,0 @@ name: 'b', |
@@ -6,3 +6,3 @@ /*--------------------------------------------------------------------------------------------- | ||
'use strict'; | ||
export var ARIA_ATTRIBUTES = [ | ||
export const ARIA_ATTRIBUTES = [ | ||
{ | ||
@@ -9,0 +9,0 @@ "name": "aria-activedescendant", |
@@ -6,3 +6,3 @@ /*--------------------------------------------------------------------------------------------- | ||
'use strict'; | ||
export var HTML5_EVENTS = [ | ||
export const HTML5_EVENTS = [ | ||
{ | ||
@@ -9,0 +9,0 @@ "name": "onabort", |
@@ -6,3 +6,3 @@ /*--------------------------------------------------------------------------------------------- | ||
'use strict'; | ||
var HTMLDataProvider = /** @class */ (function () { | ||
export class HTMLDataProvider { | ||
/** | ||
@@ -13,4 +13,3 @@ * Currently, unversioned data uses the V1 implementation | ||
*/ | ||
function HTMLDataProvider(id, customData) { | ||
var _this = this; | ||
constructor(id, customData) { | ||
this.id = id; | ||
@@ -23,31 +22,31 @@ this._tags = []; | ||
this._globalAttributes = customData.globalAttributes || []; | ||
this._tags.forEach(function (t) { | ||
_this._tagMap[t.name] = t; | ||
this._tags.forEach(t => { | ||
this._tagMap[t.name] = t; | ||
if (t.attributes) { | ||
t.attributes.forEach(function (a) { | ||
_this._attributeMap[a.name] = a; | ||
t.attributes.forEach(a => { | ||
this._attributeMap[a.name] = a; | ||
}); | ||
} | ||
}); | ||
this._globalAttributes.forEach(function (a) { | ||
_this._attributeMap[a.name] = a; | ||
this._globalAttributes.forEach(a => { | ||
this._attributeMap[a.name] = a; | ||
}); | ||
if (customData.valueSets) { | ||
customData.valueSets.forEach(function (vs) { | ||
_this._valueSetMap[vs.name] = vs.values; | ||
customData.valueSets.forEach(vs => { | ||
this._valueSetMap[vs.name] = vs.values; | ||
}); | ||
} | ||
} | ||
HTMLDataProvider.prototype.isApplicable = function () { | ||
isApplicable() { | ||
return true; | ||
}; | ||
HTMLDataProvider.prototype.getId = function () { | ||
} | ||
getId() { | ||
return this.id; | ||
}; | ||
HTMLDataProvider.prototype.provideTags = function () { | ||
} | ||
provideTags() { | ||
return this._tags; | ||
}; | ||
HTMLDataProvider.prototype.provideAttributes = function (tag) { | ||
var attributes = []; | ||
var processAttribute = function (a) { | ||
} | ||
provideAttributes(tag) { | ||
const attributes = []; | ||
const processAttribute = (a) => { | ||
attributes.push({ | ||
@@ -60,19 +59,18 @@ name: a.name, | ||
if (this._tagMap[tag]) { | ||
this._tagMap[tag].attributes.forEach(function (a) { | ||
this._tagMap[tag].attributes.forEach(a => { | ||
processAttribute(a); | ||
}); | ||
} | ||
this._globalAttributes.forEach(function (ga) { | ||
this._globalAttributes.forEach(ga => { | ||
processAttribute(ga); | ||
}); | ||
return attributes; | ||
}; | ||
HTMLDataProvider.prototype.provideValues = function (tag, attribute) { | ||
var _this = this; | ||
var values = []; | ||
var processAttributes = function (attributes) { | ||
attributes.forEach(function (a) { | ||
} | ||
provideValues(tag, attribute) { | ||
const values = []; | ||
const processAttributes = (attributes) => { | ||
attributes.forEach(a => { | ||
if (a.name === attribute) { | ||
if (a.values) { | ||
a.values.forEach(function (v) { | ||
a.values.forEach(v => { | ||
values.push(v); | ||
@@ -82,4 +80,4 @@ }); | ||
if (a.valueSet) { | ||
if (_this._valueSetMap[a.valueSet]) { | ||
_this._valueSetMap[a.valueSet].forEach(function (v) { | ||
if (this._valueSetMap[a.valueSet]) { | ||
this._valueSetMap[a.valueSet].forEach(v => { | ||
values.push(v); | ||
@@ -98,6 +96,4 @@ }); | ||
return values; | ||
}; | ||
return HTMLDataProvider; | ||
}()); | ||
export { HTMLDataProvider }; | ||
} | ||
} | ||
//# sourceMappingURL=dataProvider.js.map |
@@ -8,6 +8,6 @@ /*--------------------------------------------------------------------------------------------- | ||
// As defined in https://www.w3.org/TR/html5/syntax.html#void-elements | ||
export var VOID_ELEMENTS = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr']; | ||
export const VOID_ELEMENTS = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr']; | ||
export function isVoidElement(e) { | ||
return !!e && arrays.binarySearch(VOID_ELEMENTS, e.toLowerCase(), function (s1, s2) { return s1.localeCompare(s2); }) >= 0; | ||
return !!e && arrays.binarySearch(VOID_ELEMENTS, e.toLowerCase(), (s1, s2) => s1.localeCompare(s2)) >= 0; | ||
} | ||
//# sourceMappingURL=fact.js.map |
@@ -10,3 +10,3 @@ /*--------------------------------------------------------------------------------------------- | ||
*/ | ||
export var entities = { | ||
export const entities = { | ||
"Aacute;": "\u00C1", | ||
@@ -13,0 +13,0 @@ "Aacute": "\u00C1", |
@@ -10,4 +10,4 @@ /*--------------------------------------------------------------------------------------------- | ||
import { TokenType } from '../htmlLanguageTypes'; | ||
var Node = /** @class */ (function () { | ||
function Node(start, end, children, parent) { | ||
export class Node { | ||
constructor(start, end, children, parent) { | ||
this.start = start; | ||
@@ -19,24 +19,12 @@ this.end = end; | ||
} | ||
Object.defineProperty(Node.prototype, "attributeNames", { | ||
get: function () { return this.attributes ? Object.keys(this.attributes) : []; }, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Node.prototype.isSameTag = function (tagInLowerCase) { | ||
get attributeNames() { return this.attributes ? Object.keys(this.attributes) : []; } | ||
isSameTag(tagInLowerCase) { | ||
return this.tag && tagInLowerCase && this.tag.length === tagInLowerCase.length && this.tag.toLowerCase() === tagInLowerCase; | ||
}; | ||
Object.defineProperty(Node.prototype, "firstChild", { | ||
get: function () { return this.children[0]; }, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Node.prototype, "lastChild", { | ||
get: function () { return this.children.length ? this.children[this.children.length - 1] : void 0; }, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Node.prototype.findNodeBefore = function (offset) { | ||
var idx = findFirst(this.children, function (c) { return offset <= c.start; }) - 1; | ||
} | ||
get firstChild() { return this.children[0]; } | ||
get lastChild() { return this.children.length ? this.children[this.children.length - 1] : void 0; } | ||
findNodeBefore(offset) { | ||
let idx = findFirst(this.children, c => offset <= c.start) - 1; | ||
if (idx >= 0) { | ||
var child = this.children[idx]; | ||
let child = this.children[idx]; | ||
if (offset > child.start) { | ||
@@ -46,3 +34,3 @@ if (offset < child.end) { | ||
} | ||
var lastChild = child.lastChild; | ||
let lastChild = child.lastChild; | ||
if (lastChild && lastChild.end === child.end) { | ||
@@ -55,7 +43,7 @@ return child.findNodeBefore(offset); | ||
return this; | ||
}; | ||
Node.prototype.findNodeAt = function (offset) { | ||
var idx = findFirst(this.children, function (c) { return offset <= c.start; }) - 1; | ||
} | ||
findNodeAt(offset) { | ||
let idx = findFirst(this.children, c => offset <= c.start) - 1; | ||
if (idx >= 0) { | ||
var child = this.children[idx]; | ||
let child = this.children[idx]; | ||
if (offset > child.start && offset <= child.end) { | ||
@@ -66,18 +54,16 @@ return child.findNodeAt(offset); | ||
return this; | ||
}; | ||
return Node; | ||
}()); | ||
export { Node }; | ||
} | ||
} | ||
export function parse(text) { | ||
var scanner = createScanner(text); | ||
var htmlDocument = new Node(0, text.length, [], void 0); | ||
var curr = htmlDocument; | ||
var endTagStart = -1; | ||
var endTagName = null; | ||
var pendingAttribute = null; | ||
var token = scanner.scan(); | ||
let scanner = createScanner(text); | ||
let htmlDocument = new Node(0, text.length, [], void 0); | ||
let curr = htmlDocument; | ||
let endTagStart = -1; | ||
let endTagName = null; | ||
let pendingAttribute = null; | ||
let token = scanner.scan(); | ||
while (token !== TokenType.EOS) { | ||
switch (token) { | ||
case TokenType.StartTagOpen: | ||
var child = new Node(scanner.getTokenOffset(), text.length, [], curr); | ||
let child = new Node(scanner.getTokenOffset(), text.length, [], curr); | ||
curr.children.push(child); | ||
@@ -114,3 +100,3 @@ curr = child; | ||
if (endTagName) { | ||
var node = curr; | ||
let node = curr; | ||
// see if we can find a matching tag | ||
@@ -134,4 +120,4 @@ while (!node.isSameTag(endTagName) && node.parent) { | ||
case TokenType.AttributeName: { | ||
var attributeName = pendingAttribute = scanner.getTokenText(); | ||
var attributes = curr.attributes; | ||
let attributeName = pendingAttribute = scanner.getTokenText(); | ||
let attributes = curr.attributes; | ||
if (!attributes) { | ||
@@ -144,4 +130,4 @@ curr.attributes = attributes = {}; | ||
case TokenType.AttributeValue: { | ||
var value = scanner.getTokenText(); | ||
var attributes = curr.attributes; | ||
let value = scanner.getTokenText(); | ||
let attributes = curr.attributes; | ||
if (attributes && pendingAttribute) { | ||
@@ -148,0 +134,0 @@ attributes[pendingAttribute] = value; |
@@ -8,5 +8,5 @@ /*--------------------------------------------------------------------------------------------- | ||
import { TokenType, ScannerState } from '../htmlLanguageTypes'; | ||
var localize = nls.loadMessageBundle(); | ||
var MultiLineStream = /** @class */ (function () { | ||
function MultiLineStream(source, position) { | ||
let localize = nls.loadMessageBundle(); | ||
class MultiLineStream { | ||
constructor(source, position) { | ||
this.source = source; | ||
@@ -16,31 +16,30 @@ this.len = source.length; | ||
} | ||
MultiLineStream.prototype.eos = function () { | ||
eos() { | ||
return this.len <= this.position; | ||
}; | ||
MultiLineStream.prototype.getSource = function () { | ||
} | ||
getSource() { | ||
return this.source; | ||
}; | ||
MultiLineStream.prototype.pos = function () { | ||
} | ||
pos() { | ||
return this.position; | ||
}; | ||
MultiLineStream.prototype.goBackTo = function (pos) { | ||
} | ||
goBackTo(pos) { | ||
this.position = pos; | ||
}; | ||
MultiLineStream.prototype.goBack = function (n) { | ||
} | ||
goBack(n) { | ||
this.position -= n; | ||
}; | ||
MultiLineStream.prototype.advance = function (n) { | ||
} | ||
advance(n) { | ||
this.position += n; | ||
}; | ||
MultiLineStream.prototype.goToEnd = function () { | ||
} | ||
goToEnd() { | ||
this.position = this.source.length; | ||
}; | ||
MultiLineStream.prototype.nextChar = function () { | ||
} | ||
nextChar() { | ||
return this.source.charCodeAt(this.position++) || 0; | ||
}; | ||
MultiLineStream.prototype.peekChar = function (n) { | ||
if (n === void 0) { n = 0; } | ||
} | ||
peekChar(n = 0) { | ||
return this.source.charCodeAt(this.position + n) || 0; | ||
}; | ||
MultiLineStream.prototype.advanceIfChar = function (ch) { | ||
} | ||
advanceIfChar(ch) { | ||
if (ch === this.source.charCodeAt(this.position)) { | ||
@@ -51,5 +50,5 @@ this.position++; | ||
return false; | ||
}; | ||
MultiLineStream.prototype.advanceIfChars = function (ch) { | ||
var i; | ||
} | ||
advanceIfChars(ch) { | ||
let i; | ||
if (this.position + ch.length > this.source.length) { | ||
@@ -65,6 +64,6 @@ return false; | ||
return true; | ||
}; | ||
MultiLineStream.prototype.advanceIfRegExp = function (regex) { | ||
var str = this.source.substr(this.position); | ||
var match = str.match(regex); | ||
} | ||
advanceIfRegExp(regex) { | ||
let str = this.source.substr(this.position); | ||
let match = str.match(regex); | ||
if (match) { | ||
@@ -75,6 +74,6 @@ this.position = this.position + match.index + match[0].length; | ||
return ''; | ||
}; | ||
MultiLineStream.prototype.advanceUntilRegExp = function (regex) { | ||
var str = this.source.substr(this.position); | ||
var match = str.match(regex); | ||
} | ||
advanceUntilRegExp(regex) { | ||
let str = this.source.substr(this.position); | ||
let match = str.match(regex); | ||
if (match) { | ||
@@ -88,4 +87,4 @@ this.position = this.position + match.index; | ||
return ''; | ||
}; | ||
MultiLineStream.prototype.advanceUntilChar = function (ch) { | ||
} | ||
advanceUntilChar(ch) { | ||
while (this.position < this.source.length) { | ||
@@ -98,6 +97,6 @@ if (this.source.charCodeAt(this.position) === ch) { | ||
return false; | ||
}; | ||
MultiLineStream.prototype.advanceUntilChars = function (ch) { | ||
} | ||
advanceUntilChars(ch) { | ||
while (this.position + ch.length <= this.source.length) { | ||
var i = 0; | ||
let i = 0; | ||
for (; i < ch.length && this.source.charCodeAt(this.position + i) === ch[i]; i++) { | ||
@@ -112,11 +111,11 @@ } | ||
return false; | ||
}; | ||
MultiLineStream.prototype.skipWhitespace = function () { | ||
var n = this.advanceWhileChar(function (ch) { | ||
} | ||
skipWhitespace() { | ||
let n = this.advanceWhileChar(ch => { | ||
return ch === _WSP || ch === _TAB || ch === _NWL || ch === _LFD || ch === _CAR; | ||
}); | ||
return n > 0; | ||
}; | ||
MultiLineStream.prototype.advanceWhileChar = function (condition) { | ||
var posNow = this.position; | ||
} | ||
advanceWhileChar(condition) { | ||
let posNow = this.position; | ||
while (this.position < this.len && condition(this.source.charCodeAt(this.position))) { | ||
@@ -126,33 +125,30 @@ this.position++; | ||
return this.position - posNow; | ||
}; | ||
return MultiLineStream; | ||
}()); | ||
var _BNG = '!'.charCodeAt(0); | ||
var _MIN = '-'.charCodeAt(0); | ||
var _LAN = '<'.charCodeAt(0); | ||
var _RAN = '>'.charCodeAt(0); | ||
var _FSL = '/'.charCodeAt(0); | ||
var _EQS = '='.charCodeAt(0); | ||
var _DQO = '"'.charCodeAt(0); | ||
var _SQO = '\''.charCodeAt(0); | ||
var _NWL = '\n'.charCodeAt(0); | ||
var _CAR = '\r'.charCodeAt(0); | ||
var _LFD = '\f'.charCodeAt(0); | ||
var _WSP = ' '.charCodeAt(0); | ||
var _TAB = '\t'.charCodeAt(0); | ||
var htmlScriptContents = { | ||
} | ||
} | ||
const _BNG = '!'.charCodeAt(0); | ||
const _MIN = '-'.charCodeAt(0); | ||
const _LAN = '<'.charCodeAt(0); | ||
const _RAN = '>'.charCodeAt(0); | ||
const _FSL = '/'.charCodeAt(0); | ||
const _EQS = '='.charCodeAt(0); | ||
const _DQO = '"'.charCodeAt(0); | ||
const _SQO = '\''.charCodeAt(0); | ||
const _NWL = '\n'.charCodeAt(0); | ||
const _CAR = '\r'.charCodeAt(0); | ||
const _LFD = '\f'.charCodeAt(0); | ||
const _WSP = ' '.charCodeAt(0); | ||
const _TAB = '\t'.charCodeAt(0); | ||
const htmlScriptContents = { | ||
'text/x-handlebars-template': true | ||
}; | ||
export function createScanner(input, initialOffset, initialState) { | ||
if (initialOffset === void 0) { initialOffset = 0; } | ||
if (initialState === void 0) { initialState = ScannerState.WithinContent; } | ||
var stream = new MultiLineStream(input, initialOffset); | ||
var state = initialState; | ||
var tokenOffset = 0; | ||
var tokenType = TokenType.Unknown; | ||
var tokenError; | ||
var hasSpaceAfterTag; | ||
var lastTag; | ||
var lastAttributeName; | ||
var lastTypeValue; | ||
export function createScanner(input, initialOffset = 0, initialState = ScannerState.WithinContent) { | ||
let stream = new MultiLineStream(input, initialOffset); | ||
let state = initialState; | ||
let tokenOffset = 0; | ||
let tokenType = TokenType.Unknown; | ||
let tokenError; | ||
let hasSpaceAfterTag; | ||
let lastTag; | ||
let lastAttributeName; | ||
let lastTypeValue; | ||
function nextElementName() { | ||
@@ -171,5 +167,5 @@ return stream.advanceIfRegExp(/^[_:\w][_:\w-.\d]*/).toLowerCase(); | ||
function scan() { | ||
var offset = stream.pos(); | ||
var oldState = state; | ||
var token = internalScan(); | ||
let offset = stream.pos(); | ||
let oldState = state; | ||
let token = internalScan(); | ||
if (token !== TokenType.EOS && offset === stream.pos()) { | ||
@@ -183,7 +179,7 @@ console.log('Scanner.scan has not advanced at offset ' + offset + ', state before: ' + oldState + ' after: ' + state); | ||
function internalScan() { | ||
var offset = stream.pos(); | ||
let offset = stream.pos(); | ||
if (stream.eos()) { | ||
return finishToken(offset, TokenType.EOS); | ||
} | ||
var errorMessage; | ||
let errorMessage; | ||
switch (state) { | ||
@@ -226,3 +222,3 @@ case ScannerState.WithinComment: | ||
case ScannerState.AfterOpeningEndTag: | ||
var tagName = nextElementName(); | ||
let tagName = nextElementName(); | ||
if (tagName.length > 0) { | ||
@@ -321,3 +317,3 @@ state = ScannerState.WithinEndTag; | ||
} | ||
var attributeValue = stream.advanceIfRegExp(/^[^\s"'`=<>\/]+/); | ||
let attributeValue = stream.advanceIfRegExp(/^[^\s"'`=<>\/]+/); | ||
if (attributeValue.length > 0) { | ||
@@ -331,3 +327,3 @@ if (lastAttributeName === 'type') { | ||
} | ||
var ch = stream.peekChar(); | ||
let ch = stream.peekChar(); | ||
if (ch === _SQO || ch === _DQO) { | ||
@@ -350,5 +346,5 @@ stream.advance(1); // consume quote | ||
// see http://stackoverflow.com/questions/14574471/how-do-browsers-parse-a-script-tag-exactly | ||
var sciptState = 1; | ||
let sciptState = 1; | ||
while (!stream.eos()) { | ||
var match = stream.advanceIfRegExp(/<!--|-->|<\/?script\s*\/?>?/i); | ||
let match = stream.advanceIfRegExp(/<!--|-->|<\/?script\s*\/?>?/i); | ||
if (match.length === 0) { | ||
@@ -399,12 +395,12 @@ stream.goToEnd(); | ||
return { | ||
scan: scan, | ||
getTokenType: function () { return tokenType; }, | ||
getTokenOffset: function () { return tokenOffset; }, | ||
getTokenLength: function () { return stream.pos() - tokenOffset; }, | ||
getTokenEnd: function () { return stream.pos(); }, | ||
getTokenText: function () { return stream.getSource().substring(tokenOffset, stream.pos()); }, | ||
getScannerState: function () { return state; }, | ||
getTokenError: function () { return tokenError; } | ||
scan, | ||
getTokenType: () => tokenType, | ||
getTokenOffset: () => tokenOffset, | ||
getTokenLength: () => stream.pos() - tokenOffset, | ||
getTokenEnd: () => stream.pos(), | ||
getTokenText: () => stream.getSource().substring(tokenOffset, stream.pos()), | ||
getScannerState: () => state, | ||
getTokenError: () => tokenError | ||
}; | ||
} | ||
//# sourceMappingURL=htmlScanner.js.map |
@@ -14,28 +14,27 @@ /*--------------------------------------------------------------------------------------------- | ||
import { isLetterOrDigit, endsWith, startsWith } from '../utils/strings'; | ||
var localize = nls.loadMessageBundle(); | ||
var HTMLCompletion = /** @class */ (function () { | ||
function HTMLCompletion() { | ||
let localize = nls.loadMessageBundle(); | ||
export class HTMLCompletion { | ||
constructor() { | ||
this.completionParticipants = []; | ||
} | ||
HTMLCompletion.prototype.setCompletionParticipants = function (registeredCompletionParticipants) { | ||
setCompletionParticipants(registeredCompletionParticipants) { | ||
this.completionParticipants = registeredCompletionParticipants || []; | ||
}; | ||
HTMLCompletion.prototype.doComplete = function (document, position, htmlDocument, settings) { | ||
var result = { | ||
} | ||
doComplete(document, position, htmlDocument, settings) { | ||
let result = { | ||
isIncomplete: false, | ||
items: [] | ||
}; | ||
var completionParticipants = this.completionParticipants; | ||
var dataProviders = getAllDataProviders().filter(function (p) { return p.isApplicable(document.languageId) && (!settings || settings[p.getId()] !== false); }); | ||
var text = document.getText(); | ||
var offset = document.offsetAt(position); | ||
var node = htmlDocument.findNodeBefore(offset); | ||
let completionParticipants = this.completionParticipants; | ||
let dataProviders = getAllDataProviders().filter(p => p.isApplicable(document.languageId) && (!settings || settings[p.getId()] !== false)); | ||
let text = document.getText(); | ||
let offset = document.offsetAt(position); | ||
let node = htmlDocument.findNodeBefore(offset); | ||
if (!node) { | ||
return result; | ||
} | ||
var scanner = createScanner(text, node.start); | ||
var currentTag = ''; | ||
var currentAttributeName; | ||
function getReplaceRange(replaceStart, replaceEnd) { | ||
if (replaceEnd === void 0) { replaceEnd = offset; } | ||
let scanner = createScanner(text, node.start); | ||
let currentTag = ''; | ||
let currentAttributeName; | ||
function getReplaceRange(replaceStart, replaceEnd = offset) { | ||
if (replaceStart > offset) { | ||
@@ -47,5 +46,5 @@ replaceStart = offset; | ||
function collectOpenTagSuggestions(afterOpenBracket, tagNameEnd) { | ||
var range = getReplaceRange(afterOpenBracket, tagNameEnd); | ||
dataProviders.forEach(function (provider) { | ||
provider.provideTags().forEach(function (tag) { | ||
let range = getReplaceRange(afterOpenBracket, tagNameEnd); | ||
dataProviders.forEach((provider) => { | ||
provider.provideTags().forEach(tag => { | ||
result.items.push({ | ||
@@ -63,5 +62,5 @@ label: tag.name, | ||
function getLineIndent(offset) { | ||
var start = offset; | ||
let start = offset; | ||
while (start > 0) { | ||
var ch = text.charAt(start - 1); | ||
let ch = text.charAt(start - 1); | ||
if ("\n\r".indexOf(ch) >= 0) { | ||
@@ -77,7 +76,6 @@ return text.substring(start, offset); | ||
} | ||
function collectCloseTagSuggestions(afterOpenBracket, inOpenTag, tagNameEnd) { | ||
if (tagNameEnd === void 0) { tagNameEnd = offset; } | ||
var range = getReplaceRange(afterOpenBracket, tagNameEnd); | ||
var closeTag = isFollowedBy(text, tagNameEnd, ScannerState.WithinEndTag, TokenType.EndTagClose) ? '' : '>'; | ||
var curr = node; | ||
function collectCloseTagSuggestions(afterOpenBracket, inOpenTag, tagNameEnd = offset) { | ||
let range = getReplaceRange(afterOpenBracket, tagNameEnd); | ||
let closeTag = isFollowedBy(text, tagNameEnd, ScannerState.WithinEndTag, TokenType.EndTagClose) ? '' : '>'; | ||
let curr = node; | ||
if (inOpenTag) { | ||
@@ -87,5 +85,5 @@ curr = curr.parent; // don't suggest the own tag, it's not yet open | ||
while (curr) { | ||
var tag = curr.tag; | ||
let tag = curr.tag; | ||
if (tag && (!curr.closed || curr.endTagStart && (curr.endTagStart > offset))) { | ||
var item = { | ||
let item = { | ||
label: '/' + tag, | ||
@@ -97,6 +95,6 @@ kind: CompletionItemKind.Property, | ||
}; | ||
var startIndent = getLineIndent(curr.start); | ||
var endIndent = getLineIndent(afterOpenBracket - 1); | ||
let startIndent = getLineIndent(curr.start); | ||
let endIndent = getLineIndent(afterOpenBracket - 1); | ||
if (startIndent !== null && endIndent !== null && startIndent !== endIndent) { | ||
var insertText = startIndent + '</' + tag + closeTag; | ||
let insertText = startIndent + '</' + tag + closeTag; | ||
item.textEdit = TextEdit.replace(getReplaceRange(afterOpenBracket - 1 - endIndent.length), insertText); | ||
@@ -113,4 +111,4 @@ item.filterText = endIndent + '</' + tag + closeTag; | ||
} | ||
dataProviders.forEach(function (provider) { | ||
provider.provideTags().forEach(function (tag) { | ||
dataProviders.forEach(provider => { | ||
provider.provideTags().forEach(tag => { | ||
result.items.push({ | ||
@@ -133,3 +131,3 @@ label: '/' + tag.name, | ||
if (!isVoidElement(tag)) { | ||
var pos = document.positionAt(tagCloseEnd); | ||
let pos = document.positionAt(tagCloseEnd); | ||
result.items.push({ | ||
@@ -150,14 +148,13 @@ label: '</' + tag + '>', | ||
} | ||
function collectAttributeNameSuggestions(nameStart, nameEnd) { | ||
if (nameEnd === void 0) { nameEnd = offset; } | ||
var replaceEnd = offset; | ||
function collectAttributeNameSuggestions(nameStart, nameEnd = offset) { | ||
let replaceEnd = offset; | ||
while (replaceEnd < nameEnd && text[replaceEnd] !== '<') { // < is a valid attribute name character, but we rather assume the attribute name ends. See #23236. | ||
replaceEnd++; | ||
} | ||
var range = getReplaceRange(nameStart, replaceEnd); | ||
var value = isFollowedBy(text, nameEnd, ScannerState.AfterAttributeName, TokenType.DelimiterAssign) ? '' : '="$1"'; | ||
var tag = currentTag.toLowerCase(); | ||
var seenAttributes = Object.create(null); | ||
dataProviders.forEach(function (provider) { | ||
provider.provideAttributes(tag).forEach(function (attr) { | ||
let range = getReplaceRange(nameStart, replaceEnd); | ||
let value = isFollowedBy(text, nameEnd, ScannerState.AfterAttributeName, TokenType.DelimiterAssign) ? '' : '="$1"'; | ||
let tag = currentTag.toLowerCase(); | ||
let seenAttributes = Object.create(null); | ||
dataProviders.forEach(provider => { | ||
provider.provideAttributes(tag).forEach(attr => { | ||
if (seenAttributes[attr.name]) { | ||
@@ -167,4 +164,4 @@ return; | ||
seenAttributes[attr.name] = true; | ||
var codeSnippet = attr.name; | ||
var command; | ||
let codeSnippet = attr.name; | ||
let command; | ||
if (attr.valueSet !== 'v' && value.length) { | ||
@@ -185,3 +182,3 @@ codeSnippet = codeSnippet + value; | ||
insertTextFormat: InsertTextFormat.Snippet, | ||
command: command | ||
command | ||
}); | ||
@@ -194,7 +191,7 @@ }); | ||
function collectDataAttributesSuggestions(range, seenAttributes) { | ||
var dataAttr = 'data-'; | ||
var dataAttributes = {}; | ||
dataAttributes[dataAttr] = dataAttr + "$1=\"$2\""; | ||
const dataAttr = 'data-'; | ||
let dataAttributes = {}; | ||
dataAttributes[dataAttr] = `${dataAttr}$1="$2"`; | ||
function addNodeDataAttributes(node) { | ||
node.attributeNames.forEach(function (attr) { | ||
node.attributeNames.forEach(attr => { | ||
if (startsWith(attr, dataAttr) && !dataAttributes[attr] && !seenAttributes[attr]) { | ||
@@ -204,8 +201,8 @@ dataAttributes[attr] = attr + '="$1"'; | ||
}); | ||
node.children.forEach(function (child) { return addNodeDataAttributes(child); }); | ||
node.children.forEach(child => addNodeDataAttributes(child)); | ||
} | ||
if (htmlDocument) { | ||
htmlDocument.roots.forEach(function (root) { return addNodeDataAttributes(root); }); | ||
htmlDocument.roots.forEach(root => addNodeDataAttributes(root)); | ||
} | ||
Object.keys(dataAttributes).forEach(function (attr) { return result.items.push({ | ||
Object.keys(dataAttributes).forEach(attr => result.items.push({ | ||
label: attr, | ||
@@ -215,13 +212,12 @@ kind: CompletionItemKind.Value, | ||
insertTextFormat: InsertTextFormat.Snippet | ||
}); }); | ||
})); | ||
} | ||
function collectAttributeValueSuggestions(valueStart, valueEnd) { | ||
if (valueEnd === void 0) { valueEnd = offset; } | ||
var range; | ||
var addQuotes; | ||
var valuePrefix; | ||
function collectAttributeValueSuggestions(valueStart, valueEnd = offset) { | ||
let range; | ||
let addQuotes; | ||
let valuePrefix; | ||
if (offset > valueStart && offset <= valueEnd && isQuote(text[valueStart])) { | ||
// inside quoted attribute | ||
var valueContentStart = valueStart + 1; | ||
var valueContentEnd = valueEnd; | ||
let valueContentStart = valueStart + 1; | ||
let valueContentEnd = valueEnd; | ||
// valueEnd points to the char after quote, which encloses the replace range | ||
@@ -231,4 +227,4 @@ if (valueEnd > valueStart && text[valueEnd - 1] === text[valueStart]) { | ||
} | ||
var wsBefore = getWordStart(text, offset, valueContentStart); | ||
var wsAfter = getWordEnd(text, offset, valueContentEnd); | ||
let wsBefore = getWordStart(text, offset, valueContentStart); | ||
let wsAfter = getWordEnd(text, offset, valueContentEnd); | ||
range = getReplaceRange(wsBefore, wsAfter); | ||
@@ -243,16 +239,15 @@ valuePrefix = offset >= valueContentStart && offset <= valueContentEnd ? text.substring(valueContentStart, offset) : ''; | ||
} | ||
var tag = currentTag.toLowerCase(); | ||
var attribute = currentAttributeName.toLowerCase(); | ||
let tag = currentTag.toLowerCase(); | ||
let attribute = currentAttributeName.toLowerCase(); | ||
if (completionParticipants.length > 0) { | ||
var fullRange = getReplaceRange(valueStart, valueEnd); | ||
for (var _i = 0, completionParticipants_1 = completionParticipants; _i < completionParticipants_1.length; _i++) { | ||
var participant = completionParticipants_1[_i]; | ||
let fullRange = getReplaceRange(valueStart, valueEnd); | ||
for (let participant of completionParticipants) { | ||
if (participant.onHtmlAttributeValue) { | ||
participant.onHtmlAttributeValue({ document: document, position: position, tag: tag, attribute: attribute, value: valuePrefix, range: fullRange }); | ||
participant.onHtmlAttributeValue({ document, position, tag, attribute, value: valuePrefix, range: fullRange }); | ||
} | ||
} | ||
} | ||
dataProviders.forEach(function (provider) { | ||
provider.provideValues(tag, attribute).forEach(function (value) { | ||
var insertText = addQuotes ? '"' + value.name + '"' : value.name; | ||
dataProviders.forEach(provider => { | ||
provider.provideValues(tag, attribute).forEach(value => { | ||
let insertText = addQuotes ? '"' + value.name + '"' : value.name; | ||
result.items.push({ | ||
@@ -280,6 +275,5 @@ label: value.name, | ||
function collectInsideContent() { | ||
for (var _i = 0, completionParticipants_2 = completionParticipants; _i < completionParticipants_2.length; _i++) { | ||
var participant = completionParticipants_2[_i]; | ||
for (let participant of completionParticipants) { | ||
if (participant.onHtmlContent) { | ||
participant.onHtmlContent({ document: document, position: position }); | ||
participant.onHtmlContent({ document, position }); | ||
} | ||
@@ -291,4 +285,4 @@ } | ||
// character entities | ||
var k = offset - 1; | ||
var characterStart = position.character; | ||
let k = offset - 1; | ||
let characterStart = position.character; | ||
while (k >= 0 && isLetterOrDigit(text, k)) { | ||
@@ -299,10 +293,10 @@ k--; | ||
if (k >= 0 && text[k] === '&') { | ||
var range = Range.create(Position.create(position.line, characterStart - 1), position); | ||
for (var entity in entities) { | ||
let range = Range.create(Position.create(position.line, characterStart - 1), position); | ||
for (let entity in entities) { | ||
if (endsWith(entity, ';')) { | ||
var label = '&' + entity; | ||
const label = '&' + entity; | ||
result.items.push({ | ||
label: label, | ||
label, | ||
kind: CompletionItemKind.Keyword, | ||
documentation: localize('entity.propose', "Character entity representing '" + entities[entity] + "'"), | ||
documentation: localize('entity.propose', `Character entity representing '${entities[entity]}'`), | ||
textEdit: TextEdit.replace(range, label), | ||
@@ -317,3 +311,3 @@ insertTextFormat: InsertTextFormat.PlainText | ||
function suggestDoctype(replaceStart, replaceEnd) { | ||
var range = getReplaceRange(replaceStart, replaceEnd); | ||
let range = getReplaceRange(replaceStart, replaceEnd); | ||
result.items.push({ | ||
@@ -327,3 +321,3 @@ label: '!DOCTYPE', | ||
} | ||
var token = scanner.scan(); | ||
let token = scanner.scan(); | ||
while (token !== TokenType.EOS && scanner.getTokenOffset() <= offset) { | ||
@@ -333,3 +327,3 @@ switch (token) { | ||
if (scanner.getTokenEnd() === offset) { | ||
var endPos = scanNextForEndPos(TokenType.StartTag); | ||
let endPos = scanNextForEndPos(TokenType.StartTag); | ||
if (position.line === 0) { | ||
@@ -355,3 +349,3 @@ suggestDoctype(offset, endPos); | ||
if (scanner.getTokenEnd() === offset) { | ||
var endPos = scanNextForEndPos(TokenType.AttributeValue); | ||
let endPos = scanNextForEndPos(TokenType.AttributeValue); | ||
return collectAttributeValueSuggestions(offset, endPos); | ||
@@ -369,4 +363,4 @@ } | ||
case ScannerState.AfterOpeningStartTag: | ||
var startPos = scanner.getTokenOffset(); | ||
var endTagPos = scanNextForEndPos(TokenType.StartTag); | ||
let startPos = scanner.getTokenOffset(); | ||
let endTagPos = scanNextForEndPos(TokenType.StartTag); | ||
return collectTagSuggestions(startPos, endTagPos); | ||
@@ -387,4 +381,4 @@ case ScannerState.WithinTag: | ||
if (offset <= scanner.getTokenEnd()) { | ||
var afterOpenBracket = scanner.getTokenOffset() + 1; | ||
var endOffset = scanNextForEndPos(TokenType.EndTag); | ||
let afterOpenBracket = scanner.getTokenOffset() + 1; | ||
let endOffset = scanNextForEndPos(TokenType.EndTag); | ||
return collectCloseTagSuggestions(afterOpenBracket, false, endOffset); | ||
@@ -395,5 +389,5 @@ } | ||
if (offset <= scanner.getTokenEnd()) { | ||
var start = scanner.getTokenOffset() - 1; | ||
let start = scanner.getTokenOffset() - 1; | ||
while (start >= 0) { | ||
var ch = text.charAt(start); | ||
let ch = text.charAt(start); | ||
if (ch === '/') { | ||
@@ -430,17 +424,17 @@ return collectCloseTagSuggestions(start, false, scanner.getTokenEnd()); | ||
return result; | ||
}; | ||
HTMLCompletion.prototype.doTagComplete = function (document, position, htmlDocument) { | ||
var offset = document.offsetAt(position); | ||
} | ||
doTagComplete(document, position, htmlDocument) { | ||
let offset = document.offsetAt(position); | ||
if (offset <= 0) { | ||
return null; | ||
} | ||
var char = document.getText().charAt(offset - 1); | ||
let char = document.getText().charAt(offset - 1); | ||
if (char === '>') { | ||
var node = htmlDocument.findNodeBefore(offset); | ||
let node = htmlDocument.findNodeBefore(offset); | ||
if (node && node.tag && !isVoidElement(node.tag) && node.start < offset && (!node.endTagStart || node.endTagStart > offset)) { | ||
var scanner = createScanner(document.getText(), node.start); | ||
var token = scanner.scan(); | ||
let scanner = createScanner(document.getText(), node.start); | ||
let token = scanner.scan(); | ||
while (token !== TokenType.EOS && scanner.getTokenEnd() <= offset) { | ||
if (token === TokenType.StartTagClose && scanner.getTokenEnd() === offset) { | ||
return "$0</" + node.tag + ">"; | ||
return `$0</${node.tag}>`; | ||
} | ||
@@ -452,3 +446,3 @@ token = scanner.scan(); | ||
else if (char === '/') { | ||
var node = htmlDocument.findNodeBefore(offset); | ||
let node = htmlDocument.findNodeBefore(offset); | ||
while (node && node.closed) { | ||
@@ -458,7 +452,7 @@ node = node.parent; | ||
if (node && node.tag) { | ||
var scanner = createScanner(document.getText(), node.start); | ||
var token = scanner.scan(); | ||
let scanner = createScanner(document.getText(), node.start); | ||
let token = scanner.scan(); | ||
while (token !== TokenType.EOS && scanner.getTokenEnd() <= offset) { | ||
if (token === TokenType.EndTagOpen && scanner.getTokenEnd() === offset) { | ||
return node.tag + ">"; | ||
return `${node.tag}>`; | ||
} | ||
@@ -470,6 +464,4 @@ token = scanner.scan(); | ||
return null; | ||
}; | ||
return HTMLCompletion; | ||
}()); | ||
export { HTMLCompletion }; | ||
} | ||
} | ||
function isQuote(s) { | ||
@@ -482,4 +474,4 @@ return /^["']*$/.test(s); | ||
function isFollowedBy(s, offset, intialState, expectedToken) { | ||
var scanner = createScanner(s, offset, intialState); | ||
var token = scanner.scan(); | ||
let scanner = createScanner(s, offset, intialState); | ||
let token = scanner.scan(); | ||
while (token === TokenType.Whitespace) { | ||
@@ -486,0 +478,0 @@ token = scanner.scan(); |
@@ -11,4 +11,4 @@ /*--------------------------------------------------------------------------------------------- | ||
function limitRanges(ranges, rangeLimit) { | ||
ranges = ranges.sort(function (r1, r2) { | ||
var diff = r1.startLine - r2.startLine; | ||
ranges = ranges.sort((r1, r2) => { | ||
let diff = r1.startLine - r2.startLine; | ||
if (diff === 0) { | ||
@@ -21,7 +21,7 @@ diff = r1.endLine - r2.endLine; | ||
// count the number of ranges for each level in 'nestingLevelCounts' | ||
var top = void 0; | ||
var previous = []; | ||
var nestingLevels = []; | ||
var nestingLevelCounts = []; | ||
var setNestingLevel = function (index, level) { | ||
let top = void 0; | ||
let previous = []; | ||
let nestingLevels = []; | ||
let nestingLevelCounts = []; | ||
let setNestingLevel = (index, level) => { | ||
nestingLevels[index] = level; | ||
@@ -33,4 +33,4 @@ if (level < 30) { | ||
// compute nesting levels and sanitize | ||
for (var i = 0; i < ranges.length; i++) { | ||
var entry = ranges[i]; | ||
for (let i = 0; i < ranges.length; i++) { | ||
let entry = ranges[i]; | ||
if (!top) { | ||
@@ -60,6 +60,6 @@ top = entry; | ||
} | ||
var entries = 0; | ||
var maxLevel = 0; | ||
for (var i = 0; i < nestingLevelCounts.length; i++) { | ||
var n = nestingLevelCounts[i]; | ||
let entries = 0; | ||
let maxLevel = 0; | ||
for (let i = 0; i < nestingLevelCounts.length; i++) { | ||
let n = nestingLevelCounts[i]; | ||
if (n) { | ||
@@ -73,5 +73,5 @@ if (n + entries > rangeLimit) { | ||
} | ||
var result = []; | ||
for (var i = 0; i < ranges.length; i++) { | ||
var level = nestingLevels[i]; | ||
let result = []; | ||
for (let i = 0; i < ranges.length; i++) { | ||
let level = nestingLevels[i]; | ||
if (typeof level === 'number') { | ||
@@ -86,8 +86,8 @@ if (level < maxLevel || (level === maxLevel && entries++ < rangeLimit)) { | ||
export function getFoldingRanges(document, context) { | ||
var scanner = createScanner(document.getText()); | ||
var token = scanner.scan(); | ||
var ranges = []; | ||
var stack = []; | ||
var lastTagName = null; | ||
var prevStart = -1; | ||
const scanner = createScanner(document.getText()); | ||
let token = scanner.scan(); | ||
let ranges = []; | ||
let stack = []; | ||
let lastTagName = null; | ||
let prevStart = -1; | ||
function addRange(range) { | ||
@@ -100,5 +100,5 @@ ranges.push(range); | ||
case TokenType.StartTag: { | ||
var tagName = scanner.getTokenText(); | ||
var startLine = document.positionAt(scanner.getTokenOffset()).line; | ||
stack.push({ startLine: startLine, tagName: tagName }); | ||
let tagName = scanner.getTokenText(); | ||
let startLine = document.positionAt(scanner.getTokenOffset()).line; | ||
stack.push({ startLine, tagName }); | ||
lastTagName = tagName; | ||
@@ -118,3 +118,3 @@ break; | ||
case TokenType.StartTagSelfClose: { | ||
var i = stack.length - 1; | ||
let i = stack.length - 1; | ||
while (i >= 0 && stack[i].tagName !== lastTagName) { | ||
@@ -124,9 +124,9 @@ i--; | ||
if (i >= 0) { | ||
var stackElement = stack[i]; | ||
let stackElement = stack[i]; | ||
stack.length = i; | ||
var line = document.positionAt(scanner.getTokenOffset()).line; | ||
var startLine = stackElement.startLine; | ||
var endLine = line - 1; | ||
let line = document.positionAt(scanner.getTokenOffset()).line; | ||
let startLine = stackElement.startLine; | ||
let endLine = line - 1; | ||
if (endLine > startLine && prevStart !== startLine) { | ||
addRange({ startLine: startLine, endLine: endLine }); | ||
addRange({ startLine, endLine }); | ||
} | ||
@@ -137,11 +137,11 @@ } | ||
case TokenType.Comment: { | ||
var startLine = document.positionAt(scanner.getTokenOffset()).line; | ||
var text = scanner.getTokenText(); | ||
var m = text.match(/^\s*#(region\b)|(endregion\b)/); | ||
let startLine = document.positionAt(scanner.getTokenOffset()).line; | ||
let text = scanner.getTokenText(); | ||
let m = text.match(/^\s*#(region\b)|(endregion\b)/); | ||
if (m) { | ||
if (m[1]) { // start pattern match | ||
stack.push({ startLine: startLine, tagName: '' }); // empty tagName marks region | ||
stack.push({ startLine, tagName: '' }); // empty tagName marks region | ||
} | ||
else { | ||
var i = stack.length - 1; | ||
let i = stack.length - 1; | ||
while (i >= 0 && stack[i].tagName.length) { | ||
@@ -151,8 +151,8 @@ i--; | ||
if (i >= 0) { | ||
var stackElement = stack[i]; | ||
let stackElement = stack[i]; | ||
stack.length = i; | ||
var endLine = startLine; | ||
let endLine = startLine; | ||
startLine = stackElement.startLine; | ||
if (endLine > startLine && prevStart !== startLine) { | ||
addRange({ startLine: startLine, endLine: endLine, kind: FoldingRangeKind.Region }); | ||
addRange({ startLine, endLine, kind: FoldingRangeKind.Region }); | ||
} | ||
@@ -163,5 +163,5 @@ } | ||
else { | ||
var endLine = document.positionAt(scanner.getTokenOffset() + scanner.getTokenLength()).line; | ||
let endLine = document.positionAt(scanner.getTokenOffset() + scanner.getTokenLength()).line; | ||
if (startLine < endLine) { | ||
addRange({ startLine: startLine, endLine: endLine, kind: FoldingRangeKind.Comment }); | ||
addRange({ startLine, endLine, kind: FoldingRangeKind.Comment }); | ||
} | ||
@@ -174,3 +174,3 @@ } | ||
} | ||
var rangeLimit = context && context.rangeLimit || Number.MAX_VALUE; | ||
let rangeLimit = context && context.rangeLimit || Number.MAX_VALUE; | ||
if (ranges.length > rangeLimit) { | ||
@@ -177,0 +177,0 @@ ranges = limitRanges(ranges, rangeLimit); |
@@ -10,10 +10,10 @@ /*--------------------------------------------------------------------------------------------- | ||
export function format(document, range, options) { | ||
var value = document.getText(); | ||
var includesEnd = true; | ||
var initialIndentLevel = 0; | ||
var tabSize = options.tabSize || 4; | ||
let value = document.getText(); | ||
let includesEnd = true; | ||
let initialIndentLevel = 0; | ||
let tabSize = options.tabSize || 4; | ||
if (range) { | ||
var startOffset = document.offsetAt(range.start); | ||
let startOffset = document.offsetAt(range.start); | ||
// include all leading whitespace iff at the beginning of the line | ||
var extendedStart = startOffset; | ||
let extendedStart = startOffset; | ||
while (extendedStart > 0 && isWhitespace(value, extendedStart - 1)) { | ||
@@ -32,4 +32,4 @@ extendedStart--; | ||
// include all following whitespace until the end of the line | ||
var endOffset = document.offsetAt(range.end); | ||
var extendedEnd = endOffset; | ||
let endOffset = document.offsetAt(range.end); | ||
let extendedEnd = endOffset; | ||
while (extendedEnd < value.length && isWhitespace(value, extendedEnd)) { | ||
@@ -44,3 +44,3 @@ extendedEnd++; | ||
// Ending inside an element is fine as it doesn't cause formatting errors | ||
var firstHalf = value.substring(0, startOffset); | ||
let firstHalf = value.substring(0, startOffset); | ||
if (new RegExp(/.*[<][^>]*$/).test(firstHalf)) { | ||
@@ -57,3 +57,3 @@ //return without modification | ||
if (startOffset !== 0) { | ||
var startOfLineOffset = document.offsetAt(Position.create(range.start.line, 0)); | ||
let startOfLineOffset = document.offsetAt(Position.create(range.start.line, 0)); | ||
initialIndentLevel = computeIndentLevel(document.getText(), startOfLineOffset, options); | ||
@@ -65,3 +65,3 @@ } | ||
} | ||
var htmlOptions = { | ||
let htmlOptions = { | ||
indent_size: tabSize, | ||
@@ -82,5 +82,5 @@ indent_char: options.insertSpaces ? ' ' : '\t', | ||
}; | ||
var result = html_beautify(trimLeft(value), htmlOptions); | ||
let result = html_beautify(trimLeft(value), htmlOptions); | ||
if (initialIndentLevel > 0) { | ||
var indent = options.insertSpaces ? repeat(' ', tabSize * initialIndentLevel) : repeat('\t', initialIndentLevel); | ||
let indent = options.insertSpaces ? repeat(' ', tabSize * initialIndentLevel) : repeat('\t', initialIndentLevel); | ||
result = result.split('\n').join('\n' + indent); | ||
@@ -101,3 +101,3 @@ if (range.start.character === 0) { | ||
if (options && options.hasOwnProperty(key)) { | ||
var value = options[key]; | ||
let value = options[key]; | ||
if (value !== null) { | ||
@@ -110,6 +110,6 @@ return value; | ||
function getTagsFormatOption(options, key, dflt) { | ||
var list = getFormatOption(options, key, null); | ||
let list = getFormatOption(options, key, null); | ||
if (typeof list === 'string') { | ||
if (list.length > 0) { | ||
return list.split(',').map(function (t) { return t.trim().toLowerCase(); }); | ||
return list.split(',').map(t => t.trim().toLowerCase()); | ||
} | ||
@@ -121,7 +121,7 @@ return []; | ||
function computeIndentLevel(content, offset, options) { | ||
var i = offset; | ||
var nChars = 0; | ||
var tabSize = options.tabSize || 4; | ||
let i = offset; | ||
let nChars = 0; | ||
let tabSize = options.tabSize || 4; | ||
while (i < content.length) { | ||
var ch = content.charAt(i); | ||
let ch = content.charAt(i); | ||
if (ch === ' ') { | ||
@@ -141,6 +141,6 @@ nChars++; | ||
function getEOL(document) { | ||
var text = document.getText(); | ||
let text = document.getText(); | ||
if (document.lineCount > 1) { | ||
var to = document.offsetAt(Position.create(1, 0)); | ||
var from = to; | ||
let to = document.offsetAt(Position.create(1, 0)); | ||
let from = to; | ||
while (from > 0 && isEOL(text, from - 1)) { | ||
@@ -147,0 +147,0 @@ from--; |
@@ -10,10 +10,10 @@ /*--------------------------------------------------------------------------------------------- | ||
export function findDocumentHighlights(document, position, htmlDocument) { | ||
var offset = document.offsetAt(position); | ||
var node = htmlDocument.findNodeAt(offset); | ||
let offset = document.offsetAt(position); | ||
let node = htmlDocument.findNodeAt(offset); | ||
if (!node.tag) { | ||
return []; | ||
} | ||
var result = []; | ||
var startTagRange = getTagNameRange(TokenType.StartTag, document, node.start); | ||
var endTagRange = typeof node.endTagStart === 'number' && getTagNameRange(TokenType.EndTag, document, node.endTagStart); | ||
let result = []; | ||
let startTagRange = getTagNameRange(TokenType.StartTag, document, node.start); | ||
let endTagRange = typeof node.endTagStart === 'number' && getTagNameRange(TokenType.EndTag, document, node.endTagStart); | ||
if (startTagRange && covers(startTagRange, position) || endTagRange && covers(endTagRange, position)) { | ||
@@ -36,4 +36,4 @@ if (startTagRange) { | ||
function getTagNameRange(tokenType, document, startOffset) { | ||
var scanner = createScanner(document.getText(), startOffset); | ||
var token = scanner.scan(); | ||
let scanner = createScanner(document.getText(), startOffset); | ||
let token = scanner.scan(); | ||
while (token !== TokenType.EOS && token !== tokenType) { | ||
@@ -40,0 +40,0 @@ token = scanner.scan(); |
@@ -11,28 +11,22 @@ /*--------------------------------------------------------------------------------------------- | ||
export function doHover(document, position, htmlDocument) { | ||
var offset = document.offsetAt(position); | ||
var node = htmlDocument.findNodeAt(offset); | ||
let offset = document.offsetAt(position); | ||
let node = htmlDocument.findNodeAt(offset); | ||
if (!node || !node.tag) { | ||
return null; | ||
} | ||
var dataProviders = getAllDataProviders().filter(function (p) { return p.isApplicable(document.languageId); }); | ||
let dataProviders = getAllDataProviders().filter(p => p.isApplicable(document.languageId)); | ||
function getTagHover(currTag, range, open) { | ||
currTag = currTag.toLowerCase(); | ||
var _loop_1 = function (provider) { | ||
var hover = null; | ||
provider.provideTags().forEach(function (tag) { | ||
for (let provider of dataProviders) { | ||
let hover = null; | ||
provider.provideTags().forEach(tag => { | ||
if (tag.name.toLowerCase() === currTag.toLowerCase()) { | ||
var tagLabel = open ? '<' + currTag + '>' : '</' + currTag + '>'; | ||
var tagDescription = tag.description || ''; | ||
hover = { contents: [{ language: 'html', value: tagLabel }, MarkedString.fromPlainText(tagDescription)], range: range }; | ||
const tagLabel = open ? '<' + currTag + '>' : '</' + currTag + '>'; | ||
const tagDescription = tag.description || ''; | ||
hover = { contents: [{ language: 'html', value: tagLabel }, MarkedString.fromPlainText(tagDescription)], range }; | ||
} | ||
}); | ||
if (hover) { | ||
return { value: hover }; | ||
return hover; | ||
} | ||
}; | ||
for (var _i = 0, dataProviders_1 = dataProviders; _i < dataProviders_1.length; _i++) { | ||
var provider = dataProviders_1[_i]; | ||
var state_1 = _loop_1(provider); | ||
if (typeof state_1 === "object") | ||
return state_1.value; | ||
} | ||
@@ -42,4 +36,4 @@ return null; | ||
function getTagNameRange(tokenType, startOffset) { | ||
var scanner = createScanner(document.getText(), startOffset); | ||
var token = scanner.scan(); | ||
let scanner = createScanner(document.getText(), startOffset); | ||
let token = scanner.scan(); | ||
while (token !== TokenType.EOS && (scanner.getTokenEnd() < offset || scanner.getTokenEnd() === offset && token !== tokenType)) { | ||
@@ -54,9 +48,9 @@ token = scanner.scan(); | ||
if (node.endTagStart && offset >= node.endTagStart) { | ||
var tagRange_1 = getTagNameRange(TokenType.EndTag, node.endTagStart); | ||
if (tagRange_1) { | ||
return getTagHover(node.tag, tagRange_1, false); | ||
let tagRange = getTagNameRange(TokenType.EndTag, node.endTagStart); | ||
if (tagRange) { | ||
return getTagHover(node.tag, tagRange, false); | ||
} | ||
return null; | ||
} | ||
var tagRange = getTagNameRange(TokenType.StartTag, node.start); | ||
let tagRange = getTagNameRange(TokenType.StartTag, node.start); | ||
if (tagRange) { | ||
@@ -63,0 +57,0 @@ return getTagHover(node.tag, tagRange, true); |
@@ -12,4 +12,4 @@ /*--------------------------------------------------------------------------------------------- | ||
function normalizeRef(url, languageId) { | ||
var first = url[0]; | ||
var last = url[url.length - 1]; | ||
let first = url[0]; | ||
let last = url[url.length - 1]; | ||
if (first === last && (first === '\'' || first === '\"')) { | ||
@@ -45,3 +45,3 @@ url = url.substr(1, url.length - 2); | ||
// Absolute link (that does not name the protocol) | ||
var pickedScheme = strings.startsWith(documentUri, 'https://') ? 'https' : 'http'; | ||
let pickedScheme = strings.startsWith(documentUri, 'https://') ? 'https' : 'http'; | ||
return pickedScheme + ':' + tokenContent.replace(/^\s*/g, ''); | ||
@@ -55,3 +55,3 @@ } | ||
function createLink(document, documentContext, attributeValue, startOffset, endOffset, base) { | ||
var tokenContent = normalizeRef(attributeValue, document.languageId); | ||
let tokenContent = normalizeRef(attributeValue, document.languageId); | ||
if (!validateRef(tokenContent, document.languageId)) { | ||
@@ -64,3 +64,3 @@ return null; | ||
} | ||
var workspaceUrl = getWorkspaceUrl(document.uri, tokenContent, documentContext, base); | ||
let workspaceUrl = getWorkspaceUrl(document.uri, tokenContent, documentContext, base); | ||
if (!workspaceUrl || !isValidURI(workspaceUrl)) { | ||
@@ -84,9 +84,9 @@ return null; | ||
export function findDocumentLinks(document, documentContext) { | ||
var newLinks = []; | ||
var rootAbsoluteUrl = null; | ||
var scanner = createScanner(document.getText(), 0); | ||
var token = scanner.scan(); | ||
var afterHrefOrSrc = false; | ||
var afterBase = false; | ||
var base = void 0; | ||
let newLinks = []; | ||
let rootAbsoluteUrl = null; | ||
let scanner = createScanner(document.getText(), 0); | ||
let token = scanner.scan(); | ||
let afterHrefOrSrc = false; | ||
let afterBase = false; | ||
let base = void 0; | ||
while (token !== TokenType.EOS) { | ||
@@ -96,3 +96,3 @@ switch (token) { | ||
if (!base) { | ||
var tagName = scanner.getTokenText().toLowerCase(); | ||
let tagName = scanner.getTokenText().toLowerCase(); | ||
afterBase = tagName === 'base'; | ||
@@ -102,3 +102,3 @@ } | ||
case TokenType.AttributeName: | ||
var attributeName = scanner.getTokenText().toLowerCase(); | ||
let attributeName = scanner.getTokenText().toLowerCase(); | ||
afterHrefOrSrc = attributeName === 'src' || attributeName === 'href'; | ||
@@ -108,5 +108,5 @@ break; | ||
if (afterHrefOrSrc) { | ||
var attributeValue = scanner.getTokenText(); | ||
let attributeValue = scanner.getTokenText(); | ||
if (!afterBase) { // don't highlight the base link itself | ||
var link = createLink(document, documentContext, attributeValue, scanner.getTokenOffset(), scanner.getTokenEnd(), base); | ||
let link = createLink(document, documentContext, attributeValue, scanner.getTokenOffset(), scanner.getTokenEnd(), base); | ||
if (link) { | ||
@@ -113,0 +113,0 @@ newLinks.push(link); |
@@ -8,33 +8,39 @@ /** | ||
import { parse } from '../parser/htmlParser'; | ||
import { TokenType } from '../htmlLanguageTypes'; | ||
export function getSelectionRanges(document, position) { | ||
var applicableRanges = getApplicableRanges(document, position); | ||
var ranges = applicableRanges | ||
/** | ||
* Filter duplicated ranges | ||
*/ | ||
.filter(function (pair, i) { | ||
if (i === 0) { | ||
import { TokenType, SelectionRangeKind } from '../htmlLanguageTypes'; | ||
export function getSelectionRanges(document, positions) { | ||
function getSelectionRange(position) { | ||
const applicableRanges = getApplicableRanges(document, position); | ||
const ranges = applicableRanges | ||
/** | ||
* Filter duplicated ranges | ||
*/ | ||
.filter((pair, i) => { | ||
if (i === 0) { | ||
return true; | ||
} | ||
const prev = applicableRanges[i - 1]; | ||
if (pair[0] === prev[0] && pair[1] === prev[1]) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
var prev = applicableRanges[i - 1]; | ||
if (pair[0] === prev[0] && pair[1] === prev[1]) { | ||
return false; | ||
} | ||
return true; | ||
}) | ||
.map(function (pair) { | ||
return Range.create(document.positionAt(pair[0]), document.positionAt(pair[1])); | ||
}); | ||
return ranges; | ||
}) | ||
.map(pair => { | ||
return { | ||
range: Range.create(document.positionAt(pair[0]), document.positionAt(pair[1])), | ||
kind: SelectionRangeKind.Declaration | ||
}; | ||
}); | ||
return ranges; | ||
} | ||
return positions.map(getSelectionRange); | ||
} | ||
function getApplicableRanges(document, position) { | ||
var htmlDoc = parse(document.getText()); | ||
var currOffset = document.offsetAt(position); | ||
var currNode = htmlDoc.findNodeAt(currOffset); | ||
var result = getAllParentTagRanges(currNode); | ||
const htmlDoc = parse(document.getText()); | ||
const currOffset = document.offsetAt(position); | ||
const currNode = htmlDoc.findNodeAt(currOffset); | ||
let result = getAllParentTagRanges(currNode); | ||
// Self-closing or void elements | ||
if (currNode.startTagEnd && !currNode.endTagStart) { | ||
var closeRange = Range.create(document.positionAt(currNode.startTagEnd - 2), document.positionAt(currNode.startTagEnd)); | ||
var closeText = document.getText(closeRange); | ||
const closeRange = Range.create(document.positionAt(currNode.startTagEnd - 2), document.positionAt(currNode.startTagEnd)); | ||
const closeText = document.getText(closeRange); | ||
// Self-closing element | ||
@@ -48,3 +54,3 @@ if (closeText === '/>') { | ||
} | ||
var attributeLevelRanges = getAttributeLevelRanges(document, currNode, currOffset); | ||
const attributeLevelRanges = getAttributeLevelRanges(document, currNode, currOffset); | ||
result = attributeLevelRanges.concat(result); | ||
@@ -66,3 +72,3 @@ return result; | ||
result.unshift([currNode.start + 1, currNode.startTagEnd - 1]); | ||
var attributeLevelRanges = getAttributeLevelRanges(document, currNode, currOffset); | ||
const attributeLevelRanges = getAttributeLevelRanges(document, currNode, currOffset); | ||
result = attributeLevelRanges.concat(result); | ||
@@ -90,4 +96,4 @@ return result; | ||
function getAllParentTagRanges(initialNode) { | ||
var currNode = initialNode; | ||
var getNodeRanges = function (n) { | ||
let currNode = initialNode; | ||
const getNodeRanges = (n) => { | ||
if (n.startTagEnd && n.endTagStart && n.startTagEnd < n.endTagStart) { | ||
@@ -103,6 +109,6 @@ return [ | ||
}; | ||
var result = []; | ||
const result = []; | ||
while (currNode.parent) { | ||
currNode = currNode.parent; | ||
getNodeRanges(currNode).forEach(function (r) { return result.push(r); }); | ||
getNodeRanges(currNode).forEach(r => result.push(r)); | ||
} | ||
@@ -112,10 +118,10 @@ return result; | ||
function getAttributeLevelRanges(document, currNode, currOffset) { | ||
var currNodeRange = Range.create(document.positionAt(currNode.start), document.positionAt(currNode.end)); | ||
var currNodeText = document.getText(currNodeRange); | ||
var relativeOffset = currOffset - currNode.start; | ||
const currNodeRange = Range.create(document.positionAt(currNode.start), document.positionAt(currNode.end)); | ||
const currNodeText = document.getText(currNodeRange); | ||
const relativeOffset = currOffset - currNode.start; | ||
/** | ||
* Tag level semantic selection | ||
*/ | ||
var scanner = createScanner(currNodeText); | ||
var token = scanner.scan(); | ||
const scanner = createScanner(currNodeText); | ||
let token = scanner.scan(); | ||
/** | ||
@@ -125,6 +131,6 @@ * For text like | ||
*/ | ||
var positionOffset = currNode.start; | ||
var result = []; | ||
var isInsideAttribute = false; | ||
var attrStart = -1; | ||
const positionOffset = currNode.start; | ||
const result = []; | ||
let isInsideAttribute = false; | ||
let attrStart = -1; | ||
while (token !== TokenType.EOS) { | ||
@@ -149,3 +155,3 @@ switch (token) { | ||
} | ||
var valueText = scanner.getTokenText(); | ||
const valueText = scanner.getTokenText(); | ||
if (relativeOffset < scanner.getTokenOffset()) { | ||
@@ -160,3 +166,3 @@ // `class="foo"` | ||
// `foo` | ||
if ((valueText[0] === "\"" && valueText[valueText.length - 1] === "\"") || (valueText[0] === "'" && valueText[valueText.length - 1] === "'")) { | ||
if ((valueText[0] === `"` && valueText[valueText.length - 1] === `"`) || (valueText[0] === `'` && valueText[valueText.length - 1] === `'`)) { | ||
if (relativeOffset >= scanner.getTokenOffset() + 1 && relativeOffset <= scanner.getTokenEnd() - 1) { | ||
@@ -174,3 +180,3 @@ result.unshift([scanner.getTokenOffset() + 1, scanner.getTokenEnd() - 1]); | ||
} | ||
return result.map(function (pair) { | ||
return result.map(pair => { | ||
return [pair[0] + positionOffset, pair[1] + positionOffset]; | ||
@@ -177,0 +183,0 @@ }); |
@@ -8,4 +8,4 @@ /*--------------------------------------------------------------------------------------------- | ||
export function findDocumentSymbols(document, htmlDocument) { | ||
var symbols = []; | ||
htmlDocument.roots.forEach(function (node) { | ||
let symbols = []; | ||
htmlDocument.roots.forEach(node => { | ||
provideFileSymbolsInternal(document, node, '', symbols); | ||
@@ -16,5 +16,5 @@ }); | ||
function provideFileSymbolsInternal(document, node, container, symbols) { | ||
var name = nodeToName(node); | ||
var location = Location.create(document.uri, Range.create(document.positionAt(node.start), document.positionAt(node.end))); | ||
var symbol = { | ||
let name = nodeToName(node); | ||
let location = Location.create(document.uri, Range.create(document.positionAt(node.start), document.positionAt(node.end))); | ||
let symbol = { | ||
name: name, | ||
@@ -26,3 +26,3 @@ location: location, | ||
symbols.push(symbol); | ||
node.children.forEach(function (child) { | ||
node.children.forEach(child => { | ||
provideFileSymbolsInternal(document, child, name, symbols); | ||
@@ -32,11 +32,11 @@ }); | ||
function nodeToName(node) { | ||
var name = node.tag; | ||
let name = node.tag; | ||
if (node.attributes) { | ||
var id = node.attributes['id']; | ||
var classes = node.attributes['class']; | ||
let id = node.attributes['id']; | ||
let classes = node.attributes['class']; | ||
if (id) { | ||
name += "#" + id.replace(/[\"\']/g, ''); | ||
name += `#${id.replace(/[\"\']/g, '')}`; | ||
} | ||
if (classes) { | ||
name += classes.replace(/[\"\']/g, '').split(/\s+/).map(function (className) { return "." + className; }).join(''); | ||
name += classes.replace(/[\"\']/g, '').split(/\s+/).map(className => `.${className}`).join(''); | ||
} | ||
@@ -43,0 +43,0 @@ } |
@@ -12,3 +12,3 @@ /*--------------------------------------------------------------------------------------------- | ||
export function findFirst(array, p) { | ||
var low = 0, high = array.length; | ||
let low = 0, high = array.length; | ||
if (high === 0) { | ||
@@ -18,3 +18,3 @@ return 0; // no children | ||
while (low < high) { | ||
var mid = Math.floor((low + high) / 2); | ||
let mid = Math.floor((low + high) / 2); | ||
if (p(array[mid])) { | ||
@@ -30,6 +30,6 @@ high = mid; | ||
export function binarySearch(array, key, comparator) { | ||
var low = 0, high = array.length - 1; | ||
let low = 0, high = array.length - 1; | ||
while (low <= high) { | ||
var mid = ((low + high) / 2) | 0; | ||
var comp = comparator(array[mid], key); | ||
let mid = ((low + high) / 2) | 0; | ||
let comp = comparator(array[mid], key); | ||
if (comp < 0) { | ||
@@ -36,0 +36,0 @@ low = mid + 1; |
@@ -44,15 +44,15 @@ /*--------------------------------------------------------------------------------------------- | ||
} | ||
export var join = function () { | ||
export const join = function () { | ||
// Not using a function with var-args because of how TS compiles | ||
// them to JS - it would result in 2*n runtime cost instead | ||
// of 1*n, where n is parts.length. | ||
var value = ''; | ||
for (var i = 0; i < arguments.length; i++) { | ||
var part = arguments[i]; | ||
let value = ''; | ||
for (let i = 0; i < arguments.length; i++) { | ||
let part = arguments[i]; | ||
if (i > 0) { | ||
// add the separater between two parts unless | ||
// there already is one | ||
var last = value.charCodeAt(value.length - 1); | ||
let last = value.charCodeAt(value.length - 1); | ||
if (last !== 47 /* Slash */ && last !== 92 /* Backslash */) { | ||
var next = part.charCodeAt(0); | ||
let next = part.charCodeAt(0); | ||
if (next !== 47 /* Slash */ && next !== 92 /* Backslash */) { | ||
@@ -59,0 +59,0 @@ value += '/'; |
@@ -10,3 +10,3 @@ /*--------------------------------------------------------------------------------------------- | ||
} | ||
for (var i = 0; i < needle.length; i++) { | ||
for (let i = 0; i < needle.length; i++) { | ||
if (haystack[i] !== needle[i]) { | ||
@@ -22,3 +22,3 @@ return false; | ||
export function endsWith(haystack, needle) { | ||
var diff = haystack.length - needle.length; | ||
let diff = haystack.length - needle.length; | ||
if (diff > 0) { | ||
@@ -38,3 +38,3 @@ return haystack.lastIndexOf(needle) === diff; | ||
export function commonPrefixLength(a, b) { | ||
var i, len = Math.min(a.length, b.length); | ||
let i, len = Math.min(a.length, b.length); | ||
for (i = 0; i < len; i++) { | ||
@@ -58,12 +58,12 @@ if (a.charCodeAt(i) !== b.charCodeAt(i)) { | ||
} | ||
var _a = 'a'.charCodeAt(0); | ||
var _z = 'z'.charCodeAt(0); | ||
var _A = 'A'.charCodeAt(0); | ||
var _Z = 'Z'.charCodeAt(0); | ||
var _0 = '0'.charCodeAt(0); | ||
var _9 = '9'.charCodeAt(0); | ||
const _a = 'a'.charCodeAt(0); | ||
const _z = 'z'.charCodeAt(0); | ||
const _A = 'A'.charCodeAt(0); | ||
const _Z = 'Z'.charCodeAt(0); | ||
const _0 = '0'.charCodeAt(0); | ||
const _9 = '9'.charCodeAt(0); | ||
export function isLetterOrDigit(text, index) { | ||
var c = text.charCodeAt(index); | ||
let c = text.charCodeAt(index); | ||
return (_a <= c && c <= _z) || (_A <= c && c <= _Z) || (_0 <= c && c <= _9); | ||
} | ||
//# sourceMappingURL=strings.js.map |
// copied from js-beautify/js/lib/beautify-css.js | ||
// version: 1.9.0-beta5 | ||
// version: 1.9.0 | ||
/* AUTO-GENERATED. DO NOT MODIFY. */ | ||
@@ -4,0 +4,0 @@ /* |
import { TextDocument, Position, CompletionList, Hover, Range, SymbolInformation, TextEdit, DocumentHighlight, DocumentLink, FoldingRange } from 'vscode-languageserver-types'; | ||
import { Scanner, HTMLDocument, CompletionConfiguration, ICompletionParticipant, HTMLFormatConfiguration, DocumentContext, IHTMLDataProvider } from './htmlLanguageTypes'; | ||
import { Scanner, HTMLDocument, CompletionConfiguration, ICompletionParticipant, HTMLFormatConfiguration, DocumentContext, IHTMLDataProvider, SelectionRange, HTMLDataV1 } from './htmlLanguageTypes'; | ||
import { HTMLDataProvider } from './languageFacts'; | ||
export * from './htmlLanguageTypes'; | ||
export * from 'vscode-languageserver-types'; | ||
export { HTMLDataProvider } from './languageFacts'; | ||
export interface LanguageService { | ||
@@ -20,3 +20,3 @@ createScanner(input: string, initialOffset?: number): Scanner; | ||
}): FoldingRange[]; | ||
getSelectionRanges(document: TextDocument, position: Position): Range[]; | ||
getSelectionRanges(document: TextDocument, positions: Position[]): SelectionRange[][]; | ||
} | ||
@@ -27,1 +27,2 @@ export interface LanguageServiceOptions { | ||
export declare function getLanguageService(options?: LanguageServiceOptions): LanguageService; | ||
export declare function newHTMLDataProvider(id: string, customData: HTMLDataV1): HTMLDataProvider; |
@@ -7,3 +7,3 @@ (function (factory) { | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "./parser/htmlScanner", "./parser/htmlParser", "./services/htmlCompletion", "./services/htmlHover", "./services/htmlFormatter", "./services/htmlLinks", "./services/htmlHighlighting", "./services/htmlSymbolsProvider", "./services/htmlFolding", "./languageFacts", "./services/htmlSelectionRange", "./htmlLanguageTypes", "vscode-languageserver-types", "./languageFacts"], factory); | ||
define(["require", "exports", "./parser/htmlScanner", "./parser/htmlParser", "./services/htmlCompletion", "./services/htmlHover", "./services/htmlFormatter", "./services/htmlLinks", "./services/htmlHighlighting", "./services/htmlSymbolsProvider", "./services/htmlFolding", "./languageFacts", "./services/htmlSelectionRange", "./htmlLanguageTypes", "vscode-languageserver-types"], factory); | ||
} | ||
@@ -20,19 +20,17 @@ })(function (require, exports) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var htmlScanner_1 = require("./parser/htmlScanner"); | ||
var htmlParser_1 = require("./parser/htmlParser"); | ||
var htmlCompletion_1 = require("./services/htmlCompletion"); | ||
var htmlHover_1 = require("./services/htmlHover"); | ||
var htmlFormatter_1 = require("./services/htmlFormatter"); | ||
var htmlLinks_1 = require("./services/htmlLinks"); | ||
var htmlHighlighting_1 = require("./services/htmlHighlighting"); | ||
var htmlSymbolsProvider_1 = require("./services/htmlSymbolsProvider"); | ||
var htmlFolding_1 = require("./services/htmlFolding"); | ||
var languageFacts_1 = require("./languageFacts"); | ||
var htmlSelectionRange_1 = require("./services/htmlSelectionRange"); | ||
const htmlScanner_1 = require("./parser/htmlScanner"); | ||
const htmlParser_1 = require("./parser/htmlParser"); | ||
const htmlCompletion_1 = require("./services/htmlCompletion"); | ||
const htmlHover_1 = require("./services/htmlHover"); | ||
const htmlFormatter_1 = require("./services/htmlFormatter"); | ||
const htmlLinks_1 = require("./services/htmlLinks"); | ||
const htmlHighlighting_1 = require("./services/htmlHighlighting"); | ||
const htmlSymbolsProvider_1 = require("./services/htmlSymbolsProvider"); | ||
const htmlFolding_1 = require("./services/htmlFolding"); | ||
const languageFacts_1 = require("./languageFacts"); | ||
const htmlSelectionRange_1 = require("./services/htmlSelectionRange"); | ||
__export(require("./htmlLanguageTypes")); | ||
__export(require("vscode-languageserver-types")); | ||
var languageFacts_2 = require("./languageFacts"); | ||
exports.HTMLDataProvider = languageFacts_2.HTMLDataProvider; | ||
function getLanguageService(options) { | ||
var htmlCompletion = new htmlCompletion_1.HTMLCompletion(); | ||
const htmlCompletion = new htmlCompletion_1.HTMLCompletion(); | ||
if (options && options.customDataProviders) { | ||
@@ -43,3 +41,3 @@ languageFacts_1.handleCustomDataProviders(options.customDataProviders); | ||
createScanner: htmlScanner_1.createScanner, | ||
parseHTMLDocument: function (document) { return htmlParser_1.parse(document.getText()); }, | ||
parseHTMLDocument: document => htmlParser_1.parse(document.getText()), | ||
doComplete: htmlCompletion.doComplete.bind(htmlCompletion), | ||
@@ -58,3 +56,7 @@ setCompletionParticipants: htmlCompletion.setCompletionParticipants.bind(htmlCompletion), | ||
exports.getLanguageService = getLanguageService; | ||
function newHTMLDataProvider(id, customData) { | ||
return new languageFacts_1.HTMLDataProvider(id, customData); | ||
} | ||
exports.newHTMLDataProvider = newHTMLDataProvider; | ||
}); | ||
//# sourceMappingURL=htmlLanguageService.js.map |
import { TextDocument, Position, Range } from 'vscode-languageserver-types'; | ||
/** | ||
* Enum of known selection range kinds | ||
*/ | ||
export declare enum SelectionRangeKind { | ||
/** | ||
* Empty Kind. | ||
*/ | ||
Empty = "", | ||
/** | ||
* The statment kind, its value is `statement`, possible extensions can be | ||
* `statement.if` etc | ||
*/ | ||
Statement = "statement", | ||
/** | ||
* The declaration kind, its value is `declaration`, possible extensions can be | ||
* `declaration.function`, `declaration.class` etc. | ||
*/ | ||
Declaration = "declaration" | ||
} | ||
/** | ||
* Represents a selection range | ||
*/ | ||
export interface SelectionRange { | ||
/** | ||
* Range of the selection. | ||
*/ | ||
range: Range; | ||
/** | ||
* Describes the kind of the selection range such as `statemet' or 'declaration'. See | ||
* [SelectionRangeKind](#SelectionRangeKind) for an enumeration of standardized kinds. | ||
*/ | ||
kind: string; | ||
} | ||
export interface HTMLFormatConfiguration { | ||
@@ -3,0 +36,0 @@ tabSize?: number; |
@@ -16,2 +16,23 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// #region Proposed types, remove once added to vscode-languageserver-types | ||
/** | ||
* Enum of known selection range kinds | ||
*/ | ||
var SelectionRangeKind; | ||
(function (SelectionRangeKind) { | ||
/** | ||
* Empty Kind. | ||
*/ | ||
SelectionRangeKind["Empty"] = ""; | ||
/** | ||
* The statment kind, its value is `statement`, possible extensions can be | ||
* `statement.if` etc | ||
*/ | ||
SelectionRangeKind["Statement"] = "statement"; | ||
/** | ||
* The declaration kind, its value is `declaration`, possible extensions can be | ||
* `declaration.function`, `declaration.class` etc. | ||
*/ | ||
SelectionRangeKind["Declaration"] = "declaration"; | ||
})(SelectionRangeKind = exports.SelectionRangeKind || (exports.SelectionRangeKind = {})); | ||
var TokenType; | ||
@@ -18,0 +39,0 @@ (function (TokenType) { |
@@ -16,7 +16,7 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var html5_1 = require("./data/html5"); | ||
const html5_1 = require("./data/html5"); | ||
exports.builtinDataProviders = [ | ||
html5_1.getHTML5DataProvider() | ||
]; | ||
var customDataProviders = []; | ||
const customDataProviders = []; | ||
function getAllDataProviders() { | ||
@@ -27,3 +27,3 @@ return exports.builtinDataProviders.concat(customDataProviders); | ||
function handleCustomDataProviders(providers) { | ||
providers.forEach(function (p) { | ||
providers.forEach(p => { | ||
customDataProviders.push(p); | ||
@@ -30,0 +30,0 @@ }); |
@@ -16,6 +16,6 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var dataProvider_1 = require("../dataProvider"); | ||
var html5Tags_1 = require("./html5Tags"); | ||
var html5Events_1 = require("./html5Events"); | ||
var html5Aria_1 = require("./html5Aria"); | ||
const dataProvider_1 = require("../dataProvider"); | ||
const html5Tags_1 = require("./html5Tags"); | ||
const html5Events_1 = require("./html5Events"); | ||
const html5Aria_1 = require("./html5Aria"); | ||
function getHTML5DataProvider() { | ||
@@ -25,3 +25,3 @@ return new dataProvider_1.HTMLDataProvider('html5', { | ||
tags: html5Tags_1.HTML5_TAGS, | ||
globalAttributes: exports.HTML5_GLOBAL_ATTRIBUTES.concat(html5Events_1.HTML5_EVENTS), | ||
globalAttributes: [...exports.HTML5_GLOBAL_ATTRIBUTES, ...html5Events_1.HTML5_EVENTS], | ||
valueSets: exports.HTML5_VALUE_MAP | ||
@@ -31,3 +31,4 @@ }); | ||
exports.getHTML5DataProvider = getHTML5DataProvider; | ||
exports.HTML5_GLOBAL_ATTRIBUTES = html5Aria_1.ARIA_ATTRIBUTES.concat([ | ||
exports.HTML5_GLOBAL_ATTRIBUTES = [ | ||
...html5Aria_1.ARIA_ATTRIBUTES, | ||
{ | ||
@@ -104,3 +105,3 @@ name: 'accesskey' | ||
} | ||
]); | ||
]; | ||
exports.HTML5_VALUE_MAP = [ | ||
@@ -107,0 +108,0 @@ { |
@@ -16,3 +16,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var HTMLDataProvider = /** @class */ (function () { | ||
class HTMLDataProvider { | ||
/** | ||
@@ -23,4 +23,3 @@ * Currently, unversioned data uses the V1 implementation | ||
*/ | ||
function HTMLDataProvider(id, customData) { | ||
var _this = this; | ||
constructor(id, customData) { | ||
this.id = id; | ||
@@ -33,31 +32,31 @@ this._tags = []; | ||
this._globalAttributes = customData.globalAttributes || []; | ||
this._tags.forEach(function (t) { | ||
_this._tagMap[t.name] = t; | ||
this._tags.forEach(t => { | ||
this._tagMap[t.name] = t; | ||
if (t.attributes) { | ||
t.attributes.forEach(function (a) { | ||
_this._attributeMap[a.name] = a; | ||
t.attributes.forEach(a => { | ||
this._attributeMap[a.name] = a; | ||
}); | ||
} | ||
}); | ||
this._globalAttributes.forEach(function (a) { | ||
_this._attributeMap[a.name] = a; | ||
this._globalAttributes.forEach(a => { | ||
this._attributeMap[a.name] = a; | ||
}); | ||
if (customData.valueSets) { | ||
customData.valueSets.forEach(function (vs) { | ||
_this._valueSetMap[vs.name] = vs.values; | ||
customData.valueSets.forEach(vs => { | ||
this._valueSetMap[vs.name] = vs.values; | ||
}); | ||
} | ||
} | ||
HTMLDataProvider.prototype.isApplicable = function () { | ||
isApplicable() { | ||
return true; | ||
}; | ||
HTMLDataProvider.prototype.getId = function () { | ||
} | ||
getId() { | ||
return this.id; | ||
}; | ||
HTMLDataProvider.prototype.provideTags = function () { | ||
} | ||
provideTags() { | ||
return this._tags; | ||
}; | ||
HTMLDataProvider.prototype.provideAttributes = function (tag) { | ||
var attributes = []; | ||
var processAttribute = function (a) { | ||
} | ||
provideAttributes(tag) { | ||
const attributes = []; | ||
const processAttribute = (a) => { | ||
attributes.push({ | ||
@@ -70,19 +69,18 @@ name: a.name, | ||
if (this._tagMap[tag]) { | ||
this._tagMap[tag].attributes.forEach(function (a) { | ||
this._tagMap[tag].attributes.forEach(a => { | ||
processAttribute(a); | ||
}); | ||
} | ||
this._globalAttributes.forEach(function (ga) { | ||
this._globalAttributes.forEach(ga => { | ||
processAttribute(ga); | ||
}); | ||
return attributes; | ||
}; | ||
HTMLDataProvider.prototype.provideValues = function (tag, attribute) { | ||
var _this = this; | ||
var values = []; | ||
var processAttributes = function (attributes) { | ||
attributes.forEach(function (a) { | ||
} | ||
provideValues(tag, attribute) { | ||
const values = []; | ||
const processAttributes = (attributes) => { | ||
attributes.forEach(a => { | ||
if (a.name === attribute) { | ||
if (a.values) { | ||
a.values.forEach(function (v) { | ||
a.values.forEach(v => { | ||
values.push(v); | ||
@@ -92,4 +90,4 @@ }); | ||
if (a.valueSet) { | ||
if (_this._valueSetMap[a.valueSet]) { | ||
_this._valueSetMap[a.valueSet].forEach(function (v) { | ||
if (this._valueSetMap[a.valueSet]) { | ||
this._valueSetMap[a.valueSet].forEach(v => { | ||
values.push(v); | ||
@@ -108,7 +106,6 @@ }); | ||
return values; | ||
}; | ||
return HTMLDataProvider; | ||
}()); | ||
} | ||
} | ||
exports.HTMLDataProvider = HTMLDataProvider; | ||
}); | ||
//# sourceMappingURL=dataProvider.js.map |
@@ -16,7 +16,7 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var arrays = require("../utils/arrays"); | ||
const arrays = require("../utils/arrays"); | ||
// As defined in https://www.w3.org/TR/html5/syntax.html#void-elements | ||
exports.VOID_ELEMENTS = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr']; | ||
function isVoidElement(e) { | ||
return !!e && arrays.binarySearch(exports.VOID_ELEMENTS, e.toLowerCase(), function (s1, s2) { return s1.localeCompare(s2); }) >= 0; | ||
return !!e && arrays.binarySearch(exports.VOID_ELEMENTS, e.toLowerCase(), (s1, s2) => s1.localeCompare(s2)) >= 0; | ||
} | ||
@@ -23,0 +23,0 @@ exports.isVoidElement = isVoidElement; |
@@ -16,8 +16,8 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var htmlScanner_1 = require("./htmlScanner"); | ||
var arrays_1 = require("../utils/arrays"); | ||
var languageFacts_1 = require("../languageFacts"); | ||
var htmlLanguageTypes_1 = require("../htmlLanguageTypes"); | ||
var Node = /** @class */ (function () { | ||
function Node(start, end, children, parent) { | ||
const htmlScanner_1 = require("./htmlScanner"); | ||
const arrays_1 = require("../utils/arrays"); | ||
const languageFacts_1 = require("../languageFacts"); | ||
const htmlLanguageTypes_1 = require("../htmlLanguageTypes"); | ||
class Node { | ||
constructor(start, end, children, parent) { | ||
this.start = start; | ||
@@ -29,24 +29,12 @@ this.end = end; | ||
} | ||
Object.defineProperty(Node.prototype, "attributeNames", { | ||
get: function () { return this.attributes ? Object.keys(this.attributes) : []; }, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Node.prototype.isSameTag = function (tagInLowerCase) { | ||
get attributeNames() { return this.attributes ? Object.keys(this.attributes) : []; } | ||
isSameTag(tagInLowerCase) { | ||
return this.tag && tagInLowerCase && this.tag.length === tagInLowerCase.length && this.tag.toLowerCase() === tagInLowerCase; | ||
}; | ||
Object.defineProperty(Node.prototype, "firstChild", { | ||
get: function () { return this.children[0]; }, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Node.prototype, "lastChild", { | ||
get: function () { return this.children.length ? this.children[this.children.length - 1] : void 0; }, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Node.prototype.findNodeBefore = function (offset) { | ||
var idx = arrays_1.findFirst(this.children, function (c) { return offset <= c.start; }) - 1; | ||
} | ||
get firstChild() { return this.children[0]; } | ||
get lastChild() { return this.children.length ? this.children[this.children.length - 1] : void 0; } | ||
findNodeBefore(offset) { | ||
let idx = arrays_1.findFirst(this.children, c => offset <= c.start) - 1; | ||
if (idx >= 0) { | ||
var child = this.children[idx]; | ||
let child = this.children[idx]; | ||
if (offset > child.start) { | ||
@@ -56,3 +44,3 @@ if (offset < child.end) { | ||
} | ||
var lastChild = child.lastChild; | ||
let lastChild = child.lastChild; | ||
if (lastChild && lastChild.end === child.end) { | ||
@@ -65,7 +53,7 @@ return child.findNodeBefore(offset); | ||
return this; | ||
}; | ||
Node.prototype.findNodeAt = function (offset) { | ||
var idx = arrays_1.findFirst(this.children, function (c) { return offset <= c.start; }) - 1; | ||
} | ||
findNodeAt(offset) { | ||
let idx = arrays_1.findFirst(this.children, c => offset <= c.start) - 1; | ||
if (idx >= 0) { | ||
var child = this.children[idx]; | ||
let child = this.children[idx]; | ||
if (offset > child.start && offset <= child.end) { | ||
@@ -76,18 +64,17 @@ return child.findNodeAt(offset); | ||
return this; | ||
}; | ||
return Node; | ||
}()); | ||
} | ||
} | ||
exports.Node = Node; | ||
function parse(text) { | ||
var scanner = htmlScanner_1.createScanner(text); | ||
var htmlDocument = new Node(0, text.length, [], void 0); | ||
var curr = htmlDocument; | ||
var endTagStart = -1; | ||
var endTagName = null; | ||
var pendingAttribute = null; | ||
var token = scanner.scan(); | ||
let scanner = htmlScanner_1.createScanner(text); | ||
let htmlDocument = new Node(0, text.length, [], void 0); | ||
let curr = htmlDocument; | ||
let endTagStart = -1; | ||
let endTagName = null; | ||
let pendingAttribute = null; | ||
let token = scanner.scan(); | ||
while (token !== htmlLanguageTypes_1.TokenType.EOS) { | ||
switch (token) { | ||
case htmlLanguageTypes_1.TokenType.StartTagOpen: | ||
var child = new Node(scanner.getTokenOffset(), text.length, [], curr); | ||
let child = new Node(scanner.getTokenOffset(), text.length, [], curr); | ||
curr.children.push(child); | ||
@@ -124,3 +111,3 @@ curr = child; | ||
if (endTagName) { | ||
var node = curr; | ||
let node = curr; | ||
// see if we can find a matching tag | ||
@@ -144,4 +131,4 @@ while (!node.isSameTag(endTagName) && node.parent) { | ||
case htmlLanguageTypes_1.TokenType.AttributeName: { | ||
var attributeName = pendingAttribute = scanner.getTokenText(); | ||
var attributes = curr.attributes; | ||
let attributeName = pendingAttribute = scanner.getTokenText(); | ||
let attributes = curr.attributes; | ||
if (!attributes) { | ||
@@ -154,4 +141,4 @@ curr.attributes = attributes = {}; | ||
case htmlLanguageTypes_1.TokenType.AttributeValue: { | ||
var value = scanner.getTokenText(); | ||
var attributes = curr.attributes; | ||
let value = scanner.getTokenText(); | ||
let attributes = curr.attributes; | ||
if (attributes && pendingAttribute) { | ||
@@ -158,0 +145,0 @@ attributes[pendingAttribute] = value; |
@@ -16,7 +16,7 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var nls = require("vscode-nls"); | ||
var htmlLanguageTypes_1 = require("../htmlLanguageTypes"); | ||
var localize = nls.loadMessageBundle(); | ||
var MultiLineStream = /** @class */ (function () { | ||
function MultiLineStream(source, position) { | ||
const nls = require("vscode-nls"); | ||
const htmlLanguageTypes_1 = require("../htmlLanguageTypes"); | ||
let localize = nls.loadMessageBundle(); | ||
class MultiLineStream { | ||
constructor(source, position) { | ||
this.source = source; | ||
@@ -26,31 +26,30 @@ this.len = source.length; | ||
} | ||
MultiLineStream.prototype.eos = function () { | ||
eos() { | ||
return this.len <= this.position; | ||
}; | ||
MultiLineStream.prototype.getSource = function () { | ||
} | ||
getSource() { | ||
return this.source; | ||
}; | ||
MultiLineStream.prototype.pos = function () { | ||
} | ||
pos() { | ||
return this.position; | ||
}; | ||
MultiLineStream.prototype.goBackTo = function (pos) { | ||
} | ||
goBackTo(pos) { | ||
this.position = pos; | ||
}; | ||
MultiLineStream.prototype.goBack = function (n) { | ||
} | ||
goBack(n) { | ||
this.position -= n; | ||
}; | ||
MultiLineStream.prototype.advance = function (n) { | ||
} | ||
advance(n) { | ||
this.position += n; | ||
}; | ||
MultiLineStream.prototype.goToEnd = function () { | ||
} | ||
goToEnd() { | ||
this.position = this.source.length; | ||
}; | ||
MultiLineStream.prototype.nextChar = function () { | ||
} | ||
nextChar() { | ||
return this.source.charCodeAt(this.position++) || 0; | ||
}; | ||
MultiLineStream.prototype.peekChar = function (n) { | ||
if (n === void 0) { n = 0; } | ||
} | ||
peekChar(n = 0) { | ||
return this.source.charCodeAt(this.position + n) || 0; | ||
}; | ||
MultiLineStream.prototype.advanceIfChar = function (ch) { | ||
} | ||
advanceIfChar(ch) { | ||
if (ch === this.source.charCodeAt(this.position)) { | ||
@@ -61,5 +60,5 @@ this.position++; | ||
return false; | ||
}; | ||
MultiLineStream.prototype.advanceIfChars = function (ch) { | ||
var i; | ||
} | ||
advanceIfChars(ch) { | ||
let i; | ||
if (this.position + ch.length > this.source.length) { | ||
@@ -75,6 +74,6 @@ return false; | ||
return true; | ||
}; | ||
MultiLineStream.prototype.advanceIfRegExp = function (regex) { | ||
var str = this.source.substr(this.position); | ||
var match = str.match(regex); | ||
} | ||
advanceIfRegExp(regex) { | ||
let str = this.source.substr(this.position); | ||
let match = str.match(regex); | ||
if (match) { | ||
@@ -85,6 +84,6 @@ this.position = this.position + match.index + match[0].length; | ||
return ''; | ||
}; | ||
MultiLineStream.prototype.advanceUntilRegExp = function (regex) { | ||
var str = this.source.substr(this.position); | ||
var match = str.match(regex); | ||
} | ||
advanceUntilRegExp(regex) { | ||
let str = this.source.substr(this.position); | ||
let match = str.match(regex); | ||
if (match) { | ||
@@ -98,4 +97,4 @@ this.position = this.position + match.index; | ||
return ''; | ||
}; | ||
MultiLineStream.prototype.advanceUntilChar = function (ch) { | ||
} | ||
advanceUntilChar(ch) { | ||
while (this.position < this.source.length) { | ||
@@ -108,6 +107,6 @@ if (this.source.charCodeAt(this.position) === ch) { | ||
return false; | ||
}; | ||
MultiLineStream.prototype.advanceUntilChars = function (ch) { | ||
} | ||
advanceUntilChars(ch) { | ||
while (this.position + ch.length <= this.source.length) { | ||
var i = 0; | ||
let i = 0; | ||
for (; i < ch.length && this.source.charCodeAt(this.position + i) === ch[i]; i++) { | ||
@@ -122,11 +121,11 @@ } | ||
return false; | ||
}; | ||
MultiLineStream.prototype.skipWhitespace = function () { | ||
var n = this.advanceWhileChar(function (ch) { | ||
} | ||
skipWhitespace() { | ||
let n = this.advanceWhileChar(ch => { | ||
return ch === _WSP || ch === _TAB || ch === _NWL || ch === _LFD || ch === _CAR; | ||
}); | ||
return n > 0; | ||
}; | ||
MultiLineStream.prototype.advanceWhileChar = function (condition) { | ||
var posNow = this.position; | ||
} | ||
advanceWhileChar(condition) { | ||
let posNow = this.position; | ||
while (this.position < this.len && condition(this.source.charCodeAt(this.position))) { | ||
@@ -136,33 +135,30 @@ this.position++; | ||
return this.position - posNow; | ||
}; | ||
return MultiLineStream; | ||
}()); | ||
var _BNG = '!'.charCodeAt(0); | ||
var _MIN = '-'.charCodeAt(0); | ||
var _LAN = '<'.charCodeAt(0); | ||
var _RAN = '>'.charCodeAt(0); | ||
var _FSL = '/'.charCodeAt(0); | ||
var _EQS = '='.charCodeAt(0); | ||
var _DQO = '"'.charCodeAt(0); | ||
var _SQO = '\''.charCodeAt(0); | ||
var _NWL = '\n'.charCodeAt(0); | ||
var _CAR = '\r'.charCodeAt(0); | ||
var _LFD = '\f'.charCodeAt(0); | ||
var _WSP = ' '.charCodeAt(0); | ||
var _TAB = '\t'.charCodeAt(0); | ||
var htmlScriptContents = { | ||
} | ||
} | ||
const _BNG = '!'.charCodeAt(0); | ||
const _MIN = '-'.charCodeAt(0); | ||
const _LAN = '<'.charCodeAt(0); | ||
const _RAN = '>'.charCodeAt(0); | ||
const _FSL = '/'.charCodeAt(0); | ||
const _EQS = '='.charCodeAt(0); | ||
const _DQO = '"'.charCodeAt(0); | ||
const _SQO = '\''.charCodeAt(0); | ||
const _NWL = '\n'.charCodeAt(0); | ||
const _CAR = '\r'.charCodeAt(0); | ||
const _LFD = '\f'.charCodeAt(0); | ||
const _WSP = ' '.charCodeAt(0); | ||
const _TAB = '\t'.charCodeAt(0); | ||
const htmlScriptContents = { | ||
'text/x-handlebars-template': true | ||
}; | ||
function createScanner(input, initialOffset, initialState) { | ||
if (initialOffset === void 0) { initialOffset = 0; } | ||
if (initialState === void 0) { initialState = htmlLanguageTypes_1.ScannerState.WithinContent; } | ||
var stream = new MultiLineStream(input, initialOffset); | ||
var state = initialState; | ||
var tokenOffset = 0; | ||
var tokenType = htmlLanguageTypes_1.TokenType.Unknown; | ||
var tokenError; | ||
var hasSpaceAfterTag; | ||
var lastTag; | ||
var lastAttributeName; | ||
var lastTypeValue; | ||
function createScanner(input, initialOffset = 0, initialState = htmlLanguageTypes_1.ScannerState.WithinContent) { | ||
let stream = new MultiLineStream(input, initialOffset); | ||
let state = initialState; | ||
let tokenOffset = 0; | ||
let tokenType = htmlLanguageTypes_1.TokenType.Unknown; | ||
let tokenError; | ||
let hasSpaceAfterTag; | ||
let lastTag; | ||
let lastAttributeName; | ||
let lastTypeValue; | ||
function nextElementName() { | ||
@@ -181,5 +177,5 @@ return stream.advanceIfRegExp(/^[_:\w][_:\w-.\d]*/).toLowerCase(); | ||
function scan() { | ||
var offset = stream.pos(); | ||
var oldState = state; | ||
var token = internalScan(); | ||
let offset = stream.pos(); | ||
let oldState = state; | ||
let token = internalScan(); | ||
if (token !== htmlLanguageTypes_1.TokenType.EOS && offset === stream.pos()) { | ||
@@ -193,7 +189,7 @@ console.log('Scanner.scan has not advanced at offset ' + offset + ', state before: ' + oldState + ' after: ' + state); | ||
function internalScan() { | ||
var offset = stream.pos(); | ||
let offset = stream.pos(); | ||
if (stream.eos()) { | ||
return finishToken(offset, htmlLanguageTypes_1.TokenType.EOS); | ||
} | ||
var errorMessage; | ||
let errorMessage; | ||
switch (state) { | ||
@@ -236,3 +232,3 @@ case htmlLanguageTypes_1.ScannerState.WithinComment: | ||
case htmlLanguageTypes_1.ScannerState.AfterOpeningEndTag: | ||
var tagName = nextElementName(); | ||
let tagName = nextElementName(); | ||
if (tagName.length > 0) { | ||
@@ -331,3 +327,3 @@ state = htmlLanguageTypes_1.ScannerState.WithinEndTag; | ||
} | ||
var attributeValue = stream.advanceIfRegExp(/^[^\s"'`=<>\/]+/); | ||
let attributeValue = stream.advanceIfRegExp(/^[^\s"'`=<>\/]+/); | ||
if (attributeValue.length > 0) { | ||
@@ -341,3 +337,3 @@ if (lastAttributeName === 'type') { | ||
} | ||
var ch = stream.peekChar(); | ||
let ch = stream.peekChar(); | ||
if (ch === _SQO || ch === _DQO) { | ||
@@ -360,5 +356,5 @@ stream.advance(1); // consume quote | ||
// see http://stackoverflow.com/questions/14574471/how-do-browsers-parse-a-script-tag-exactly | ||
var sciptState = 1; | ||
let sciptState = 1; | ||
while (!stream.eos()) { | ||
var match = stream.advanceIfRegExp(/<!--|-->|<\/?script\s*\/?>?/i); | ||
let match = stream.advanceIfRegExp(/<!--|-->|<\/?script\s*\/?>?/i); | ||
if (match.length === 0) { | ||
@@ -409,10 +405,10 @@ stream.goToEnd(); | ||
return { | ||
scan: scan, | ||
getTokenType: function () { return tokenType; }, | ||
getTokenOffset: function () { return tokenOffset; }, | ||
getTokenLength: function () { return stream.pos() - tokenOffset; }, | ||
getTokenEnd: function () { return stream.pos(); }, | ||
getTokenText: function () { return stream.getSource().substring(tokenOffset, stream.pos()); }, | ||
getScannerState: function () { return state; }, | ||
getTokenError: function () { return tokenError; } | ||
scan, | ||
getTokenType: () => tokenType, | ||
getTokenOffset: () => tokenOffset, | ||
getTokenLength: () => stream.pos() - tokenOffset, | ||
getTokenEnd: () => stream.pos(), | ||
getTokenText: () => stream.getSource().substring(tokenOffset, stream.pos()), | ||
getScannerState: () => state, | ||
getTokenError: () => tokenError | ||
}; | ||
@@ -419,0 +415,0 @@ } |
@@ -16,36 +16,35 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var vscode_languageserver_types_1 = require("vscode-languageserver-types"); | ||
var htmlScanner_1 = require("../parser/htmlScanner"); | ||
var languageFacts_1 = require("../languageFacts"); | ||
var languageFacts_2 = require("../languageFacts"); | ||
var htmlLanguageTypes_1 = require("../htmlLanguageTypes"); | ||
var htmlEntities_1 = require("../parser/htmlEntities"); | ||
var nls = require("vscode-nls"); | ||
var strings_1 = require("../utils/strings"); | ||
var localize = nls.loadMessageBundle(); | ||
var HTMLCompletion = /** @class */ (function () { | ||
function HTMLCompletion() { | ||
const vscode_languageserver_types_1 = require("vscode-languageserver-types"); | ||
const htmlScanner_1 = require("../parser/htmlScanner"); | ||
const languageFacts_1 = require("../languageFacts"); | ||
const languageFacts_2 = require("../languageFacts"); | ||
const htmlLanguageTypes_1 = require("../htmlLanguageTypes"); | ||
const htmlEntities_1 = require("../parser/htmlEntities"); | ||
const nls = require("vscode-nls"); | ||
const strings_1 = require("../utils/strings"); | ||
let localize = nls.loadMessageBundle(); | ||
class HTMLCompletion { | ||
constructor() { | ||
this.completionParticipants = []; | ||
} | ||
HTMLCompletion.prototype.setCompletionParticipants = function (registeredCompletionParticipants) { | ||
setCompletionParticipants(registeredCompletionParticipants) { | ||
this.completionParticipants = registeredCompletionParticipants || []; | ||
}; | ||
HTMLCompletion.prototype.doComplete = function (document, position, htmlDocument, settings) { | ||
var result = { | ||
} | ||
doComplete(document, position, htmlDocument, settings) { | ||
let result = { | ||
isIncomplete: false, | ||
items: [] | ||
}; | ||
var completionParticipants = this.completionParticipants; | ||
var dataProviders = languageFacts_2.getAllDataProviders().filter(function (p) { return p.isApplicable(document.languageId) && (!settings || settings[p.getId()] !== false); }); | ||
var text = document.getText(); | ||
var offset = document.offsetAt(position); | ||
var node = htmlDocument.findNodeBefore(offset); | ||
let completionParticipants = this.completionParticipants; | ||
let dataProviders = languageFacts_2.getAllDataProviders().filter(p => p.isApplicable(document.languageId) && (!settings || settings[p.getId()] !== false)); | ||
let text = document.getText(); | ||
let offset = document.offsetAt(position); | ||
let node = htmlDocument.findNodeBefore(offset); | ||
if (!node) { | ||
return result; | ||
} | ||
var scanner = htmlScanner_1.createScanner(text, node.start); | ||
var currentTag = ''; | ||
var currentAttributeName; | ||
function getReplaceRange(replaceStart, replaceEnd) { | ||
if (replaceEnd === void 0) { replaceEnd = offset; } | ||
let scanner = htmlScanner_1.createScanner(text, node.start); | ||
let currentTag = ''; | ||
let currentAttributeName; | ||
function getReplaceRange(replaceStart, replaceEnd = offset) { | ||
if (replaceStart > offset) { | ||
@@ -57,5 +56,5 @@ replaceStart = offset; | ||
function collectOpenTagSuggestions(afterOpenBracket, tagNameEnd) { | ||
var range = getReplaceRange(afterOpenBracket, tagNameEnd); | ||
dataProviders.forEach(function (provider) { | ||
provider.provideTags().forEach(function (tag) { | ||
let range = getReplaceRange(afterOpenBracket, tagNameEnd); | ||
dataProviders.forEach((provider) => { | ||
provider.provideTags().forEach(tag => { | ||
result.items.push({ | ||
@@ -73,5 +72,5 @@ label: tag.name, | ||
function getLineIndent(offset) { | ||
var start = offset; | ||
let start = offset; | ||
while (start > 0) { | ||
var ch = text.charAt(start - 1); | ||
let ch = text.charAt(start - 1); | ||
if ("\n\r".indexOf(ch) >= 0) { | ||
@@ -87,7 +86,6 @@ return text.substring(start, offset); | ||
} | ||
function collectCloseTagSuggestions(afterOpenBracket, inOpenTag, tagNameEnd) { | ||
if (tagNameEnd === void 0) { tagNameEnd = offset; } | ||
var range = getReplaceRange(afterOpenBracket, tagNameEnd); | ||
var closeTag = isFollowedBy(text, tagNameEnd, htmlLanguageTypes_1.ScannerState.WithinEndTag, htmlLanguageTypes_1.TokenType.EndTagClose) ? '' : '>'; | ||
var curr = node; | ||
function collectCloseTagSuggestions(afterOpenBracket, inOpenTag, tagNameEnd = offset) { | ||
let range = getReplaceRange(afterOpenBracket, tagNameEnd); | ||
let closeTag = isFollowedBy(text, tagNameEnd, htmlLanguageTypes_1.ScannerState.WithinEndTag, htmlLanguageTypes_1.TokenType.EndTagClose) ? '' : '>'; | ||
let curr = node; | ||
if (inOpenTag) { | ||
@@ -97,5 +95,5 @@ curr = curr.parent; // don't suggest the own tag, it's not yet open | ||
while (curr) { | ||
var tag = curr.tag; | ||
let tag = curr.tag; | ||
if (tag && (!curr.closed || curr.endTagStart && (curr.endTagStart > offset))) { | ||
var item = { | ||
let item = { | ||
label: '/' + tag, | ||
@@ -107,6 +105,6 @@ kind: vscode_languageserver_types_1.CompletionItemKind.Property, | ||
}; | ||
var startIndent = getLineIndent(curr.start); | ||
var endIndent = getLineIndent(afterOpenBracket - 1); | ||
let startIndent = getLineIndent(curr.start); | ||
let endIndent = getLineIndent(afterOpenBracket - 1); | ||
if (startIndent !== null && endIndent !== null && startIndent !== endIndent) { | ||
var insertText = startIndent + '</' + tag + closeTag; | ||
let insertText = startIndent + '</' + tag + closeTag; | ||
item.textEdit = vscode_languageserver_types_1.TextEdit.replace(getReplaceRange(afterOpenBracket - 1 - endIndent.length), insertText); | ||
@@ -123,4 +121,4 @@ item.filterText = endIndent + '</' + tag + closeTag; | ||
} | ||
dataProviders.forEach(function (provider) { | ||
provider.provideTags().forEach(function (tag) { | ||
dataProviders.forEach(provider => { | ||
provider.provideTags().forEach(tag => { | ||
result.items.push({ | ||
@@ -143,3 +141,3 @@ label: '/' + tag.name, | ||
if (!languageFacts_1.isVoidElement(tag)) { | ||
var pos = document.positionAt(tagCloseEnd); | ||
let pos = document.positionAt(tagCloseEnd); | ||
result.items.push({ | ||
@@ -160,14 +158,13 @@ label: '</' + tag + '>', | ||
} | ||
function collectAttributeNameSuggestions(nameStart, nameEnd) { | ||
if (nameEnd === void 0) { nameEnd = offset; } | ||
var replaceEnd = offset; | ||
function collectAttributeNameSuggestions(nameStart, nameEnd = offset) { | ||
let replaceEnd = offset; | ||
while (replaceEnd < nameEnd && text[replaceEnd] !== '<') { // < is a valid attribute name character, but we rather assume the attribute name ends. See #23236. | ||
replaceEnd++; | ||
} | ||
var range = getReplaceRange(nameStart, replaceEnd); | ||
var value = isFollowedBy(text, nameEnd, htmlLanguageTypes_1.ScannerState.AfterAttributeName, htmlLanguageTypes_1.TokenType.DelimiterAssign) ? '' : '="$1"'; | ||
var tag = currentTag.toLowerCase(); | ||
var seenAttributes = Object.create(null); | ||
dataProviders.forEach(function (provider) { | ||
provider.provideAttributes(tag).forEach(function (attr) { | ||
let range = getReplaceRange(nameStart, replaceEnd); | ||
let value = isFollowedBy(text, nameEnd, htmlLanguageTypes_1.ScannerState.AfterAttributeName, htmlLanguageTypes_1.TokenType.DelimiterAssign) ? '' : '="$1"'; | ||
let tag = currentTag.toLowerCase(); | ||
let seenAttributes = Object.create(null); | ||
dataProviders.forEach(provider => { | ||
provider.provideAttributes(tag).forEach(attr => { | ||
if (seenAttributes[attr.name]) { | ||
@@ -177,4 +174,4 @@ return; | ||
seenAttributes[attr.name] = true; | ||
var codeSnippet = attr.name; | ||
var command; | ||
let codeSnippet = attr.name; | ||
let command; | ||
if (attr.valueSet !== 'v' && value.length) { | ||
@@ -195,3 +192,3 @@ codeSnippet = codeSnippet + value; | ||
insertTextFormat: vscode_languageserver_types_1.InsertTextFormat.Snippet, | ||
command: command | ||
command | ||
}); | ||
@@ -204,7 +201,7 @@ }); | ||
function collectDataAttributesSuggestions(range, seenAttributes) { | ||
var dataAttr = 'data-'; | ||
var dataAttributes = {}; | ||
dataAttributes[dataAttr] = dataAttr + "$1=\"$2\""; | ||
const dataAttr = 'data-'; | ||
let dataAttributes = {}; | ||
dataAttributes[dataAttr] = `${dataAttr}$1="$2"`; | ||
function addNodeDataAttributes(node) { | ||
node.attributeNames.forEach(function (attr) { | ||
node.attributeNames.forEach(attr => { | ||
if (strings_1.startsWith(attr, dataAttr) && !dataAttributes[attr] && !seenAttributes[attr]) { | ||
@@ -214,8 +211,8 @@ dataAttributes[attr] = attr + '="$1"'; | ||
}); | ||
node.children.forEach(function (child) { return addNodeDataAttributes(child); }); | ||
node.children.forEach(child => addNodeDataAttributes(child)); | ||
} | ||
if (htmlDocument) { | ||
htmlDocument.roots.forEach(function (root) { return addNodeDataAttributes(root); }); | ||
htmlDocument.roots.forEach(root => addNodeDataAttributes(root)); | ||
} | ||
Object.keys(dataAttributes).forEach(function (attr) { return result.items.push({ | ||
Object.keys(dataAttributes).forEach(attr => result.items.push({ | ||
label: attr, | ||
@@ -225,13 +222,12 @@ kind: vscode_languageserver_types_1.CompletionItemKind.Value, | ||
insertTextFormat: vscode_languageserver_types_1.InsertTextFormat.Snippet | ||
}); }); | ||
})); | ||
} | ||
function collectAttributeValueSuggestions(valueStart, valueEnd) { | ||
if (valueEnd === void 0) { valueEnd = offset; } | ||
var range; | ||
var addQuotes; | ||
var valuePrefix; | ||
function collectAttributeValueSuggestions(valueStart, valueEnd = offset) { | ||
let range; | ||
let addQuotes; | ||
let valuePrefix; | ||
if (offset > valueStart && offset <= valueEnd && isQuote(text[valueStart])) { | ||
// inside quoted attribute | ||
var valueContentStart = valueStart + 1; | ||
var valueContentEnd = valueEnd; | ||
let valueContentStart = valueStart + 1; | ||
let valueContentEnd = valueEnd; | ||
// valueEnd points to the char after quote, which encloses the replace range | ||
@@ -241,4 +237,4 @@ if (valueEnd > valueStart && text[valueEnd - 1] === text[valueStart]) { | ||
} | ||
var wsBefore = getWordStart(text, offset, valueContentStart); | ||
var wsAfter = getWordEnd(text, offset, valueContentEnd); | ||
let wsBefore = getWordStart(text, offset, valueContentStart); | ||
let wsAfter = getWordEnd(text, offset, valueContentEnd); | ||
range = getReplaceRange(wsBefore, wsAfter); | ||
@@ -253,16 +249,15 @@ valuePrefix = offset >= valueContentStart && offset <= valueContentEnd ? text.substring(valueContentStart, offset) : ''; | ||
} | ||
var tag = currentTag.toLowerCase(); | ||
var attribute = currentAttributeName.toLowerCase(); | ||
let tag = currentTag.toLowerCase(); | ||
let attribute = currentAttributeName.toLowerCase(); | ||
if (completionParticipants.length > 0) { | ||
var fullRange = getReplaceRange(valueStart, valueEnd); | ||
for (var _i = 0, completionParticipants_1 = completionParticipants; _i < completionParticipants_1.length; _i++) { | ||
var participant = completionParticipants_1[_i]; | ||
let fullRange = getReplaceRange(valueStart, valueEnd); | ||
for (let participant of completionParticipants) { | ||
if (participant.onHtmlAttributeValue) { | ||
participant.onHtmlAttributeValue({ document: document, position: position, tag: tag, attribute: attribute, value: valuePrefix, range: fullRange }); | ||
participant.onHtmlAttributeValue({ document, position, tag, attribute, value: valuePrefix, range: fullRange }); | ||
} | ||
} | ||
} | ||
dataProviders.forEach(function (provider) { | ||
provider.provideValues(tag, attribute).forEach(function (value) { | ||
var insertText = addQuotes ? '"' + value.name + '"' : value.name; | ||
dataProviders.forEach(provider => { | ||
provider.provideValues(tag, attribute).forEach(value => { | ||
let insertText = addQuotes ? '"' + value.name + '"' : value.name; | ||
result.items.push({ | ||
@@ -290,6 +285,5 @@ label: value.name, | ||
function collectInsideContent() { | ||
for (var _i = 0, completionParticipants_2 = completionParticipants; _i < completionParticipants_2.length; _i++) { | ||
var participant = completionParticipants_2[_i]; | ||
for (let participant of completionParticipants) { | ||
if (participant.onHtmlContent) { | ||
participant.onHtmlContent({ document: document, position: position }); | ||
participant.onHtmlContent({ document, position }); | ||
} | ||
@@ -301,4 +295,4 @@ } | ||
// character entities | ||
var k = offset - 1; | ||
var characterStart = position.character; | ||
let k = offset - 1; | ||
let characterStart = position.character; | ||
while (k >= 0 && strings_1.isLetterOrDigit(text, k)) { | ||
@@ -309,10 +303,10 @@ k--; | ||
if (k >= 0 && text[k] === '&') { | ||
var range = vscode_languageserver_types_1.Range.create(vscode_languageserver_types_1.Position.create(position.line, characterStart - 1), position); | ||
for (var entity in htmlEntities_1.entities) { | ||
let range = vscode_languageserver_types_1.Range.create(vscode_languageserver_types_1.Position.create(position.line, characterStart - 1), position); | ||
for (let entity in htmlEntities_1.entities) { | ||
if (strings_1.endsWith(entity, ';')) { | ||
var label = '&' + entity; | ||
const label = '&' + entity; | ||
result.items.push({ | ||
label: label, | ||
label, | ||
kind: vscode_languageserver_types_1.CompletionItemKind.Keyword, | ||
documentation: localize('entity.propose', "Character entity representing '" + htmlEntities_1.entities[entity] + "'"), | ||
documentation: localize('entity.propose', `Character entity representing '${htmlEntities_1.entities[entity]}'`), | ||
textEdit: vscode_languageserver_types_1.TextEdit.replace(range, label), | ||
@@ -327,3 +321,3 @@ insertTextFormat: vscode_languageserver_types_1.InsertTextFormat.PlainText | ||
function suggestDoctype(replaceStart, replaceEnd) { | ||
var range = getReplaceRange(replaceStart, replaceEnd); | ||
let range = getReplaceRange(replaceStart, replaceEnd); | ||
result.items.push({ | ||
@@ -337,3 +331,3 @@ label: '!DOCTYPE', | ||
} | ||
var token = scanner.scan(); | ||
let token = scanner.scan(); | ||
while (token !== htmlLanguageTypes_1.TokenType.EOS && scanner.getTokenOffset() <= offset) { | ||
@@ -343,3 +337,3 @@ switch (token) { | ||
if (scanner.getTokenEnd() === offset) { | ||
var endPos = scanNextForEndPos(htmlLanguageTypes_1.TokenType.StartTag); | ||
let endPos = scanNextForEndPos(htmlLanguageTypes_1.TokenType.StartTag); | ||
if (position.line === 0) { | ||
@@ -365,3 +359,3 @@ suggestDoctype(offset, endPos); | ||
if (scanner.getTokenEnd() === offset) { | ||
var endPos = scanNextForEndPos(htmlLanguageTypes_1.TokenType.AttributeValue); | ||
let endPos = scanNextForEndPos(htmlLanguageTypes_1.TokenType.AttributeValue); | ||
return collectAttributeValueSuggestions(offset, endPos); | ||
@@ -379,4 +373,4 @@ } | ||
case htmlLanguageTypes_1.ScannerState.AfterOpeningStartTag: | ||
var startPos = scanner.getTokenOffset(); | ||
var endTagPos = scanNextForEndPos(htmlLanguageTypes_1.TokenType.StartTag); | ||
let startPos = scanner.getTokenOffset(); | ||
let endTagPos = scanNextForEndPos(htmlLanguageTypes_1.TokenType.StartTag); | ||
return collectTagSuggestions(startPos, endTagPos); | ||
@@ -397,4 +391,4 @@ case htmlLanguageTypes_1.ScannerState.WithinTag: | ||
if (offset <= scanner.getTokenEnd()) { | ||
var afterOpenBracket = scanner.getTokenOffset() + 1; | ||
var endOffset = scanNextForEndPos(htmlLanguageTypes_1.TokenType.EndTag); | ||
let afterOpenBracket = scanner.getTokenOffset() + 1; | ||
let endOffset = scanNextForEndPos(htmlLanguageTypes_1.TokenType.EndTag); | ||
return collectCloseTagSuggestions(afterOpenBracket, false, endOffset); | ||
@@ -405,5 +399,5 @@ } | ||
if (offset <= scanner.getTokenEnd()) { | ||
var start = scanner.getTokenOffset() - 1; | ||
let start = scanner.getTokenOffset() - 1; | ||
while (start >= 0) { | ||
var ch = text.charAt(start); | ||
let ch = text.charAt(start); | ||
if (ch === '/') { | ||
@@ -440,17 +434,17 @@ return collectCloseTagSuggestions(start, false, scanner.getTokenEnd()); | ||
return result; | ||
}; | ||
HTMLCompletion.prototype.doTagComplete = function (document, position, htmlDocument) { | ||
var offset = document.offsetAt(position); | ||
} | ||
doTagComplete(document, position, htmlDocument) { | ||
let offset = document.offsetAt(position); | ||
if (offset <= 0) { | ||
return null; | ||
} | ||
var char = document.getText().charAt(offset - 1); | ||
let char = document.getText().charAt(offset - 1); | ||
if (char === '>') { | ||
var node = htmlDocument.findNodeBefore(offset); | ||
let node = htmlDocument.findNodeBefore(offset); | ||
if (node && node.tag && !languageFacts_1.isVoidElement(node.tag) && node.start < offset && (!node.endTagStart || node.endTagStart > offset)) { | ||
var scanner = htmlScanner_1.createScanner(document.getText(), node.start); | ||
var token = scanner.scan(); | ||
let scanner = htmlScanner_1.createScanner(document.getText(), node.start); | ||
let token = scanner.scan(); | ||
while (token !== htmlLanguageTypes_1.TokenType.EOS && scanner.getTokenEnd() <= offset) { | ||
if (token === htmlLanguageTypes_1.TokenType.StartTagClose && scanner.getTokenEnd() === offset) { | ||
return "$0</" + node.tag + ">"; | ||
return `$0</${node.tag}>`; | ||
} | ||
@@ -462,3 +456,3 @@ token = scanner.scan(); | ||
else if (char === '/') { | ||
var node = htmlDocument.findNodeBefore(offset); | ||
let node = htmlDocument.findNodeBefore(offset); | ||
while (node && node.closed) { | ||
@@ -468,7 +462,7 @@ node = node.parent; | ||
if (node && node.tag) { | ||
var scanner = htmlScanner_1.createScanner(document.getText(), node.start); | ||
var token = scanner.scan(); | ||
let scanner = htmlScanner_1.createScanner(document.getText(), node.start); | ||
let token = scanner.scan(); | ||
while (token !== htmlLanguageTypes_1.TokenType.EOS && scanner.getTokenEnd() <= offset) { | ||
if (token === htmlLanguageTypes_1.TokenType.EndTagOpen && scanner.getTokenEnd() === offset) { | ||
return node.tag + ">"; | ||
return `${node.tag}>`; | ||
} | ||
@@ -480,5 +474,4 @@ token = scanner.scan(); | ||
return null; | ||
}; | ||
return HTMLCompletion; | ||
}()); | ||
} | ||
} | ||
exports.HTMLCompletion = HTMLCompletion; | ||
@@ -492,4 +485,4 @@ function isQuote(s) { | ||
function isFollowedBy(s, offset, intialState, expectedToken) { | ||
var scanner = htmlScanner_1.createScanner(s, offset, intialState); | ||
var token = scanner.scan(); | ||
let scanner = htmlScanner_1.createScanner(s, offset, intialState); | ||
let token = scanner.scan(); | ||
while (token === htmlLanguageTypes_1.TokenType.Whitespace) { | ||
@@ -496,0 +489,0 @@ token = scanner.scan(); |
@@ -16,9 +16,9 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var vscode_languageserver_types_1 = require("vscode-languageserver-types"); | ||
var htmlLanguageTypes_1 = require("../htmlLanguageTypes"); | ||
var htmlScanner_1 = require("../parser/htmlScanner"); | ||
var languageFacts_1 = require("../languageFacts"); | ||
const vscode_languageserver_types_1 = require("vscode-languageserver-types"); | ||
const htmlLanguageTypes_1 = require("../htmlLanguageTypes"); | ||
const htmlScanner_1 = require("../parser/htmlScanner"); | ||
const languageFacts_1 = require("../languageFacts"); | ||
function limitRanges(ranges, rangeLimit) { | ||
ranges = ranges.sort(function (r1, r2) { | ||
var diff = r1.startLine - r2.startLine; | ||
ranges = ranges.sort((r1, r2) => { | ||
let diff = r1.startLine - r2.startLine; | ||
if (diff === 0) { | ||
@@ -31,7 +31,7 @@ diff = r1.endLine - r2.endLine; | ||
// count the number of ranges for each level in 'nestingLevelCounts' | ||
var top = void 0; | ||
var previous = []; | ||
var nestingLevels = []; | ||
var nestingLevelCounts = []; | ||
var setNestingLevel = function (index, level) { | ||
let top = void 0; | ||
let previous = []; | ||
let nestingLevels = []; | ||
let nestingLevelCounts = []; | ||
let setNestingLevel = (index, level) => { | ||
nestingLevels[index] = level; | ||
@@ -43,4 +43,4 @@ if (level < 30) { | ||
// compute nesting levels and sanitize | ||
for (var i = 0; i < ranges.length; i++) { | ||
var entry = ranges[i]; | ||
for (let i = 0; i < ranges.length; i++) { | ||
let entry = ranges[i]; | ||
if (!top) { | ||
@@ -70,6 +70,6 @@ top = entry; | ||
} | ||
var entries = 0; | ||
var maxLevel = 0; | ||
for (var i = 0; i < nestingLevelCounts.length; i++) { | ||
var n = nestingLevelCounts[i]; | ||
let entries = 0; | ||
let maxLevel = 0; | ||
for (let i = 0; i < nestingLevelCounts.length; i++) { | ||
let n = nestingLevelCounts[i]; | ||
if (n) { | ||
@@ -83,5 +83,5 @@ if (n + entries > rangeLimit) { | ||
} | ||
var result = []; | ||
for (var i = 0; i < ranges.length; i++) { | ||
var level = nestingLevels[i]; | ||
let result = []; | ||
for (let i = 0; i < ranges.length; i++) { | ||
let level = nestingLevels[i]; | ||
if (typeof level === 'number') { | ||
@@ -96,8 +96,8 @@ if (level < maxLevel || (level === maxLevel && entries++ < rangeLimit)) { | ||
function getFoldingRanges(document, context) { | ||
var scanner = htmlScanner_1.createScanner(document.getText()); | ||
var token = scanner.scan(); | ||
var ranges = []; | ||
var stack = []; | ||
var lastTagName = null; | ||
var prevStart = -1; | ||
const scanner = htmlScanner_1.createScanner(document.getText()); | ||
let token = scanner.scan(); | ||
let ranges = []; | ||
let stack = []; | ||
let lastTagName = null; | ||
let prevStart = -1; | ||
function addRange(range) { | ||
@@ -110,5 +110,5 @@ ranges.push(range); | ||
case htmlLanguageTypes_1.TokenType.StartTag: { | ||
var tagName = scanner.getTokenText(); | ||
var startLine = document.positionAt(scanner.getTokenOffset()).line; | ||
stack.push({ startLine: startLine, tagName: tagName }); | ||
let tagName = scanner.getTokenText(); | ||
let startLine = document.positionAt(scanner.getTokenOffset()).line; | ||
stack.push({ startLine, tagName }); | ||
lastTagName = tagName; | ||
@@ -128,3 +128,3 @@ break; | ||
case htmlLanguageTypes_1.TokenType.StartTagSelfClose: { | ||
var i = stack.length - 1; | ||
let i = stack.length - 1; | ||
while (i >= 0 && stack[i].tagName !== lastTagName) { | ||
@@ -134,9 +134,9 @@ i--; | ||
if (i >= 0) { | ||
var stackElement = stack[i]; | ||
let stackElement = stack[i]; | ||
stack.length = i; | ||
var line = document.positionAt(scanner.getTokenOffset()).line; | ||
var startLine = stackElement.startLine; | ||
var endLine = line - 1; | ||
let line = document.positionAt(scanner.getTokenOffset()).line; | ||
let startLine = stackElement.startLine; | ||
let endLine = line - 1; | ||
if (endLine > startLine && prevStart !== startLine) { | ||
addRange({ startLine: startLine, endLine: endLine }); | ||
addRange({ startLine, endLine }); | ||
} | ||
@@ -147,11 +147,11 @@ } | ||
case htmlLanguageTypes_1.TokenType.Comment: { | ||
var startLine = document.positionAt(scanner.getTokenOffset()).line; | ||
var text = scanner.getTokenText(); | ||
var m = text.match(/^\s*#(region\b)|(endregion\b)/); | ||
let startLine = document.positionAt(scanner.getTokenOffset()).line; | ||
let text = scanner.getTokenText(); | ||
let m = text.match(/^\s*#(region\b)|(endregion\b)/); | ||
if (m) { | ||
if (m[1]) { // start pattern match | ||
stack.push({ startLine: startLine, tagName: '' }); // empty tagName marks region | ||
stack.push({ startLine, tagName: '' }); // empty tagName marks region | ||
} | ||
else { | ||
var i = stack.length - 1; | ||
let i = stack.length - 1; | ||
while (i >= 0 && stack[i].tagName.length) { | ||
@@ -161,8 +161,8 @@ i--; | ||
if (i >= 0) { | ||
var stackElement = stack[i]; | ||
let stackElement = stack[i]; | ||
stack.length = i; | ||
var endLine = startLine; | ||
let endLine = startLine; | ||
startLine = stackElement.startLine; | ||
if (endLine > startLine && prevStart !== startLine) { | ||
addRange({ startLine: startLine, endLine: endLine, kind: vscode_languageserver_types_1.FoldingRangeKind.Region }); | ||
addRange({ startLine, endLine, kind: vscode_languageserver_types_1.FoldingRangeKind.Region }); | ||
} | ||
@@ -173,5 +173,5 @@ } | ||
else { | ||
var endLine = document.positionAt(scanner.getTokenOffset() + scanner.getTokenLength()).line; | ||
let endLine = document.positionAt(scanner.getTokenOffset() + scanner.getTokenLength()).line; | ||
if (startLine < endLine) { | ||
addRange({ startLine: startLine, endLine: endLine, kind: vscode_languageserver_types_1.FoldingRangeKind.Comment }); | ||
addRange({ startLine, endLine, kind: vscode_languageserver_types_1.FoldingRangeKind.Comment }); | ||
} | ||
@@ -184,3 +184,3 @@ } | ||
} | ||
var rangeLimit = context && context.rangeLimit || Number.MAX_VALUE; | ||
let rangeLimit = context && context.rangeLimit || Number.MAX_VALUE; | ||
if (ranges.length > rangeLimit) { | ||
@@ -187,0 +187,0 @@ ranges = limitRanges(ranges, rangeLimit); |
@@ -16,14 +16,14 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var vscode_languageserver_types_1 = require("vscode-languageserver-types"); | ||
var beautify_html_1 = require("../beautify/beautify-html"); | ||
var strings_1 = require("../utils/strings"); | ||
const vscode_languageserver_types_1 = require("vscode-languageserver-types"); | ||
const beautify_html_1 = require("../beautify/beautify-html"); | ||
const strings_1 = require("../utils/strings"); | ||
function format(document, range, options) { | ||
var value = document.getText(); | ||
var includesEnd = true; | ||
var initialIndentLevel = 0; | ||
var tabSize = options.tabSize || 4; | ||
let value = document.getText(); | ||
let includesEnd = true; | ||
let initialIndentLevel = 0; | ||
let tabSize = options.tabSize || 4; | ||
if (range) { | ||
var startOffset = document.offsetAt(range.start); | ||
let startOffset = document.offsetAt(range.start); | ||
// include all leading whitespace iff at the beginning of the line | ||
var extendedStart = startOffset; | ||
let extendedStart = startOffset; | ||
while (extendedStart > 0 && isWhitespace(value, extendedStart - 1)) { | ||
@@ -42,4 +42,4 @@ extendedStart--; | ||
// include all following whitespace until the end of the line | ||
var endOffset = document.offsetAt(range.end); | ||
var extendedEnd = endOffset; | ||
let endOffset = document.offsetAt(range.end); | ||
let extendedEnd = endOffset; | ||
while (extendedEnd < value.length && isWhitespace(value, extendedEnd)) { | ||
@@ -54,3 +54,3 @@ extendedEnd++; | ||
// Ending inside an element is fine as it doesn't cause formatting errors | ||
var firstHalf = value.substring(0, startOffset); | ||
let firstHalf = value.substring(0, startOffset); | ||
if (new RegExp(/.*[<][^>]*$/).test(firstHalf)) { | ||
@@ -67,3 +67,3 @@ //return without modification | ||
if (startOffset !== 0) { | ||
var startOfLineOffset = document.offsetAt(vscode_languageserver_types_1.Position.create(range.start.line, 0)); | ||
let startOfLineOffset = document.offsetAt(vscode_languageserver_types_1.Position.create(range.start.line, 0)); | ||
initialIndentLevel = computeIndentLevel(document.getText(), startOfLineOffset, options); | ||
@@ -75,3 +75,3 @@ } | ||
} | ||
var htmlOptions = { | ||
let htmlOptions = { | ||
indent_size: tabSize, | ||
@@ -92,5 +92,5 @@ indent_char: options.insertSpaces ? ' ' : '\t', | ||
}; | ||
var result = beautify_html_1.html_beautify(trimLeft(value), htmlOptions); | ||
let result = beautify_html_1.html_beautify(trimLeft(value), htmlOptions); | ||
if (initialIndentLevel > 0) { | ||
var indent = options.insertSpaces ? strings_1.repeat(' ', tabSize * initialIndentLevel) : strings_1.repeat('\t', initialIndentLevel); | ||
let indent = options.insertSpaces ? strings_1.repeat(' ', tabSize * initialIndentLevel) : strings_1.repeat('\t', initialIndentLevel); | ||
result = result.split('\n').join('\n' + indent); | ||
@@ -112,3 +112,3 @@ if (range.start.character === 0) { | ||
if (options && options.hasOwnProperty(key)) { | ||
var value = options[key]; | ||
let value = options[key]; | ||
if (value !== null) { | ||
@@ -121,6 +121,6 @@ return value; | ||
function getTagsFormatOption(options, key, dflt) { | ||
var list = getFormatOption(options, key, null); | ||
let list = getFormatOption(options, key, null); | ||
if (typeof list === 'string') { | ||
if (list.length > 0) { | ||
return list.split(',').map(function (t) { return t.trim().toLowerCase(); }); | ||
return list.split(',').map(t => t.trim().toLowerCase()); | ||
} | ||
@@ -132,7 +132,7 @@ return []; | ||
function computeIndentLevel(content, offset, options) { | ||
var i = offset; | ||
var nChars = 0; | ||
var tabSize = options.tabSize || 4; | ||
let i = offset; | ||
let nChars = 0; | ||
let tabSize = options.tabSize || 4; | ||
while (i < content.length) { | ||
var ch = content.charAt(i); | ||
let ch = content.charAt(i); | ||
if (ch === ' ') { | ||
@@ -152,6 +152,6 @@ nChars++; | ||
function getEOL(document) { | ||
var text = document.getText(); | ||
let text = document.getText(); | ||
if (document.lineCount > 1) { | ||
var to = document.offsetAt(vscode_languageserver_types_1.Position.create(1, 0)); | ||
var from = to; | ||
let to = document.offsetAt(vscode_languageserver_types_1.Position.create(1, 0)); | ||
let from = to; | ||
while (from > 0 && isEOL(text, from - 1)) { | ||
@@ -158,0 +158,0 @@ from--; |
@@ -16,14 +16,14 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var htmlScanner_1 = require("../parser/htmlScanner"); | ||
var vscode_languageserver_types_1 = require("vscode-languageserver-types"); | ||
var htmlLanguageTypes_1 = require("../htmlLanguageTypes"); | ||
const htmlScanner_1 = require("../parser/htmlScanner"); | ||
const vscode_languageserver_types_1 = require("vscode-languageserver-types"); | ||
const htmlLanguageTypes_1 = require("../htmlLanguageTypes"); | ||
function findDocumentHighlights(document, position, htmlDocument) { | ||
var offset = document.offsetAt(position); | ||
var node = htmlDocument.findNodeAt(offset); | ||
let offset = document.offsetAt(position); | ||
let node = htmlDocument.findNodeAt(offset); | ||
if (!node.tag) { | ||
return []; | ||
} | ||
var result = []; | ||
var startTagRange = getTagNameRange(htmlLanguageTypes_1.TokenType.StartTag, document, node.start); | ||
var endTagRange = typeof node.endTagStart === 'number' && getTagNameRange(htmlLanguageTypes_1.TokenType.EndTag, document, node.endTagStart); | ||
let result = []; | ||
let startTagRange = getTagNameRange(htmlLanguageTypes_1.TokenType.StartTag, document, node.start); | ||
let endTagRange = typeof node.endTagStart === 'number' && getTagNameRange(htmlLanguageTypes_1.TokenType.EndTag, document, node.endTagStart); | ||
if (startTagRange && covers(startTagRange, position) || endTagRange && covers(endTagRange, position)) { | ||
@@ -47,4 +47,4 @@ if (startTagRange) { | ||
function getTagNameRange(tokenType, document, startOffset) { | ||
var scanner = htmlScanner_1.createScanner(document.getText(), startOffset); | ||
var token = scanner.scan(); | ||
let scanner = htmlScanner_1.createScanner(document.getText(), startOffset); | ||
let token = scanner.scan(); | ||
while (token !== htmlLanguageTypes_1.TokenType.EOS && token !== tokenType) { | ||
@@ -51,0 +51,0 @@ token = scanner.scan(); |
@@ -16,33 +16,27 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var htmlScanner_1 = require("../parser/htmlScanner"); | ||
var vscode_languageserver_types_1 = require("vscode-languageserver-types"); | ||
var languageFacts_1 = require("../languageFacts"); | ||
var htmlLanguageTypes_1 = require("../htmlLanguageTypes"); | ||
const htmlScanner_1 = require("../parser/htmlScanner"); | ||
const vscode_languageserver_types_1 = require("vscode-languageserver-types"); | ||
const languageFacts_1 = require("../languageFacts"); | ||
const htmlLanguageTypes_1 = require("../htmlLanguageTypes"); | ||
function doHover(document, position, htmlDocument) { | ||
var offset = document.offsetAt(position); | ||
var node = htmlDocument.findNodeAt(offset); | ||
let offset = document.offsetAt(position); | ||
let node = htmlDocument.findNodeAt(offset); | ||
if (!node || !node.tag) { | ||
return null; | ||
} | ||
var dataProviders = languageFacts_1.getAllDataProviders().filter(function (p) { return p.isApplicable(document.languageId); }); | ||
let dataProviders = languageFacts_1.getAllDataProviders().filter(p => p.isApplicable(document.languageId)); | ||
function getTagHover(currTag, range, open) { | ||
currTag = currTag.toLowerCase(); | ||
var _loop_1 = function (provider) { | ||
var hover = null; | ||
provider.provideTags().forEach(function (tag) { | ||
for (let provider of dataProviders) { | ||
let hover = null; | ||
provider.provideTags().forEach(tag => { | ||
if (tag.name.toLowerCase() === currTag.toLowerCase()) { | ||
var tagLabel = open ? '<' + currTag + '>' : '</' + currTag + '>'; | ||
var tagDescription = tag.description || ''; | ||
hover = { contents: [{ language: 'html', value: tagLabel }, vscode_languageserver_types_1.MarkedString.fromPlainText(tagDescription)], range: range }; | ||
const tagLabel = open ? '<' + currTag + '>' : '</' + currTag + '>'; | ||
const tagDescription = tag.description || ''; | ||
hover = { contents: [{ language: 'html', value: tagLabel }, vscode_languageserver_types_1.MarkedString.fromPlainText(tagDescription)], range }; | ||
} | ||
}); | ||
if (hover) { | ||
return { value: hover }; | ||
return hover; | ||
} | ||
}; | ||
for (var _i = 0, dataProviders_1 = dataProviders; _i < dataProviders_1.length; _i++) { | ||
var provider = dataProviders_1[_i]; | ||
var state_1 = _loop_1(provider); | ||
if (typeof state_1 === "object") | ||
return state_1.value; | ||
} | ||
@@ -52,4 +46,4 @@ return null; | ||
function getTagNameRange(tokenType, startOffset) { | ||
var scanner = htmlScanner_1.createScanner(document.getText(), startOffset); | ||
var token = scanner.scan(); | ||
let scanner = htmlScanner_1.createScanner(document.getText(), startOffset); | ||
let token = scanner.scan(); | ||
while (token !== htmlLanguageTypes_1.TokenType.EOS && (scanner.getTokenEnd() < offset || scanner.getTokenEnd() === offset && token !== tokenType)) { | ||
@@ -64,9 +58,9 @@ token = scanner.scan(); | ||
if (node.endTagStart && offset >= node.endTagStart) { | ||
var tagRange_1 = getTagNameRange(htmlLanguageTypes_1.TokenType.EndTag, node.endTagStart); | ||
if (tagRange_1) { | ||
return getTagHover(node.tag, tagRange_1, false); | ||
let tagRange = getTagNameRange(htmlLanguageTypes_1.TokenType.EndTag, node.endTagStart); | ||
if (tagRange) { | ||
return getTagHover(node.tag, tagRange, false); | ||
} | ||
return null; | ||
} | ||
var tagRange = getTagNameRange(htmlLanguageTypes_1.TokenType.StartTag, node.start); | ||
let tagRange = getTagNameRange(htmlLanguageTypes_1.TokenType.StartTag, node.start); | ||
if (tagRange) { | ||
@@ -73,0 +67,0 @@ return getTagHover(node.tag, tagRange, true); |
@@ -16,10 +16,10 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var htmlScanner_1 = require("../parser/htmlScanner"); | ||
var vscode_languageserver_types_1 = require("vscode-languageserver-types"); | ||
var strings = require("../utils/strings"); | ||
var vscode_uri_1 = require("vscode-uri"); | ||
var htmlLanguageTypes_1 = require("../htmlLanguageTypes"); | ||
const htmlScanner_1 = require("../parser/htmlScanner"); | ||
const vscode_languageserver_types_1 = require("vscode-languageserver-types"); | ||
const strings = require("../utils/strings"); | ||
const vscode_uri_1 = require("vscode-uri"); | ||
const htmlLanguageTypes_1 = require("../htmlLanguageTypes"); | ||
function normalizeRef(url, languageId) { | ||
var first = url[0]; | ||
var last = url[url.length - 1]; | ||
let first = url[0]; | ||
let last = url[url.length - 1]; | ||
if (first === last && (first === '\'' || first === '\"')) { | ||
@@ -55,3 +55,3 @@ url = url.substr(1, url.length - 2); | ||
// Absolute link (that does not name the protocol) | ||
var pickedScheme = strings.startsWith(documentUri, 'https://') ? 'https' : 'http'; | ||
let pickedScheme = strings.startsWith(documentUri, 'https://') ? 'https' : 'http'; | ||
return pickedScheme + ':' + tokenContent.replace(/^\s*/g, ''); | ||
@@ -65,3 +65,3 @@ } | ||
function createLink(document, documentContext, attributeValue, startOffset, endOffset, base) { | ||
var tokenContent = normalizeRef(attributeValue, document.languageId); | ||
let tokenContent = normalizeRef(attributeValue, document.languageId); | ||
if (!validateRef(tokenContent, document.languageId)) { | ||
@@ -74,3 +74,3 @@ return null; | ||
} | ||
var workspaceUrl = getWorkspaceUrl(document.uri, tokenContent, documentContext, base); | ||
let workspaceUrl = getWorkspaceUrl(document.uri, tokenContent, documentContext, base); | ||
if (!workspaceUrl || !isValidURI(workspaceUrl)) { | ||
@@ -94,9 +94,9 @@ return null; | ||
function findDocumentLinks(document, documentContext) { | ||
var newLinks = []; | ||
var rootAbsoluteUrl = null; | ||
var scanner = htmlScanner_1.createScanner(document.getText(), 0); | ||
var token = scanner.scan(); | ||
var afterHrefOrSrc = false; | ||
var afterBase = false; | ||
var base = void 0; | ||
let newLinks = []; | ||
let rootAbsoluteUrl = null; | ||
let scanner = htmlScanner_1.createScanner(document.getText(), 0); | ||
let token = scanner.scan(); | ||
let afterHrefOrSrc = false; | ||
let afterBase = false; | ||
let base = void 0; | ||
while (token !== htmlLanguageTypes_1.TokenType.EOS) { | ||
@@ -106,3 +106,3 @@ switch (token) { | ||
if (!base) { | ||
var tagName = scanner.getTokenText().toLowerCase(); | ||
let tagName = scanner.getTokenText().toLowerCase(); | ||
afterBase = tagName === 'base'; | ||
@@ -112,3 +112,3 @@ } | ||
case htmlLanguageTypes_1.TokenType.AttributeName: | ||
var attributeName = scanner.getTokenText().toLowerCase(); | ||
let attributeName = scanner.getTokenText().toLowerCase(); | ||
afterHrefOrSrc = attributeName === 'src' || attributeName === 'href'; | ||
@@ -118,5 +118,5 @@ break; | ||
if (afterHrefOrSrc) { | ||
var attributeValue = scanner.getTokenText(); | ||
let attributeValue = scanner.getTokenText(); | ||
if (!afterBase) { // don't highlight the base link itself | ||
var link = createLink(document, documentContext, attributeValue, scanner.getTokenOffset(), scanner.getTokenEnd(), base); | ||
let link = createLink(document, documentContext, attributeValue, scanner.getTokenOffset(), scanner.getTokenEnd(), base); | ||
if (link) { | ||
@@ -123,0 +123,0 @@ newLinks.push(link); |
@@ -16,37 +16,43 @@ (function (factory) { | ||
*/ | ||
var vscode_languageserver_types_1 = require("vscode-languageserver-types"); | ||
var htmlScanner_1 = require("../parser/htmlScanner"); | ||
var htmlParser_1 = require("../parser/htmlParser"); | ||
var htmlLanguageTypes_1 = require("../htmlLanguageTypes"); | ||
function getSelectionRanges(document, position) { | ||
var applicableRanges = getApplicableRanges(document, position); | ||
var ranges = applicableRanges | ||
/** | ||
* Filter duplicated ranges | ||
*/ | ||
.filter(function (pair, i) { | ||
if (i === 0) { | ||
const vscode_languageserver_types_1 = require("vscode-languageserver-types"); | ||
const htmlScanner_1 = require("../parser/htmlScanner"); | ||
const htmlParser_1 = require("../parser/htmlParser"); | ||
const htmlLanguageTypes_1 = require("../htmlLanguageTypes"); | ||
function getSelectionRanges(document, positions) { | ||
function getSelectionRange(position) { | ||
const applicableRanges = getApplicableRanges(document, position); | ||
const ranges = applicableRanges | ||
/** | ||
* Filter duplicated ranges | ||
*/ | ||
.filter((pair, i) => { | ||
if (i === 0) { | ||
return true; | ||
} | ||
const prev = applicableRanges[i - 1]; | ||
if (pair[0] === prev[0] && pair[1] === prev[1]) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
var prev = applicableRanges[i - 1]; | ||
if (pair[0] === prev[0] && pair[1] === prev[1]) { | ||
return false; | ||
} | ||
return true; | ||
}) | ||
.map(function (pair) { | ||
return vscode_languageserver_types_1.Range.create(document.positionAt(pair[0]), document.positionAt(pair[1])); | ||
}); | ||
return ranges; | ||
}) | ||
.map(pair => { | ||
return { | ||
range: vscode_languageserver_types_1.Range.create(document.positionAt(pair[0]), document.positionAt(pair[1])), | ||
kind: htmlLanguageTypes_1.SelectionRangeKind.Declaration | ||
}; | ||
}); | ||
return ranges; | ||
} | ||
return positions.map(getSelectionRange); | ||
} | ||
exports.getSelectionRanges = getSelectionRanges; | ||
function getApplicableRanges(document, position) { | ||
var htmlDoc = htmlParser_1.parse(document.getText()); | ||
var currOffset = document.offsetAt(position); | ||
var currNode = htmlDoc.findNodeAt(currOffset); | ||
var result = getAllParentTagRanges(currNode); | ||
const htmlDoc = htmlParser_1.parse(document.getText()); | ||
const currOffset = document.offsetAt(position); | ||
const currNode = htmlDoc.findNodeAt(currOffset); | ||
let result = getAllParentTagRanges(currNode); | ||
// Self-closing or void elements | ||
if (currNode.startTagEnd && !currNode.endTagStart) { | ||
var closeRange = vscode_languageserver_types_1.Range.create(document.positionAt(currNode.startTagEnd - 2), document.positionAt(currNode.startTagEnd)); | ||
var closeText = document.getText(closeRange); | ||
const closeRange = vscode_languageserver_types_1.Range.create(document.positionAt(currNode.startTagEnd - 2), document.positionAt(currNode.startTagEnd)); | ||
const closeText = document.getText(closeRange); | ||
// Self-closing element | ||
@@ -60,3 +66,3 @@ if (closeText === '/>') { | ||
} | ||
var attributeLevelRanges = getAttributeLevelRanges(document, currNode, currOffset); | ||
const attributeLevelRanges = getAttributeLevelRanges(document, currNode, currOffset); | ||
result = attributeLevelRanges.concat(result); | ||
@@ -78,3 +84,3 @@ return result; | ||
result.unshift([currNode.start + 1, currNode.startTagEnd - 1]); | ||
var attributeLevelRanges = getAttributeLevelRanges(document, currNode, currOffset); | ||
const attributeLevelRanges = getAttributeLevelRanges(document, currNode, currOffset); | ||
result = attributeLevelRanges.concat(result); | ||
@@ -102,4 +108,4 @@ return result; | ||
function getAllParentTagRanges(initialNode) { | ||
var currNode = initialNode; | ||
var getNodeRanges = function (n) { | ||
let currNode = initialNode; | ||
const getNodeRanges = (n) => { | ||
if (n.startTagEnd && n.endTagStart && n.startTagEnd < n.endTagStart) { | ||
@@ -115,6 +121,6 @@ return [ | ||
}; | ||
var result = []; | ||
const result = []; | ||
while (currNode.parent) { | ||
currNode = currNode.parent; | ||
getNodeRanges(currNode).forEach(function (r) { return result.push(r); }); | ||
getNodeRanges(currNode).forEach(r => result.push(r)); | ||
} | ||
@@ -124,10 +130,10 @@ return result; | ||
function getAttributeLevelRanges(document, currNode, currOffset) { | ||
var currNodeRange = vscode_languageserver_types_1.Range.create(document.positionAt(currNode.start), document.positionAt(currNode.end)); | ||
var currNodeText = document.getText(currNodeRange); | ||
var relativeOffset = currOffset - currNode.start; | ||
const currNodeRange = vscode_languageserver_types_1.Range.create(document.positionAt(currNode.start), document.positionAt(currNode.end)); | ||
const currNodeText = document.getText(currNodeRange); | ||
const relativeOffset = currOffset - currNode.start; | ||
/** | ||
* Tag level semantic selection | ||
*/ | ||
var scanner = htmlScanner_1.createScanner(currNodeText); | ||
var token = scanner.scan(); | ||
const scanner = htmlScanner_1.createScanner(currNodeText); | ||
let token = scanner.scan(); | ||
/** | ||
@@ -137,6 +143,6 @@ * For text like | ||
*/ | ||
var positionOffset = currNode.start; | ||
var result = []; | ||
var isInsideAttribute = false; | ||
var attrStart = -1; | ||
const positionOffset = currNode.start; | ||
const result = []; | ||
let isInsideAttribute = false; | ||
let attrStart = -1; | ||
while (token !== htmlLanguageTypes_1.TokenType.EOS) { | ||
@@ -161,3 +167,3 @@ switch (token) { | ||
} | ||
var valueText = scanner.getTokenText(); | ||
const valueText = scanner.getTokenText(); | ||
if (relativeOffset < scanner.getTokenOffset()) { | ||
@@ -172,3 +178,3 @@ // `class="foo"` | ||
// `foo` | ||
if ((valueText[0] === "\"" && valueText[valueText.length - 1] === "\"") || (valueText[0] === "'" && valueText[valueText.length - 1] === "'")) { | ||
if ((valueText[0] === `"` && valueText[valueText.length - 1] === `"`) || (valueText[0] === `'` && valueText[valueText.length - 1] === `'`)) { | ||
if (relativeOffset >= scanner.getTokenOffset() + 1 && relativeOffset <= scanner.getTokenEnd() - 1) { | ||
@@ -186,3 +192,3 @@ result.unshift([scanner.getTokenOffset() + 1, scanner.getTokenEnd() - 1]); | ||
} | ||
return result.map(function (pair) { | ||
return result.map(pair => { | ||
return [pair[0] + positionOffset, pair[1] + positionOffset]; | ||
@@ -189,0 +195,0 @@ }); |
@@ -16,6 +16,6 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var vscode_languageserver_types_1 = require("vscode-languageserver-types"); | ||
const vscode_languageserver_types_1 = require("vscode-languageserver-types"); | ||
function findDocumentSymbols(document, htmlDocument) { | ||
var symbols = []; | ||
htmlDocument.roots.forEach(function (node) { | ||
let symbols = []; | ||
htmlDocument.roots.forEach(node => { | ||
provideFileSymbolsInternal(document, node, '', symbols); | ||
@@ -27,5 +27,5 @@ }); | ||
function provideFileSymbolsInternal(document, node, container, symbols) { | ||
var name = nodeToName(node); | ||
var location = vscode_languageserver_types_1.Location.create(document.uri, vscode_languageserver_types_1.Range.create(document.positionAt(node.start), document.positionAt(node.end))); | ||
var symbol = { | ||
let name = nodeToName(node); | ||
let location = vscode_languageserver_types_1.Location.create(document.uri, vscode_languageserver_types_1.Range.create(document.positionAt(node.start), document.positionAt(node.end))); | ||
let symbol = { | ||
name: name, | ||
@@ -37,3 +37,3 @@ location: location, | ||
symbols.push(symbol); | ||
node.children.forEach(function (child) { | ||
node.children.forEach(child => { | ||
provideFileSymbolsInternal(document, child, name, symbols); | ||
@@ -43,11 +43,11 @@ }); | ||
function nodeToName(node) { | ||
var name = node.tag; | ||
let name = node.tag; | ||
if (node.attributes) { | ||
var id = node.attributes['id']; | ||
var classes = node.attributes['class']; | ||
let id = node.attributes['id']; | ||
let classes = node.attributes['class']; | ||
if (id) { | ||
name += "#" + id.replace(/[\"\']/g, ''); | ||
name += `#${id.replace(/[\"\']/g, '')}`; | ||
} | ||
if (classes) { | ||
name += classes.replace(/[\"\']/g, '').split(/\s+/).map(function (className) { return "." + className; }).join(''); | ||
name += classes.replace(/[\"\']/g, '').split(/\s+/).map(className => `.${className}`).join(''); | ||
} | ||
@@ -54,0 +54,0 @@ } |
@@ -22,3 +22,3 @@ (function (factory) { | ||
function findFirst(array, p) { | ||
var low = 0, high = array.length; | ||
let low = 0, high = array.length; | ||
if (high === 0) { | ||
@@ -28,3 +28,3 @@ return 0; // no children | ||
while (low < high) { | ||
var mid = Math.floor((low + high) / 2); | ||
let mid = Math.floor((low + high) / 2); | ||
if (p(array[mid])) { | ||
@@ -41,6 +41,6 @@ high = mid; | ||
function binarySearch(array, key, comparator) { | ||
var low = 0, high = array.length - 1; | ||
let low = 0, high = array.length - 1; | ||
while (low <= high) { | ||
var mid = ((low + high) / 2) | 0; | ||
var comp = comparator(array[mid], key); | ||
let mid = ((low + high) / 2) | 0; | ||
let comp = comparator(array[mid], key); | ||
if (comp < 0) { | ||
@@ -47,0 +47,0 @@ low = mid + 1; |
@@ -61,11 +61,11 @@ (function (factory) { | ||
// of 1*n, where n is parts.length. | ||
var value = ''; | ||
for (var i = 0; i < arguments.length; i++) { | ||
var part = arguments[i]; | ||
let value = ''; | ||
for (let i = 0; i < arguments.length; i++) { | ||
let part = arguments[i]; | ||
if (i > 0) { | ||
// add the separater between two parts unless | ||
// there already is one | ||
var last = value.charCodeAt(value.length - 1); | ||
let last = value.charCodeAt(value.length - 1); | ||
if (last !== 47 /* Slash */ && last !== 92 /* Backslash */) { | ||
var next = part.charCodeAt(0); | ||
let next = part.charCodeAt(0); | ||
if (next !== 47 /* Slash */ && next !== 92 /* Backslash */) { | ||
@@ -72,0 +72,0 @@ value += '/'; |
@@ -20,3 +20,3 @@ (function (factory) { | ||
} | ||
for (var i = 0; i < needle.length; i++) { | ||
for (let i = 0; i < needle.length; i++) { | ||
if (haystack[i] !== needle[i]) { | ||
@@ -33,3 +33,3 @@ return false; | ||
function endsWith(haystack, needle) { | ||
var diff = haystack.length - needle.length; | ||
let diff = haystack.length - needle.length; | ||
if (diff > 0) { | ||
@@ -50,3 +50,3 @@ return haystack.lastIndexOf(needle) === diff; | ||
function commonPrefixLength(a, b) { | ||
var i, len = Math.min(a.length, b.length); | ||
let i, len = Math.min(a.length, b.length); | ||
for (i = 0; i < len; i++) { | ||
@@ -72,10 +72,10 @@ if (a.charCodeAt(i) !== b.charCodeAt(i)) { | ||
exports.repeat = repeat; | ||
var _a = 'a'.charCodeAt(0); | ||
var _z = 'z'.charCodeAt(0); | ||
var _A = 'A'.charCodeAt(0); | ||
var _Z = 'Z'.charCodeAt(0); | ||
var _0 = '0'.charCodeAt(0); | ||
var _9 = '9'.charCodeAt(0); | ||
const _a = 'a'.charCodeAt(0); | ||
const _z = 'z'.charCodeAt(0); | ||
const _A = 'A'.charCodeAt(0); | ||
const _Z = 'Z'.charCodeAt(0); | ||
const _0 = '0'.charCodeAt(0); | ||
const _9 = '9'.charCodeAt(0); | ||
function isLetterOrDigit(text, index) { | ||
var c = text.charCodeAt(index); | ||
let c = text.charCodeAt(index); | ||
return (_a <= c && c <= _z) || (_A <= c && c <= _Z) || (_0 <= c && c <= _9); | ||
@@ -82,0 +82,0 @@ } |
{ | ||
"name": "vscode-html-languageservice", | ||
"version": "2.1.11", | ||
"version": "3.0.0-next.0", | ||
"description": "Language service for HTML", | ||
@@ -18,15 +18,15 @@ "main": "./lib/umd/htmlLanguageService.js", | ||
"devDependencies": { | ||
"@types/mocha": "2.2.33", | ||
"@types/node": "^8.10.25", | ||
"@types/mocha": "2.2.42", | ||
"@types/node": "^10.12.21", | ||
"cpy-cli": "^2.0.0", | ||
"js-beautify": "^1.9.0-beta5", | ||
"mocha": "^5.2.0", | ||
"js-beautify": "^1.9.0", | ||
"mocha": "^6.0.2", | ||
"remark": "^10.0.1", | ||
"rimraf": "^2.6.2", | ||
"rimraf": "^2.6.3", | ||
"strip-markdown": "^3.0.3", | ||
"tslint": "^5.11.0", | ||
"typescript": "^3.0.3" | ||
"tslint": "^5.13.1", | ||
"typescript": "^3.3.3333" | ||
}, | ||
"dependencies": { | ||
"vscode-languageserver-types": "^3.13.0", | ||
"vscode-languageserver-types": "^3.14.0", | ||
"vscode-nls": "^4.0.0", | ||
@@ -33,0 +33,0 @@ "vscode-uri": "^1.0.6" |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30051
1430829
2