Skip to content

Commit 97fdb7d

Browse files
authored
(fix) bump html language service (#644)
- Parser got better: Now sees `<` as start of other opening tag. #547, closes #578 - New option to not provide default data provider which removes duplicate suggestions
1 parent ff23eef commit 97fdb7d

File tree

4 files changed

+58
-26
lines changed

4 files changed

+58
-26
lines changed

packages/language-server/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,12 @@
5959
"typescript": "*",
6060
"vscode-css-languageservice": "4.2.0",
6161
"vscode-emmet-helper": "1.2.17",
62-
"vscode-html-languageservice": "3.0.4-next.15",
62+
"vscode-html-languageservice": "3.1.4",
6363
"vscode-languageserver": "6.1.1",
6464
"vscode-languageserver-types": "3.15.1",
6565
"vscode-uri": "2.1.2"
66+
},
67+
"resolutions": {
68+
"vscode-languageserver-types": "3.15.1"
6669
}
6770
}

packages/language-server/src/plugins/html/HTMLPlugin.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import { EmmetConfiguration, getEmmetCompletionParticipants } from 'vscode-emmet-helper';
2-
import { getLanguageService, HTMLDocument } from 'vscode-html-languageservice';
2+
import {
3+
getLanguageService,
4+
HTMLDocument,
5+
CompletionItem as HtmlCompletionItem
6+
} from 'vscode-html-languageservice';
37
import {
48
CompletionList,
59
Hover,
610
Position,
711
SymbolInformation,
812
CompletionItem,
9-
CompletionItemKind
13+
CompletionItemKind,
14+
TextEdit
1015
} from 'vscode-languageserver';
1116
import {
1217
DocumentManager,
@@ -20,7 +25,10 @@ import { HoverProvider, CompletionsProvider } from '../interfaces';
2025

2126
export class HTMLPlugin implements HoverProvider, CompletionsProvider {
2227
private configManager: LSConfigManager;
23-
private lang = getLanguageService({ customDataProviders: [svelteHtmlDataProvider] });
28+
private lang = getLanguageService({
29+
customDataProviders: [svelteHtmlDataProvider],
30+
useDefaultDataProvider: false
31+
});
2432
private documents = new WeakMap<Document, HTMLDocument>();
2533
private styleScriptTemplate = new Set(['template', 'style', 'script']);
2634

@@ -84,13 +92,34 @@ export class HTMLPlugin implements HoverProvider, CompletionsProvider {
8492
// Other attributes/events would be false positives.
8593
CompletionList.create([])
8694
: this.lang.doComplete(document, position, html);
95+
const items = this.toCompletionItems(results.items);
8796
return CompletionList.create(
88-
[...results.items, ...this.getLangCompletions(results.items), ...emmetResults.items],
97+
[
98+
...this.toCompletionItems(items),
99+
...this.getLangCompletions(items),
100+
...emmetResults.items
101+
],
89102
// Emmet completions change on every keystroke, so they are never complete
90103
emmetResults.items.length > 0
91104
);
92105
}
93106

107+
/**
108+
* The HTML language service uses newer types which clash
109+
* without the stable ones. Transform to the stable types.
110+
*/
111+
private toCompletionItems(items: HtmlCompletionItem[]): CompletionItem[] {
112+
return items.map((item) => {
113+
if (!item.textEdit || TextEdit.is(item.textEdit)) {
114+
return <CompletionItem>item;
115+
}
116+
return {
117+
...item,
118+
textEdit: TextEdit.replace(item.textEdit.replace, item.textEdit.newText)
119+
};
120+
});
121+
}
122+
94123
private isInComponentTag(html: HTMLDocument, document: Document, position: Position) {
95124
return !!getNodeIfIsInComponentStartTag(html, document.offsetAt(position));
96125
}

packages/language-server/test/plugins/html/HTMLPlugin.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('HTML Plugin', () => {
2929
contents: {
3030
kind: 'markdown',
3131
value:
32-
'```html\n<h1>\n```\nThe h1 element represents a section heading.\n\n[MDN Reference](https://developer.mozilla.org/docs/Web/HTML/Element/Heading_Elements)'
32+
'The h1 element represents a section heading.\n\n[MDN Reference](https://developer.mozilla.org/docs/Web/HTML/Element/Heading_Elements)'
3333
},
3434

3535
range: Range.create(0, 1, 0, 3)

yarn.lock

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2652,15 +2652,15 @@ [email protected]:
26522652
jsonc-parser "^1.0.0"
26532653
vscode-languageserver-types "^3.6.0-next.1"
26542654

2655-
vscode-html-languageservice@3.0.4-next.15:
2656-
version "3.0.4-next.15"
2657-
resolved "https://registry.yarnpkg.com/vscode-html-languageservice/-/vscode-html-languageservice-3.0.4-next.15.tgz#7214ccd9b4a06cf138b5945d9fd88285a0add490"
2658-
integrity sha512-UmUm3A1ZTj+BloVIyel+5pK/nfsqRfPLXzl8BA9O7v5Cj64vivddABvNf/rW1US8fzdikFNZNloC/4ooqxB2kw==
2655+
vscode-html-languageservice@3.1.4:
2656+
version "3.1.4"
2657+
resolved "https://registry.yarnpkg.com/vscode-html-languageservice/-/vscode-html-languageservice-3.1.4.tgz#0316dff77ee38dc176f40560cbf55e4f64f4f433"
2658+
integrity sha512-3M+bm+hNvwQcScVe5/ok9BXvctOiGJ4nlOkkFf+WKSDrYNkarZ/RByKOa1/iylbvZxJUPzbeziembWPe/dMvhw==
26592659
dependencies:
2660-
vscode-languageserver-textdocument "^1.0.1-next.1"
2661-
vscode-languageserver-types "^3.15.1"
2662-
vscode-nls "^4.1.1"
2663-
vscode-uri "^2.1.1"
2660+
vscode-languageserver-textdocument "^1.0.1"
2661+
vscode-languageserver-types "3.16.0-next.2"
2662+
vscode-nls "^5.0.0"
2663+
vscode-uri "^2.1.2"
26642664

26652665
vscode-jsonrpc@^5.0.1:
26662666
version "5.0.1"
@@ -2683,7 +2683,7 @@ [email protected], vscode-languageserver-protocol@^3.15.3:
26832683
vscode-jsonrpc "^5.0.1"
26842684
vscode-languageserver-types "3.15.1"
26852685

2686-
vscode-languageserver-textdocument@^1.0.1, vscode-languageserver-textdocument@^1.0.1-next.1:
2686+
vscode-languageserver-textdocument@^1.0.1:
26872687
version "1.0.1"
26882688
resolved "https://registry.yarnpkg.com/vscode-languageserver-textdocument/-/vscode-languageserver-textdocument-1.0.1.tgz#178168e87efad6171b372add1dea34f53e5d330f"
26892689
integrity sha512-UIcJDjX7IFkck7cSkNNyzIz5FyvpQfY7sdzVy+wkKN/BLaD4DQ0ppXQrKePomCxTS7RrolK1I0pey0bG9eh8dA==
@@ -2693,33 +2693,33 @@ [email protected], vscode-languageserver-types@^3.15.1, vscode-
26932693
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.15.1.tgz#17be71d78d2f6236d414f0001ce1ef4d23e6b6de"
26942694
integrity sha512-+a9MPUQrNGRrGU630OGbYVQ+11iOIovjCkqxajPa9w57Sd5ruK8WQNsslzpa0x/QJqC8kRc2DUxWjIFwoNm4ZQ==
26952695

2696+
2697+
version "3.16.0-next.2"
2698+
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.16.0-next.2.tgz#940bd15c992295a65eae8ab6b8568a1e8daa3083"
2699+
integrity sha512-QjXB7CKIfFzKbiCJC4OWC8xUncLsxo19FzGVp/ADFvvi87PlmBSCAtZI5xwGjF5qE0xkLf0jjKUn3DzmpDP52Q==
2700+
26962701
26972702
version "6.1.1"
26982703
resolved "https://registry.yarnpkg.com/vscode-languageserver/-/vscode-languageserver-6.1.1.tgz#d76afc68172c27d4327ee74332b468fbc740d762"
26992704
integrity sha512-DueEpkUAkD5XTR4MLYNr6bQIp/UFR0/IPApgXU3YfCBCB08u2sm9hRCs6DxYZELkk++STPjpcjksR2H8qI3cDQ==
27002705
dependencies:
27012706
vscode-languageserver-protocol "^3.15.3"
27022707

2703-
vscode-nls@^4.1.1:
2704-
version "4.1.1"
2705-
resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-4.1.1.tgz#f9916b64e4947b20322defb1e676a495861f133c"
2706-
integrity sha512-4R+2UoUUU/LdnMnFjePxfLqNhBS8lrAFyX7pjb2ud/lqDkrUavFUTcG7wR0HBZFakae0Q6KLBFjMS6W93F403A==
2707-
27082708
vscode-nls@^4.1.2:
27092709
version "4.1.2"
27102710
resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-4.1.2.tgz#ca8bf8bb82a0987b32801f9fddfdd2fb9fd3c167"
27112711
integrity sha512-7bOHxPsfyuCqmP+hZXscLhiHwe7CSuFE4hyhbs22xPIhQ4jv99FcR4eBzfYYVLP356HNFpdvz63FFb/xw6T4Iw==
27122712

2713-
2713+
vscode-nls@^5.0.0:
2714+
version "5.0.0"
2715+
resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-5.0.0.tgz#99f0da0bd9ea7cda44e565a74c54b1f2bc257840"
2716+
integrity sha512-u0Lw+IYlgbEJFF6/qAqG2d1jQmJl0eyAGJHoAJqr2HT4M2BNuQYSEiSE75f52pXHSJm8AlTjnLLbBFPrdz2hpA==
2717+
2718+
[email protected], vscode-uri@^2.1.1, vscode-uri@^2.1.2:
27142719
version "2.1.2"
27152720
resolved "https://registry.yarnpkg.com/vscode-uri/-/vscode-uri-2.1.2.tgz#c8d40de93eb57af31f3c715dd650e2ca2c096f1c"
27162721
integrity sha512-8TEXQxlldWAuIODdukIb+TR5s+9Ds40eSJrw+1iDDA9IFORPjMELarNQE3myz5XIkWWpdprmJjm1/SxMlWOC8A==
27172722

2718-
vscode-uri@^2.1.1:
2719-
version "2.1.1"
2720-
resolved "https://registry.yarnpkg.com/vscode-uri/-/vscode-uri-2.1.1.tgz#5aa1803391b6ebdd17d047f51365cf62c38f6e90"
2721-
integrity sha512-eY9jmGoEnVf8VE8xr5znSah7Qt1P/xsCdErz+g8HYZtJ7bZqKH5E3d+6oVNm1AC/c6IHUDokbmVXKOi4qPAC9A==
2722-
27232723
which-module@^2.0.0:
27242724
version "2.0.0"
27252725
resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a"

0 commit comments

Comments
 (0)