diff --git a/extensions/html/server/package.json b/extensions/html/server/package.json
index 9056f257be6a36226a4ebfe7ba5d6745867b857f..65cd75b02e9a879c56ea4e004c267bae702473c9 100644
--- a/extensions/html/server/package.json
+++ b/extensions/html/server/package.json
@@ -8,8 +8,8 @@
"node": "*"
},
"dependencies": {
- "vscode-css-languageservice": "^3.0.2",
- "vscode-html-languageservice": "^2.0.13",
+ "vscode-css-languageservice": "^3.0.3",
+ "vscode-html-languageservice": "^2.0.14",
"vscode-languageserver": "^3.5.0",
"vscode-nls": "^2.0.2",
"vscode-uri": "^1.0.1"
diff --git a/extensions/html/server/src/htmlServerMain.ts b/extensions/html/server/src/htmlServerMain.ts
index 3cb1fc97d2ba9556b11baeb9c45b47eb453378f7..8ce00331d83d8e94fec5b745c853f9136528eded 100644
--- a/extensions/html/server/src/htmlServerMain.ts
+++ b/extensions/html/server/src/htmlServerMain.ts
@@ -5,7 +5,6 @@
'use strict';
import { createConnection, IConnection, TextDocuments, InitializeParams, InitializeResult, RequestType, DocumentRangeFormattingRequest, Disposable, DocumentSelector, TextDocumentPositionParams, ServerCapabilities, Position } from 'vscode-languageserver';
-import { DocumentContext } from 'vscode-html-languageservice';
import { TextDocument, Diagnostic, DocumentLink, SymbolInformation } from 'vscode-languageserver-types';
import { getLanguageModes, LanguageModes, Settings } from './modes/languageModes';
@@ -15,13 +14,11 @@ import { DidChangeWorkspaceFoldersNotification, WorkspaceFolder } from 'vscode-l
import { format } from './modes/formatting';
import { pushAll } from './utils/arrays';
-import { endsWith, startsWith } from './utils/strings';
-
-import * as url from 'url';
-import * as path from 'path';
+import { getDocumentContext } from './utils/documentContext';
import uri from 'vscode-uri';
import * as nls from 'vscode-nls';
+
nls.config(process.env['VSCODE_NLS_CONFIG']);
namespace TagCloseRequest {
@@ -41,7 +38,6 @@ let documents: TextDocuments = new TextDocuments();
// for open, change and close text document events
documents.listen(connection);
-let workspacePath: string | undefined | null;
let workspaceFolders: WorkspaceFolder[] | undefined;
var languageModes: LanguageModes;
@@ -77,8 +73,13 @@ function getDocumentSettings(textDocument: TextDocument, needsDocumentSettings:
connection.onInitialize((params: InitializeParams): InitializeResult => {
let initializationOptions = params.initializationOptions;
- workspacePath = params.rootPath;
workspaceFolders = (params).workspaceFolders;
+ if (!Array.isArray(workspaceFolders)) {
+ workspaceFolders = [];
+ if (params.rootPath) {
+ workspaceFolders.push({ name: '', uri: uri.file(params.rootPath).toString() });
+ }
+ }
languageModes = getLanguageModes(initializationOptions ? initializationOptions.embeddedLanguages : { css: true, javascript: true });
documents.onDidClose(e => {
@@ -305,45 +306,19 @@ connection.onDocumentRangeFormatting(async formatParams => {
connection.onDocumentLinks(documentLinkParam => {
let document = documents.get(documentLinkParam.textDocument.uri);
- let documentContext: DocumentContext = {
- resolveReference: (ref, base) => {
- if (base) {
- ref = url.resolve(base, ref);
- }
- if (ref[0] === '/') {
- let root = getRootFolder(document.uri);
- if (root) {
- return uri.file(path.join(root, ref)).toString();
- }
- }
- return url.resolve(document.uri, ref);
- },
-
- };
let links: DocumentLink[] = [];
- languageModes.getAllModesInDocument(document).forEach(m => {
- if (m.findDocumentLinks) {
- pushAll(links, m.findDocumentLinks(document, documentContext));
- }
- });
+ if (document) {
+ let documentContext = getDocumentContext(document.uri, workspaceFolders);
+ languageModes.getAllModesInDocument(document).forEach(m => {
+ if (m.findDocumentLinks) {
+ pushAll(links, m.findDocumentLinks(document, documentContext));
+ }
+ });
+ }
return links;
});
-function getRootFolder(docUri: string): string | undefined {
- if (workspaceFolders) {
- for (let folder of workspaceFolders) {
- let folderURI = folder.uri;
- if (!endsWith(folderURI, '/')) {
- folderURI = folderURI + '/';
- }
- if (startsWith(docUri, folderURI)) {
- return uri.parse(folderURI).fsPath;
- }
- }
- return void 0;
- }
- return workspacePath;
-}
+
connection.onDocumentSymbol(documentSymbolParms => {
let document = documents.get(documentSymbolParms.textDocument.uri);
diff --git a/extensions/html/server/src/test/documentContext.test.ts b/extensions/html/server/src/test/documentContext.test.ts
new file mode 100644
index 0000000000000000000000000000000000000000..4d9dba13fbcfac50f8c6984cabeb2da2adc96c14
--- /dev/null
+++ b/extensions/html/server/src/test/documentContext.test.ts
@@ -0,0 +1,22 @@
+/*---------------------------------------------------------------------------------------------
+ * Copyright (c) Microsoft Corporation. All rights reserved.
+ * Licensed under the MIT License. See License.txt in the project root for license information.
+ *--------------------------------------------------------------------------------------------*/
+'use strict';
+
+import * as assert from 'assert';
+import { getDocumentContext } from '../utils/documentContext';
+
+suite('Document Context', () => {
+
+ test('Context', function (): any {
+ const docURI = 'file:///users/test/folder/test.html';
+ const rootFolders = [{ name: '', uri: 'file:///users/test/' }];
+
+ let context = getDocumentContext(docURI, rootFolders);
+ assert.equal(context.resolveReference('/', docURI), 'file:///users/test/');
+ assert.equal(context.resolveReference('/message.html', docURI), 'file:///users/test/message.html');
+ assert.equal(context.resolveReference('message.html', docURI), 'file:///users/test/folder/message.html');
+ assert.equal(context.resolveReference('message.html', 'file:///users/test/'), 'file:///users/test/message.html');
+ });
+});
\ No newline at end of file
diff --git a/extensions/html/server/src/utils/documentContext.ts b/extensions/html/server/src/utils/documentContext.ts
new file mode 100644
index 0000000000000000000000000000000000000000..fb56e1d882ce9f270df96fd0ebb7c0e21e53ae51
--- /dev/null
+++ b/extensions/html/server/src/utils/documentContext.ts
@@ -0,0 +1,40 @@
+/*---------------------------------------------------------------------------------------------
+ * Copyright (c) Microsoft Corporation. All rights reserved.
+ * Licensed under the MIT License. See License.txt in the project root for license information.
+ *--------------------------------------------------------------------------------------------*/
+'use strict';
+
+import { DocumentContext } from 'vscode-html-languageservice';
+import { endsWith, startsWith } from '../utils/strings';
+import * as url from 'url';
+import { WorkspaceFolder } from 'vscode-languageserver-protocol/lib/protocol.workspaceFolders.proposed';
+
+export function getDocumentContext(documentUri: string, workspaceFolders: WorkspaceFolder[]): DocumentContext {
+ function getRootFolder(): string | undefined {
+ for (let folder of workspaceFolders) {
+ let folderURI = folder.uri;
+ if (!endsWith(folderURI, '/')) {
+ folderURI = folderURI + '/';
+ }
+ if (startsWith(documentUri, folderURI)) {
+ return folderURI;
+ }
+ }
+ return void 0;
+ }
+
+ return {
+ resolveReference: (ref, base = documentUri) => {
+ if (ref[0] === '/') { // resolve absolute path against the current workspace folder
+ if (startsWith(base, 'file://')) {
+ let folderUri = getRootFolder();
+ if (folderUri) {
+ return folderUri + ref.substr(1);
+ }
+ }
+ }
+ return url.resolve(base, ref);
+ },
+ };
+}
+
diff --git a/extensions/html/server/yarn.lock b/extensions/html/server/yarn.lock
index f2c569af414fae8c3c6470ae57f12aee6561b87c..d676d5f4456b6a124774c448ad72cb39a00d5ea5 100644
--- a/extensions/html/server/yarn.lock
+++ b/extensions/html/server/yarn.lock
@@ -10,16 +10,16 @@
version "7.0.43"
resolved "https://registry.yarnpkg.com/@types/node/-/node-7.0.43.tgz#a187e08495a075f200ca946079c914e1a5fe962c"
-vscode-css-languageservice@^3.0.2:
- version "3.0.2"
- resolved "https://registry.yarnpkg.com/vscode-css-languageservice/-/vscode-css-languageservice-3.0.2.tgz#ae0c43836318455aa290c777556394d6127b8f6c"
+vscode-css-languageservice@^3.0.3:
+ version "3.0.3"
+ resolved "https://registry.yarnpkg.com/vscode-css-languageservice/-/vscode-css-languageservice-3.0.3.tgz#02cc4efa5335f5104e0a2f3b6920faaf59db4f7a"
dependencies:
vscode-languageserver-types "3.5.0"
vscode-nls "^2.0.1"
-vscode-html-languageservice@^2.0.13:
- version "2.0.13"
- resolved "https://registry.yarnpkg.com/vscode-html-languageservice/-/vscode-html-languageservice-2.0.13.tgz#09c4437cffb0800b865d71552f4dfd8240c796d8"
+vscode-html-languageservice@^2.0.14:
+ version "2.0.14"
+ resolved "https://registry.yarnpkg.com/vscode-html-languageservice/-/vscode-html-languageservice-2.0.14.tgz#15491c11bb7e196f6fd03b6c6c768901935862eb"
dependencies:
vscode-languageserver-types "3.5.0"
vscode-nls "^2.0.2"