mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 20:26:08 +00:00
[css] update to vscode-uri@3.0
This commit is contained in:
@@ -10,9 +10,9 @@
|
||||
"main": "./out/node/cssServerMain",
|
||||
"browser": "./dist/browser/cssServerMain",
|
||||
"dependencies": {
|
||||
"vscode-css-languageservice": "^5.0.0",
|
||||
"vscode-css-languageservice": "^5.0.1",
|
||||
"vscode-languageserver": "^7.0.0",
|
||||
"vscode-uri": "^2.1.2"
|
||||
"vscode-uri": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/mocha": "7.0.2",
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { RequestService, getScheme } from '../requests';
|
||||
import { RequestService } from '../requests';
|
||||
import { URI as Uri } from 'vscode-uri';
|
||||
|
||||
import * as fs from 'fs';
|
||||
@@ -11,7 +11,7 @@ import { FileType } from 'vscode-css-languageservice';
|
||||
|
||||
export function getNodeFSRequestService(): RequestService {
|
||||
function ensureFileUri(location: string) {
|
||||
if (getScheme(location) !== 'file') {
|
||||
if (!location.startsWith('file://')) {
|
||||
throw new Error('fileRequestService can only handle file URLs');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { URI } from 'vscode-uri';
|
||||
import { RequestType, Connection } from 'vscode-languageserver';
|
||||
import { RuntimeEnvironment } from './cssServer';
|
||||
|
||||
@@ -99,79 +98,6 @@ export function getRequestService(handledSchemas: string[], connection: Connecti
|
||||
};
|
||||
}
|
||||
|
||||
export function getScheme(uri: string) {
|
||||
function getScheme(uri: string) {
|
||||
return uri.substr(0, uri.indexOf(':'));
|
||||
}
|
||||
|
||||
export function dirname(uri: string) {
|
||||
const lastIndexOfSlash = uri.lastIndexOf('/');
|
||||
return lastIndexOfSlash !== -1 ? uri.substr(0, lastIndexOfSlash) : '';
|
||||
}
|
||||
|
||||
export function basename(uri: string) {
|
||||
const lastIndexOfSlash = uri.lastIndexOf('/');
|
||||
return uri.substr(lastIndexOfSlash + 1);
|
||||
}
|
||||
|
||||
|
||||
const Slash = '/'.charCodeAt(0);
|
||||
const Dot = '.'.charCodeAt(0);
|
||||
|
||||
export function extname(uri: string) {
|
||||
for (let i = uri.length - 1; i >= 0; i--) {
|
||||
const ch = uri.charCodeAt(i);
|
||||
if (ch === Dot) {
|
||||
if (i > 0 && uri.charCodeAt(i - 1) !== Slash) {
|
||||
return uri.substr(i);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else if (ch === Slash) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
export function isAbsolutePath(path: string) {
|
||||
return path.charCodeAt(0) === Slash;
|
||||
}
|
||||
|
||||
export function resolvePath(uriString: string, path: string): string {
|
||||
if (isAbsolutePath(path)) {
|
||||
const uri = URI.parse(uriString);
|
||||
const parts = path.split('/');
|
||||
return uri.with({ path: normalizePath(parts) }).toString();
|
||||
}
|
||||
return joinPath(uriString, path);
|
||||
}
|
||||
|
||||
export function normalizePath(parts: string[]): string {
|
||||
const newParts: string[] = [];
|
||||
for (const part of parts) {
|
||||
if (part.length === 0 || part.length === 1 && part.charCodeAt(0) === Dot) {
|
||||
// ignore
|
||||
} else if (part.length === 2 && part.charCodeAt(0) === Dot && part.charCodeAt(1) === Dot) {
|
||||
newParts.pop();
|
||||
} else {
|
||||
newParts.push(part);
|
||||
}
|
||||
}
|
||||
if (parts.length > 1 && parts[parts.length - 1].length === 0) {
|
||||
newParts.push('');
|
||||
}
|
||||
let res = newParts.join('/');
|
||||
if (parts[0].length === 0) {
|
||||
res = '/' + res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
export function joinPath(uriString: string, ...paths: string[]): string {
|
||||
const uri = URI.parse(uriString);
|
||||
const parts = uri.path.split('/');
|
||||
for (let path of paths) {
|
||||
parts.push(...path.split('/'));
|
||||
}
|
||||
return uri.with({ path: normalizePath(parts) }).toString();
|
||||
}
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import 'mocha';
|
||||
import * as assert from 'assert';
|
||||
import { joinPath, normalizePath, resolvePath, extname } from '../requests';
|
||||
|
||||
suite('requests', () => {
|
||||
test('join', async function () {
|
||||
assert.equal(joinPath('foo://a/foo/bar', 'x'), 'foo://a/foo/bar/x');
|
||||
assert.equal(joinPath('foo://a/foo/bar/', 'x'), 'foo://a/foo/bar/x');
|
||||
assert.equal(joinPath('foo://a/foo/bar/', '/x'), 'foo://a/foo/bar/x');
|
||||
assert.equal(joinPath('foo://a/foo/bar/', 'x/'), 'foo://a/foo/bar/x/');
|
||||
assert.equal(joinPath('foo://a/foo/bar/', 'x', 'y'), 'foo://a/foo/bar/x/y');
|
||||
assert.equal(joinPath('foo://a/foo/bar/', 'x/', '/y'), 'foo://a/foo/bar/x/y');
|
||||
assert.equal(joinPath('foo://a/foo/bar/', '.', '/y'), 'foo://a/foo/bar/y');
|
||||
assert.equal(joinPath('foo://a/foo/bar/', 'x/y/z', '..'), 'foo://a/foo/bar/x/y');
|
||||
});
|
||||
|
||||
test('resolve', async function () {
|
||||
assert.equal(resolvePath('foo://a/foo/bar', 'x'), 'foo://a/foo/bar/x');
|
||||
assert.equal(resolvePath('foo://a/foo/bar/', 'x'), 'foo://a/foo/bar/x');
|
||||
assert.equal(resolvePath('foo://a/foo/bar/', '/x'), 'foo://a/x');
|
||||
assert.equal(resolvePath('foo://a/foo/bar/', 'x/'), 'foo://a/foo/bar/x/');
|
||||
});
|
||||
|
||||
test('normalize', async function () {
|
||||
function assertNormalize(path: string, expected: string) {
|
||||
assert.equal(normalizePath(path.split('/')), expected, path);
|
||||
}
|
||||
assertNormalize('a', 'a');
|
||||
assertNormalize('/a', '/a');
|
||||
assertNormalize('a/', 'a/');
|
||||
assertNormalize('a/b', 'a/b');
|
||||
assertNormalize('/a/foo/bar/x', '/a/foo/bar/x');
|
||||
assertNormalize('/a/foo/bar//x', '/a/foo/bar/x');
|
||||
assertNormalize('/a/foo/bar///x', '/a/foo/bar/x');
|
||||
assertNormalize('/a/foo/bar/x/', '/a/foo/bar/x/');
|
||||
assertNormalize('a/foo/bar/x/', 'a/foo/bar/x/');
|
||||
assertNormalize('a/foo/bar/x//', 'a/foo/bar/x/');
|
||||
assertNormalize('//a/foo/bar/x//', '/a/foo/bar/x/');
|
||||
assertNormalize('a/.', 'a');
|
||||
assertNormalize('a/./b', 'a/b');
|
||||
assertNormalize('a/././b', 'a/b');
|
||||
assertNormalize('a/n/../b', 'a/b');
|
||||
assertNormalize('a/n/../', 'a/');
|
||||
assertNormalize('a/n/../', 'a/');
|
||||
assertNormalize('/a/n/../..', '/');
|
||||
assertNormalize('..', '');
|
||||
assertNormalize('/..', '/');
|
||||
});
|
||||
|
||||
test('extname', async function () {
|
||||
function assertExtName(input: string, expected: string) {
|
||||
assert.equal(extname(input), expected, input);
|
||||
}
|
||||
assertExtName('foo://a/foo/bar', '');
|
||||
assertExtName('foo://a/foo/bar.foo', '.foo');
|
||||
assertExtName('foo://a/foo/.foo', '');
|
||||
});
|
||||
});
|
||||
@@ -6,7 +6,7 @@
|
||||
import { DocumentContext } from 'vscode-css-languageservice';
|
||||
import { endsWith, startsWith } from '../utils/strings';
|
||||
import { WorkspaceFolder } from 'vscode-languageserver';
|
||||
import { resolvePath } from '../requests';
|
||||
import { Utils, URI } from 'vscode-uri';
|
||||
|
||||
export function getDocumentContext(documentUri: string, workspaceFolders: WorkspaceFolder[]): DocumentContext {
|
||||
function getRootFolder(): string | undefined {
|
||||
@@ -31,7 +31,7 @@ export function getDocumentContext(documentUri: string, workspaceFolders: Worksp
|
||||
}
|
||||
}
|
||||
base = base.substr(0, base.lastIndexOf('/') + 1);
|
||||
return resolvePath(base, ref);
|
||||
return Utils.resolvePath(URI.parse(base), ref).toString();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ if (process.env.BUILD_ARTIFACTSTAGINGDIRECTORY) {
|
||||
|
||||
const mocha = new Mocha(options);
|
||||
|
||||
glob.sync(__dirname + '/../out/test/**/*.test.js')
|
||||
glob.sync(path.join(__dirname, '../out/test/**/*.test.js'))
|
||||
.forEach(file => mocha.addFile(file));
|
||||
|
||||
mocha.run(failures => process.exit(failures ? -1 : 0));
|
||||
|
||||
@@ -12,15 +12,15 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.11.7.tgz#57682a9771a3f7b09c2497f28129a0462966524a"
|
||||
integrity sha512-JNbGaHFCLwgHn/iCckiGSOZ1XYHsKFwREtzPwSGCVld1SGhOlmZw2D4ZI94HQCrBHbADzW9m4LER/8olJTRGHA==
|
||||
|
||||
vscode-css-languageservice@^5.0.0:
|
||||
version "5.0.0"
|
||||
resolved "https://registry.yarnpkg.com/vscode-css-languageservice/-/vscode-css-languageservice-5.0.0.tgz#04fd899e25407a2fccd8f59a5896e2f020269bda"
|
||||
integrity sha512-DTMa8QbVmujFPvD3NxoC5jjIXCyCG+cvn3hNzwQRhvhsk8LblNymBZBwzfcDdgEtqsi4O/2AB5HnMIRzxhzEzg==
|
||||
vscode-css-languageservice@^5.0.1:
|
||||
version "5.0.1"
|
||||
resolved "https://registry.yarnpkg.com/vscode-css-languageservice/-/vscode-css-languageservice-5.0.1.tgz#0061e0af23e7c49feba3abfda90799a4877738ee"
|
||||
integrity sha512-9Lzf7XQD82ykwuyuma2r5g2NkrFth96k7PC4YCwtMoLIKxHXGDqHm7NIzjvY2qi43WgUROpw9XXTKKr8NmNuhA==
|
||||
dependencies:
|
||||
vscode-languageserver-textdocument "^1.0.1"
|
||||
vscode-languageserver-types "^3.16.0"
|
||||
vscode-nls "^5.0.0"
|
||||
vscode-uri "^2.1.2"
|
||||
vscode-uri "^3.0.0"
|
||||
|
||||
vscode-jsonrpc@6.0.0:
|
||||
version "6.0.0"
|
||||
@@ -57,7 +57,7 @@ vscode-nls@^5.0.0:
|
||||
resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-5.0.0.tgz#99f0da0bd9ea7cda44e565a74c54b1f2bc257840"
|
||||
integrity sha512-u0Lw+IYlgbEJFF6/qAqG2d1jQmJl0eyAGJHoAJqr2HT4M2BNuQYSEiSE75f52pXHSJm8AlTjnLLbBFPrdz2hpA==
|
||||
|
||||
vscode-uri@^2.1.2:
|
||||
version "2.1.2"
|
||||
resolved "https://registry.yarnpkg.com/vscode-uri/-/vscode-uri-2.1.2.tgz#c8d40de93eb57af31f3c715dd650e2ca2c096f1c"
|
||||
integrity sha512-8TEXQxlldWAuIODdukIb+TR5s+9Ds40eSJrw+1iDDA9IFORPjMELarNQE3myz5XIkWWpdprmJjm1/SxMlWOC8A==
|
||||
vscode-uri@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/vscode-uri/-/vscode-uri-3.0.0.tgz#a881b16614999d97e71d5d29ea453d4f8c19499d"
|
||||
integrity sha512-boWPjBN8UPv8/9OnEGumoXgIVreVjs3RyqULtfHC3GRT1aCnaotYRKOhZERmaMsCVVt6nPmmI/ec7i1FH2kctw==
|
||||
|
||||
Reference in New Issue
Block a user