Skip to content

Commit c6ad02f

Browse files
committed
Updated HTML language server
1 parent 1043218 commit c6ad02f

File tree

9 files changed

+145
-187
lines changed

9 files changed

+145
-187
lines changed

server/package-lock.json

Lines changed: 92 additions & 92 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
},
1717
"main": "./out/node/htmlServerMain",
1818
"dependencies": {
19-
"vscode-css-languageservice": "^6.0.1",
20-
"vscode-html-languageservice": "^5.0.0",
21-
"vscode-languageserver": "^8.0.2-next.4",
22-
"vscode-languageserver-textdocument": "^1.0.4",
23-
"vscode-nls": "^5.0.1",
24-
"vscode-uri": "^3.0.3"
19+
"vscode-css-languageservice": "^6.2.1",
20+
"vscode-html-languageservice": "^5.0.3",
21+
"vscode-languageserver": "^8.1.0-next.2",
22+
"vscode-languageserver-textdocument": "^1.0.7",
23+
"vscode-uri": "^3.0.6",
24+
"@vscode/l10n": "^0.0.10"
2525
},
2626
"devDependencies": {
2727
"@types/mocha": "^9.1.1",
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
declare let self: any;
6+
7+
import * as l10n from '@vscode/l10n';
8+
9+
let initialized = false;
10+
self.onmessage = async (e: any) => {
11+
if (!initialized) {
12+
initialized = true;
13+
const i10lLocation = e.data.i10lLocation;
14+
if (i10lLocation) {
15+
await l10n.config({ uri: i10lLocation });
16+
}
17+
await import('./htmlServerMain');
18+
}
19+
};

server/src/modes/embeddedSupport.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ function getEmbeddedDocument(document: TextDocument, contents: EmbeddedRegion[],
168168
for (const c of contents) {
169169
if (c.languageId === languageId && (!ignoreAttributeValues || !c.attributeValue)) {
170170
result = substituteWithWhitespace(result, currentPos, c.start, oldContent, lastSuffix, getPrefix(c));
171-
result += oldContent.substring(c.start, c.end);
171+
result += updateContent(c, oldContent.substring(c.start, c.end));
172172
currentPos = c.end;
173173
lastSuffix = getSuffix(c);
174174
}
@@ -194,11 +194,17 @@ function getSuffix(c: EmbeddedRegion) {
194194
}
195195
return '';
196196
}
197+
function updateContent(c: EmbeddedRegion, content: string): string {
198+
if (!c.attributeValue && c.languageId === 'javascript') {
199+
return content.replace(`<!--`, `/* `).replace(`-->`, ` */`);
200+
}
201+
return content;
202+
}
197203

198204
function substituteWithWhitespace(result: string, start: number, end: number, oldContent: string, before: string, after: string) {
199-
let accumulatedWS = 0;
200205
result += before;
201-
for (let i = start + before.length; i < end; i++) {
206+
let accumulatedWS = -before.length; // start with a negative value to account for the before string
207+
for (let i = start; i < end; i++) {
202208
const ch = oldContent[i];
203209
if (ch === '\n' || ch === '\r') {
204210
// only write new lines, skip the whitespace

server/src/modes/javascriptMode.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,16 @@ function getLanguageServiceHost(scriptKind: ts.ScriptKind) {
9393
};
9494
}
9595

96+
const ignoredErrors = [
97+
1108, /* A_return_statement_can_only_be_used_within_a_function_body_1108 */
98+
2792, /* Cannot_find_module_0_Did_you_mean_to_set_the_moduleResolution_option_to_node_or_to_add_aliases_to_the_paths_option */
99+
];
96100

97101
export function getJavaScriptMode(documentRegions: LanguageModelCache<HTMLDocumentRegions>, languageId: 'javascript' | 'typescript', workspace: Workspace): LanguageMode {
98102
const jsDocuments = getLanguageModelCache<TextDocument>(10, 60, document => documentRegions.get(document).getEmbeddedDocument(languageId));
99103

100104
const host = getLanguageServiceHost(languageId === 'javascript' ? ts.ScriptKind.JS : ts.ScriptKind.TS);
101105
const globalSettings: Settings = {};
102-
103106
return {
104107
getId() {
105108
return languageId;
@@ -110,7 +113,7 @@ export function getJavaScriptMode(documentRegions: LanguageModelCache<HTMLDocume
110113
const languageService = await host.getLanguageService(jsDocument);
111114
const syntaxDiagnostics: ts.Diagnostic[] = languageService.getSyntacticDiagnostics(jsDocument.uri);
112115
const semanticDiagnostics = languageService.getSemanticDiagnostics(jsDocument.uri);
113-
return syntaxDiagnostics.concat(semanticDiagnostics).filter(d => d.code !== 1108).map((diag: ts.Diagnostic): Diagnostic => {
116+
return syntaxDiagnostics.concat(semanticDiagnostics).filter(d => !ignoredErrors.includes(d.code)).map((diag: ts.Diagnostic): Diagnostic => {
114117
return {
115118
range: convertRange(jsDocument, diag),
116119
severity: DiagnosticSeverity.Error,

server/src/node/nodeFs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { FileSystemProvider, getScheme } from '../requests';
6+
import { FileSystemProvider } from '../requests';
77
import { URI as Uri } from 'vscode-uri';
88

99
import * as fs from 'fs';
1010
import { FileType } from 'vscode-css-languageservice';
1111

1212
export function getNodeFileFS(): FileSystemProvider {
1313
function ensureFileUri(location: string) {
14-
if (getScheme(location) !== 'file') {
14+
if (!location.startsWith('file:')) {
1515
throw new Error('fileSystemProvider can only handle file URLs');
1616
}
1717
}

0 commit comments

Comments
 (0)