vscode-html-languageservice
Advanced tools
Comparing version 3.1.3 to 3.1.4
@@ -6,6 +6,10 @@ /*--------------------------------------------------------------------------------------------- | ||
import { createScanner } from '../parser/htmlScanner'; | ||
import { MarkupKind } from 'vscode-languageserver-types'; | ||
import { Range, Position, MarkupKind } from 'vscode-languageserver-types'; | ||
import { TokenType } from '../htmlLanguageTypes'; | ||
import { isDefined } from '../utils/object'; | ||
import { generateDocumentation } from '../languageFacts/dataProvider'; | ||
import { entities } from '../parser/htmlEntities'; | ||
import { isLetterOrDigit } from '../utils/strings'; | ||
import * as nls from 'vscode-nls'; | ||
var localize = nls.loadMessageBundle(); | ||
var HTMLHover = /** @class */ (function () { | ||
@@ -21,2 +25,3 @@ function HTMLHover(lsOptions, dataManager) { | ||
var node = htmlDocument.findNodeAt(offset); | ||
var text = document.getText(); | ||
if (!node || !node.tag) { | ||
@@ -108,2 +113,34 @@ return null; | ||
} | ||
function getEntityHover(text, range) { | ||
var currEntity = filterEntity(text); | ||
for (var entity in entities) { | ||
var hover = null; | ||
var label = '&' + entity; | ||
if (currEntity === label) { | ||
var code = entities[entity].charCodeAt(0).toString(16).toUpperCase(); | ||
var hex = 'U+'; | ||
if (code.length < 4) { | ||
var zeroes = 4 - code.length; | ||
var k = 0; | ||
while (k < zeroes) { | ||
hex += '0'; | ||
k += 1; | ||
} | ||
} | ||
hex += code; | ||
var contentsDoc = localize('entity.propose', "Character entity representing '" + entities[entity] + "', unicode equivalent '" + hex + "'"); | ||
if (contentsDoc) { | ||
hover = { contents: contentsDoc, range: range }; | ||
} | ||
else { | ||
hover = null; | ||
} | ||
} | ||
if (hover) { | ||
hover.contents = convertContents(hover.contents); | ||
return hover; | ||
} | ||
} | ||
return null; | ||
} | ||
function getTagNameRange(tokenType, startOffset) { | ||
@@ -120,2 +157,41 @@ var scanner = createScanner(document.getText(), startOffset); | ||
} | ||
function getEntityRange() { | ||
var k = offset - 1; | ||
var characterStart = position.character; | ||
while (k >= 0 && isLetterOrDigit(text, k)) { | ||
k--; | ||
characterStart--; | ||
} | ||
var n = k + 1; | ||
var characterEnd = characterStart; | ||
while (isLetterOrDigit(text, n)) { | ||
n++; | ||
characterEnd++; | ||
} | ||
if (k >= 0 && text[k] === '&') { | ||
var range = null; | ||
if (text[n] === ';') { | ||
range = Range.create(Position.create(position.line, characterStart), Position.create(position.line, characterEnd + 1)); | ||
} | ||
else { | ||
range = Range.create(Position.create(position.line, characterStart), Position.create(position.line, characterEnd)); | ||
} | ||
return range; | ||
} | ||
return null; | ||
} | ||
function filterEntity(text) { | ||
var k = offset - 1; | ||
var newText = '&'; | ||
while (k >= 0 && isLetterOrDigit(text, k)) { | ||
k--; | ||
} | ||
k = k + 1; | ||
while (isLetterOrDigit(text, k)) { | ||
newText += text[k]; | ||
k += 1; | ||
} | ||
newText += ';'; | ||
return newText; | ||
} | ||
if (node.endTagStart && offset >= node.endTagStart) { | ||
@@ -138,2 +214,6 @@ var tagRange_1 = getTagNameRange(TokenType.EndTag, node.endTagStart); | ||
} | ||
var entityRange = getEntityRange(); | ||
if (entityRange) { | ||
return getEntityHover(text, entityRange); | ||
} | ||
function scanAttrAndAttrValue(nodeStart, attrValueStart) { | ||
@@ -140,0 +220,0 @@ var scanner = createScanner(document.getText(), nodeStart); |
@@ -11,3 +11,3 @@ /*--------------------------------------------------------------------------------------------- | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "../parser/htmlScanner", "vscode-languageserver-types", "../htmlLanguageTypes", "../utils/object", "../languageFacts/dataProvider"], factory); | ||
define(["require", "exports", "../parser/htmlScanner", "vscode-languageserver-types", "../htmlLanguageTypes", "../utils/object", "../languageFacts/dataProvider", "../parser/htmlEntities", "../utils/strings", "vscode-nls"], factory); | ||
} | ||
@@ -23,2 +23,6 @@ })(function (require, exports) { | ||
var dataProvider_1 = require("../languageFacts/dataProvider"); | ||
var htmlEntities_1 = require("../parser/htmlEntities"); | ||
var strings_1 = require("../utils/strings"); | ||
var nls = require("vscode-nls"); | ||
var localize = nls.loadMessageBundle(); | ||
var HTMLHover = /** @class */ (function () { | ||
@@ -34,2 +38,3 @@ function HTMLHover(lsOptions, dataManager) { | ||
var node = htmlDocument.findNodeAt(offset); | ||
var text = document.getText(); | ||
if (!node || !node.tag) { | ||
@@ -121,2 +126,34 @@ return null; | ||
} | ||
function getEntityHover(text, range) { | ||
var currEntity = filterEntity(text); | ||
for (var entity in htmlEntities_1.entities) { | ||
var hover = null; | ||
var label = '&' + entity; | ||
if (currEntity === label) { | ||
var code = htmlEntities_1.entities[entity].charCodeAt(0).toString(16).toUpperCase(); | ||
var hex = 'U+'; | ||
if (code.length < 4) { | ||
var zeroes = 4 - code.length; | ||
var k = 0; | ||
while (k < zeroes) { | ||
hex += '0'; | ||
k += 1; | ||
} | ||
} | ||
hex += code; | ||
var contentsDoc = localize('entity.propose', "Character entity representing '" + htmlEntities_1.entities[entity] + "', unicode equivalent '" + hex + "'"); | ||
if (contentsDoc) { | ||
hover = { contents: contentsDoc, range: range }; | ||
} | ||
else { | ||
hover = null; | ||
} | ||
} | ||
if (hover) { | ||
hover.contents = convertContents(hover.contents); | ||
return hover; | ||
} | ||
} | ||
return null; | ||
} | ||
function getTagNameRange(tokenType, startOffset) { | ||
@@ -133,2 +170,41 @@ var scanner = htmlScanner_1.createScanner(document.getText(), startOffset); | ||
} | ||
function getEntityRange() { | ||
var k = offset - 1; | ||
var characterStart = position.character; | ||
while (k >= 0 && strings_1.isLetterOrDigit(text, k)) { | ||
k--; | ||
characterStart--; | ||
} | ||
var n = k + 1; | ||
var characterEnd = characterStart; | ||
while (strings_1.isLetterOrDigit(text, n)) { | ||
n++; | ||
characterEnd++; | ||
} | ||
if (k >= 0 && text[k] === '&') { | ||
var range = null; | ||
if (text[n] === ';') { | ||
range = vscode_languageserver_types_1.Range.create(vscode_languageserver_types_1.Position.create(position.line, characterStart), vscode_languageserver_types_1.Position.create(position.line, characterEnd + 1)); | ||
} | ||
else { | ||
range = vscode_languageserver_types_1.Range.create(vscode_languageserver_types_1.Position.create(position.line, characterStart), vscode_languageserver_types_1.Position.create(position.line, characterEnd)); | ||
} | ||
return range; | ||
} | ||
return null; | ||
} | ||
function filterEntity(text) { | ||
var k = offset - 1; | ||
var newText = '&'; | ||
while (k >= 0 && strings_1.isLetterOrDigit(text, k)) { | ||
k--; | ||
} | ||
k = k + 1; | ||
while (strings_1.isLetterOrDigit(text, k)) { | ||
newText += text[k]; | ||
k += 1; | ||
} | ||
newText += ';'; | ||
return newText; | ||
} | ||
if (node.endTagStart && offset >= node.endTagStart) { | ||
@@ -151,2 +227,6 @@ var tagRange_1 = getTagNameRange(htmlLanguageTypes_1.TokenType.EndTag, node.endTagStart); | ||
} | ||
var entityRange = getEntityRange(); | ||
if (entityRange) { | ||
return getEntityHover(text, entityRange); | ||
} | ||
function scanAttrAndAttrValue(nodeStart, attrValueStart) { | ||
@@ -153,0 +233,0 @@ var scanner = htmlScanner_1.createScanner(document.getText(), nodeStart); |
{ | ||
"name": "vscode-html-languageservice", | ||
"version": "3.1.3", | ||
"version": "3.1.4", | ||
"description": "Language service for HTML", | ||
@@ -5,0 +5,0 @@ "main": "./lib/umd/htmlLanguageService.js", |
@@ -16,6 +16,6 @@ # vscode-html-languageservice | ||
- *findDocumentHighlights* provides the highlighted symbols for a given position. | ||
- *doComplete* provides completion proposals for a given location. | ||
- *doComplete* / *doComplete2* (async) provide completion proposals for a given location. | ||
- *setCompletionParticipants* allows participant to provide suggestions for specific tokens. | ||
- *doHover* provides hover information at a given location. | ||
- *format* formats the code at the given range. | ||
@@ -26,3 +26,6 @@ - *findDocumentLinks* finds all links in the document. | ||
- *getSelectionRanges* return the selection ranges for the given document. | ||
... | ||
For the complete API see [htmlLanguageService.ts](./src/htmlLanguageService.ts) and [htmlLanguageTypes.ts](./src/htmlLanguageTypes.ts) | ||
Installation | ||
@@ -33,2 +36,30 @@ ------------ | ||
Development | ||
----------- | ||
- clone this repo, run yarn | ||
- `yarn test` to compile and run tests | ||
How can I run and debug the service? | ||
- open the folder in VSCode. | ||
- set breakpoints, e.g. in `htmlCompletion.ts` | ||
- run the Unit tests from the run viewlet and wait until a breakpoint is hit: | ||
![image](https://user-images.githubusercontent.com/6461412/94239202-bdad4e80-ff11-11ea-99c3-cb9dbeb1c0b2.png) | ||
How can I run and debug the service inside an instance of VSCode? | ||
- run VSCode out of sources setup as described here: https://github.com/Microsoft/vscode/wiki/How-to-Contribute | ||
- link the fodler of the `vscode-html-languageservice` repo to `vscode/extensions/html-language-features/server` to run VSCode with the latest changes from that folder: | ||
- cd `vscode-html-languageservice`, `yarn link` | ||
- cd `vscode/extensions/html-language-features/server`, `yarn link vscode-html-languageservice | ||
- run VSCode out of source (`vscode/scripts/code.sh|bat`) and open a `.html` file | ||
- in VSCode window that is open on the `vscode-html-languageservice` sources, run command `Debug: Attach to Node process` and pick the `code-oss` process with the `html-language-features` path | ||
![image](https://user-images.githubusercontent.com/6461412/94239296-dfa6d100-ff11-11ea-8e30-6444cf5defb8.png) | ||
- set breakpoints, e.g. in `htmlCompletion.ts` | ||
- in the instance run from sources, invoke code completion in the `.html` file | ||
License | ||
@@ -39,5 +70,5 @@ ------- | ||
Copyright 2016-2019, Microsoft | ||
Copyright 2016-2020, Microsoft | ||
With the exceptions of `data/*.json`, which is built upon content from [Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/Web) | ||
and distributed under CC BY-SA 2.5. |
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
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
1544607
32509
71