mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 20:26:08 +00:00
[html] clean up request service: add CustomDataRequestService #135459
This commit is contained in:
@@ -4,10 +4,11 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { workspace, extensions, Uri, EventEmitter, Disposable } from 'vscode';
|
||||
import { resolvePath, joinPath } from './requests';
|
||||
import { Runtime } from './htmlClient';
|
||||
import { Utils } from 'vscode-uri';
|
||||
|
||||
|
||||
export function getCustomDataSource(toDispose: Disposable[]) {
|
||||
export function getCustomDataSource(runtime: Runtime, toDispose: Disposable[]) {
|
||||
let pathsInWorkspace = getCustomDataPathsInAllWorkspaces();
|
||||
let pathsInExtensions = getCustomDataPathsFromAllExtensions();
|
||||
|
||||
@@ -40,6 +41,17 @@ export function getCustomDataSource(toDispose: Disposable[]) {
|
||||
},
|
||||
get onDidChange() {
|
||||
return onChange.event;
|
||||
},
|
||||
getContent(uriString: string): Thenable<string> {
|
||||
const uri = Uri.parse(uriString);
|
||||
if (pathsInExtensions.has(uriString)) {
|
||||
return workspace.fs.readFile(uri).then(buffer => {
|
||||
return new runtime.TextDecoder().decode(buffer);
|
||||
});
|
||||
}
|
||||
return workspace.openTextDocument(uri).then(doc => {
|
||||
return doc.getText();
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -64,7 +76,7 @@ function getCustomDataPathsInAllWorkspaces(): Set<string> {
|
||||
if (typeof uriOrPath === 'string') {
|
||||
if (!isURI(uriOrPath)) {
|
||||
// path in the workspace
|
||||
dataPaths.add(resolvePath(rootFolder, uriOrPath).toString());
|
||||
dataPaths.add(Utils.resolvePath(rootFolder, uriOrPath).toString());
|
||||
} else {
|
||||
// external uri
|
||||
dataPaths.add(uriOrPath);
|
||||
@@ -100,7 +112,7 @@ function getCustomDataPathsFromAllExtensions(): Set<string> {
|
||||
for (const uriOrPath of customData) {
|
||||
if (!isURI(uriOrPath)) {
|
||||
// relative path in an extension
|
||||
dataPaths.add(joinPath(extension.extensionUri, uriOrPath).toString());
|
||||
dataPaths.add(Uri.joinPath(extension.extensionUri, uriOrPath).toString());
|
||||
} else {
|
||||
// external uri
|
||||
dataPaths.add(uriOrPath);
|
||||
|
||||
@@ -16,13 +16,17 @@ import {
|
||||
DocumentRangeFormattingRequest, ProvideCompletionItemsSignature, TextDocumentIdentifier, RequestType0, Range as LspRange, NotificationType, CommonLanguageClient
|
||||
} from 'vscode-languageclient';
|
||||
import { activateTagClosing } from './tagClosing';
|
||||
import { RequestService, serveFileSystemRequests } from './requests';
|
||||
import { FileSystemProvider, serveFileSystemRequests } from './requests';
|
||||
import { getCustomDataSource } from './customData';
|
||||
|
||||
namespace CustomDataChangedNotification {
|
||||
export const type: NotificationType<string[]> = new NotificationType('html/customDataChanged');
|
||||
}
|
||||
|
||||
namespace CustomDataContent {
|
||||
export const type: RequestType<string, string, any> = new RequestType('html/customDataContent');
|
||||
}
|
||||
|
||||
namespace TagCloseRequest {
|
||||
export const type: RequestType<TextDocumentPositionParams, string, any> = new RequestType('html/tag');
|
||||
}
|
||||
@@ -56,7 +60,7 @@ export type LanguageClientConstructor = (name: string, description: string, clie
|
||||
|
||||
export interface Runtime {
|
||||
TextDecoder: { new(encoding?: string): { decode(buffer: ArrayBuffer): string; } };
|
||||
fs?: RequestService;
|
||||
fileFs?: FileSystemProvider;
|
||||
telemetry?: TelemetryReporter;
|
||||
readonly timer: {
|
||||
setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): Disposable;
|
||||
@@ -73,8 +77,6 @@ export function startClient(context: ExtensionContext, newLanguageClient: Langua
|
||||
|
||||
let rangeFormatting: Disposable | undefined = undefined;
|
||||
|
||||
const customDataSource = getCustomDataSource(context.subscriptions);
|
||||
|
||||
// Options to control the language client
|
||||
let clientOptions: LanguageClientOptions = {
|
||||
documentSelector,
|
||||
@@ -122,10 +124,14 @@ export function startClient(context: ExtensionContext, newLanguageClient: Langua
|
||||
|
||||
toDispose.push(serveFileSystemRequests(client, runtime));
|
||||
|
||||
const customDataSource = getCustomDataSource(runtime, context.subscriptions);
|
||||
|
||||
client.sendNotification(CustomDataChangedNotification.type, customDataSource.uris);
|
||||
customDataSource.onDidChange(() => {
|
||||
client.sendNotification(CustomDataChangedNotification.type, customDataSource.uris);
|
||||
});
|
||||
client.onRequest(CustomDataContent.type, customDataSource.getContent);
|
||||
|
||||
|
||||
let tagRequestor = (document: TextDocument, position: Position) => {
|
||||
let param = client.code2ProtocolConverter.asTextDocumentPositionParams(document, position);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { getNodeFSRequestService } from './nodeFs';
|
||||
import { getNodeFileFS } from './nodeFs';
|
||||
import { Disposable, ExtensionContext } from 'vscode';
|
||||
import { startClient, LanguageClientConstructor } from '../htmlClient';
|
||||
import { ServerOptions, TransportKind, LanguageClientOptions, LanguageClient } from 'vscode-languageclient/node';
|
||||
@@ -44,7 +44,7 @@ export function activate(context: ExtensionContext) {
|
||||
}
|
||||
};
|
||||
|
||||
startClient(context, newLanguageClient, { fs: getNodeFSRequestService(), TextDecoder, telemetry, timer });
|
||||
startClient(context, newLanguageClient, { fileFs: getNodeFileFS(), TextDecoder, telemetry, timer });
|
||||
}
|
||||
|
||||
interface IPackageInfo {
|
||||
|
||||
@@ -5,28 +5,15 @@
|
||||
|
||||
import * as fs from 'fs';
|
||||
import { Uri } from 'vscode';
|
||||
import { getScheme, RequestService, FileType } from '../requests';
|
||||
import { FileSystemProvider, FileType } from '../requests';
|
||||
|
||||
export function getNodeFSRequestService(): RequestService {
|
||||
export function getNodeFileFS(): FileSystemProvider {
|
||||
function ensureFileUri(location: string) {
|
||||
if (getScheme(location) !== 'file') {
|
||||
if (!location.startsWith('file:')) {
|
||||
throw new Error('fileRequestService can only handle file URLs');
|
||||
}
|
||||
}
|
||||
return {
|
||||
getContent(location: string, encoding?: string) {
|
||||
ensureFileUri(location);
|
||||
return new Promise((c, e) => {
|
||||
const uri = Uri.parse(location);
|
||||
fs.readFile(uri.fsPath, encoding, (err, buf) => {
|
||||
if (err) {
|
||||
return e(err);
|
||||
}
|
||||
c(buf.toString());
|
||||
|
||||
});
|
||||
});
|
||||
},
|
||||
stat(location: string) {
|
||||
ensureFileUri(location);
|
||||
return new Promise((c, e) => {
|
||||
|
||||
@@ -7,9 +7,6 @@ import { Uri, workspace, Disposable } from 'vscode';
|
||||
import { RequestType, CommonLanguageClient } from 'vscode-languageclient';
|
||||
import { Runtime } from './htmlClient';
|
||||
|
||||
export namespace FsContentRequest {
|
||||
export const type: RequestType<{ uri: string; encoding?: string; }, string, any> = new RequestType('fs/content');
|
||||
}
|
||||
export namespace FsStatRequest {
|
||||
export const type: RequestType<string, FileStat, any> = new RequestType('fs/stat');
|
||||
}
|
||||
@@ -20,26 +17,17 @@ export namespace FsReadDirRequest {
|
||||
|
||||
export function serveFileSystemRequests(client: CommonLanguageClient, runtime: Runtime): Disposable {
|
||||
const disposables = [];
|
||||
disposables.push(client.onRequest(FsContentRequest.type, (param: { uri: string; encoding?: string; }) => {
|
||||
const uri = Uri.parse(param.uri);
|
||||
if (uri.scheme === 'file' && runtime.fs) {
|
||||
return runtime.fs.getContent(param.uri);
|
||||
}
|
||||
return workspace.fs.readFile(uri).then(buffer => {
|
||||
return new runtime.TextDecoder(param.encoding).decode(buffer);
|
||||
});
|
||||
}));
|
||||
disposables.push(client.onRequest(FsReadDirRequest.type, (uriString: string) => {
|
||||
const uri = Uri.parse(uriString);
|
||||
if (uri.scheme === 'file' && runtime.fs) {
|
||||
return runtime.fs.readDirectory(uriString);
|
||||
if (uri.scheme === 'file' && runtime.fileFs) {
|
||||
return runtime.fileFs.readDirectory(uriString);
|
||||
}
|
||||
return workspace.fs.readDirectory(uri);
|
||||
}));
|
||||
disposables.push(client.onRequest(FsStatRequest.type, (uriString: string) => {
|
||||
const uri = Uri.parse(uriString);
|
||||
if (uri.scheme === 'file' && runtime.fs) {
|
||||
return runtime.fs.stat(uriString);
|
||||
if (uri.scheme === 'file' && runtime.fileFs) {
|
||||
return runtime.fileFs.stat(uriString);
|
||||
}
|
||||
return workspace.fs.stat(uri);
|
||||
}));
|
||||
@@ -84,67 +72,7 @@ export interface FileStat {
|
||||
size: number;
|
||||
}
|
||||
|
||||
export interface RequestService {
|
||||
getContent(uri: string, encoding?: string): Promise<string>;
|
||||
|
||||
export interface FileSystemProvider {
|
||||
stat(uri: string): Promise<FileStat>;
|
||||
readDirectory(uri: string): Promise<[string, FileType][]>;
|
||||
}
|
||||
|
||||
export 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 isAbsolutePath(path: string) {
|
||||
return path.charCodeAt(0) === Slash;
|
||||
}
|
||||
|
||||
export function resolvePath(uri: Uri, path: string): Uri {
|
||||
if (isAbsolutePath(path)) {
|
||||
return uri.with({ path: normalizePath(path.split('/')) });
|
||||
}
|
||||
return joinPath(uri, 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(uri: Uri, ...paths: string[]): Uri {
|
||||
const parts = uri.path.split('/');
|
||||
for (let path of paths) {
|
||||
parts.push(...path.split('/'));
|
||||
}
|
||||
return uri.with({ path: normalizePath(parts) });
|
||||
}
|
||||
|
||||
@@ -257,7 +257,8 @@
|
||||
"dependencies": {
|
||||
"vscode-extension-telemetry": "0.4.3",
|
||||
"vscode-languageclient": "^7.0.0",
|
||||
"vscode-nls": "^5.0.0"
|
||||
"vscode-nls": "^5.0.0",
|
||||
"vscode-uri": "^3.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "14.x"
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IHTMLDataProvider, newHTMLDataProvider } from 'vscode-html-languageservice';
|
||||
import { RequestService } from './requests';
|
||||
import { CustomDataRequestService } from './htmlServer';
|
||||
|
||||
export function fetchHTMLDataProviders(dataPaths: string[], requestService: RequestService): Promise<IHTMLDataProvider[]> {
|
||||
export function fetchHTMLDataProviders(dataPaths: string[], requestService: CustomDataRequestService): Promise<IHTMLDataProvider[]> {
|
||||
const providers = dataPaths.map(async p => {
|
||||
try {
|
||||
const content = await requestService.getContent(p);
|
||||
|
||||
@@ -24,12 +24,16 @@ import { getFoldingRanges } from './modes/htmlFolding';
|
||||
import { fetchHTMLDataProviders } from './customData';
|
||||
import { getSelectionRanges } from './modes/selectionRanges';
|
||||
import { SemanticTokenProvider, newSemanticTokenProvider } from './modes/semanticTokens';
|
||||
import { RequestService, getRequestService } from './requests';
|
||||
import { FileSystemProvider, getFileSystemProvider } from './requests';
|
||||
|
||||
namespace CustomDataChangedNotification {
|
||||
export const type: NotificationType<string[]> = new NotificationType('html/customDataChanged');
|
||||
}
|
||||
|
||||
namespace CustomDataContent {
|
||||
export const type: RequestType<string, string, any> = new RequestType('html/customDataContent');
|
||||
}
|
||||
|
||||
namespace TagCloseRequest {
|
||||
export const type: RequestType<TextDocumentPositionParams, string | null, any> = new RequestType('html/tag');
|
||||
}
|
||||
@@ -47,8 +51,7 @@ namespace SemanticTokenLegendRequest {
|
||||
}
|
||||
|
||||
export interface RuntimeEnvironment {
|
||||
file?: RequestService;
|
||||
http?: RequestService
|
||||
fileFs?: FileSystemProvider;
|
||||
configureHttpRequests?(proxy: string, strictSSL: boolean): void;
|
||||
readonly timer: {
|
||||
setImmediate(callback: (...args: any[]) => void, ...args: any[]): Disposable;
|
||||
@@ -56,6 +59,12 @@ export interface RuntimeEnvironment {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export interface CustomDataRequestService {
|
||||
getContent(uri: string): Promise<string>;
|
||||
}
|
||||
|
||||
|
||||
export function startServer(connection: Connection, runtime: RuntimeEnvironment) {
|
||||
|
||||
// Create a text document manager.
|
||||
@@ -74,10 +83,11 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
|
||||
let workspaceFoldersSupport = false;
|
||||
let foldingRangeLimit = Number.MAX_VALUE;
|
||||
|
||||
const notReady = () => Promise.reject('Not Ready');
|
||||
let requestService: RequestService = { getContent: notReady, stat: notReady, readDirectory: notReady };
|
||||
|
||||
|
||||
const customDataRequestService : CustomDataRequestService = {
|
||||
getContent(uri: string) {
|
||||
return connection.sendRequest(CustomDataContent.type, uri);
|
||||
}
|
||||
};
|
||||
|
||||
let globalSettings: Settings = {};
|
||||
let documentSettings: { [key: string]: Thenable<Settings> } = {};
|
||||
@@ -113,17 +123,19 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
|
||||
}
|
||||
}
|
||||
|
||||
requestService = getRequestService(initializationOptions?.handledSchemas || ['file'], connection, runtime);
|
||||
const handledSchemas = initializationOptions?.handledSchemas as string[] ?? ['file'];
|
||||
|
||||
const fileSystemProvider = getFileSystemProvider(handledSchemas, connection, runtime);
|
||||
|
||||
const workspace = {
|
||||
get settings() { return globalSettings; },
|
||||
get folders() { return workspaceFolders; }
|
||||
};
|
||||
|
||||
languageModes = getLanguageModes(initializationOptions?.embeddedLanguages || { css: true, javascript: true }, workspace, params.capabilities, requestService);
|
||||
languageModes = getLanguageModes(initializationOptions?.embeddedLanguages || { css: true, javascript: true }, workspace, params.capabilities, fileSystemProvider);
|
||||
|
||||
const dataPaths: string[] = initializationOptions?.dataPaths || [];
|
||||
fetchHTMLDataProviders(dataPaths, requestService).then(dataProviders => {
|
||||
fetchHTMLDataProviders(dataPaths, customDataRequestService).then(dataProviders => {
|
||||
languageModes.updateDataProviders(dataProviders);
|
||||
});
|
||||
|
||||
@@ -567,7 +579,7 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
|
||||
});
|
||||
|
||||
connection.onNotification(CustomDataChangedNotification.type, dataPaths => {
|
||||
fetchHTMLDataProviders(dataPaths, requestService).then(dataProviders => {
|
||||
fetchHTMLDataProviders(dataPaths, customDataRequestService).then(dataProviders => {
|
||||
languageModes.updateDataProviders(dataProviders);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,7 +21,7 @@ import { getCSSMode } from './cssMode';
|
||||
import { getDocumentRegions, HTMLDocumentRegions } from './embeddedSupport';
|
||||
import { getHTMLMode } from './htmlMode';
|
||||
import { getJavaScriptMode } from './javascriptMode';
|
||||
import { RequestService } from '../requests';
|
||||
import { FileSystemProvider } from '../requests';
|
||||
|
||||
export {
|
||||
WorkspaceFolder, CompletionItem, CompletionList, CompletionItemKind, Definition, Diagnostic, DocumentHighlight, DocumentHighlightKind,
|
||||
@@ -97,7 +97,7 @@ export interface LanguageModeRange extends Range {
|
||||
attributeValue?: boolean;
|
||||
}
|
||||
|
||||
export function getLanguageModes(supportedLanguages: { [languageId: string]: boolean; }, workspace: Workspace, clientCapabilities: ClientCapabilities, requestService: RequestService): LanguageModes {
|
||||
export function getLanguageModes(supportedLanguages: { [languageId: string]: boolean; }, workspace: Workspace, clientCapabilities: ClientCapabilities, requestService: FileSystemProvider): LanguageModes {
|
||||
const htmlLanguageService = getHTMLLanguageService({ clientCapabilities, fileSystemProvider: requestService });
|
||||
const cssLanguageService = getCSSLanguageService({ clientCapabilities, fileSystemProvider: requestService });
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import { createConnection, Connection, Disposable } from 'vscode-languageserver/node';
|
||||
import { formatError } from '../utils/runner';
|
||||
import { RuntimeEnvironment, startServer } from '../htmlServer';
|
||||
import { getNodeFSRequestService } from './nodeFs';
|
||||
import { getNodeFileFS } from './nodeFs';
|
||||
|
||||
|
||||
// Create a connection for the server.
|
||||
@@ -30,7 +30,7 @@ const runtime: RuntimeEnvironment = {
|
||||
return { dispose: () => clearTimeout(handle) };
|
||||
}
|
||||
},
|
||||
file: getNodeFSRequestService()
|
||||
fileFs: getNodeFileFS()
|
||||
};
|
||||
|
||||
startServer(connection, runtime);
|
||||
|
||||
@@ -3,32 +3,19 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { RequestService, getScheme } from '../requests';
|
||||
import { FileSystemProvider, getScheme } from '../requests';
|
||||
import { URI as Uri } from 'vscode-uri';
|
||||
|
||||
import * as fs from 'fs';
|
||||
import { FileType } from 'vscode-css-languageservice';
|
||||
|
||||
export function getNodeFSRequestService(): RequestService {
|
||||
export function getNodeFileFS(): FileSystemProvider {
|
||||
function ensureFileUri(location: string) {
|
||||
if (getScheme(location) !== 'file') {
|
||||
throw new Error('fileRequestService can only handle file URLs');
|
||||
throw new Error('fileSystemProvider can only handle file URLs');
|
||||
}
|
||||
}
|
||||
return {
|
||||
getContent(location: string, encoding?: string) {
|
||||
ensureFileUri(location);
|
||||
return new Promise((c, e) => {
|
||||
const uri = Uri.parse(location);
|
||||
fs.readFile(uri.fsPath, encoding, (err, buf) => {
|
||||
if (err) {
|
||||
return e(err);
|
||||
}
|
||||
c(buf.toString());
|
||||
|
||||
});
|
||||
});
|
||||
},
|
||||
stat(location: string) {
|
||||
ensureFileUri(location);
|
||||
return new Promise((c, e) => {
|
||||
|
||||
@@ -7,9 +7,6 @@ import { URI } from 'vscode-uri';
|
||||
import { RequestType, Connection } from 'vscode-languageserver';
|
||||
import { RuntimeEnvironment } from './htmlServer';
|
||||
|
||||
export namespace FsContentRequest {
|
||||
export const type: RequestType<{ uri: string; encoding?: string; }, string, any> = new RequestType('fs/content');
|
||||
}
|
||||
export namespace FsStatRequest {
|
||||
export const type: RequestType<string, FileStat, any> = new RequestType('fs/stat');
|
||||
}
|
||||
@@ -56,45 +53,27 @@ export interface FileStat {
|
||||
size: number;
|
||||
}
|
||||
|
||||
export interface RequestService {
|
||||
getContent(uri: string, encoding?: string): Promise<string>;
|
||||
|
||||
export interface FileSystemProvider {
|
||||
stat(uri: string): Promise<FileStat>;
|
||||
readDirectory(uri: string): Promise<[string, FileType][]>;
|
||||
}
|
||||
|
||||
|
||||
export function getRequestService(handledSchemas: string[], connection: Connection, runtime: RuntimeEnvironment): RequestService {
|
||||
const builtInHandlers: { [protocol: string]: RequestService | undefined } = {};
|
||||
for (let protocol of handledSchemas) {
|
||||
if (protocol === 'file') {
|
||||
builtInHandlers[protocol] = runtime.file;
|
||||
} else if (protocol === 'http' || protocol === 'https') {
|
||||
builtInHandlers[protocol] = runtime.http;
|
||||
}
|
||||
}
|
||||
export function getFileSystemProvider(handledSchemas: string[], connection: Connection, runtime: RuntimeEnvironment): FileSystemProvider {
|
||||
const fileFs = runtime.fileFs && handledSchemas.indexOf('file') !== -1 ? runtime.fileFs : undefined;
|
||||
return {
|
||||
async stat(uri: string): Promise<FileStat> {
|
||||
const handler = builtInHandlers[getScheme(uri)];
|
||||
if (handler) {
|
||||
return handler.stat(uri);
|
||||
if (fileFs && uri.startsWith('file:')) {
|
||||
return fileFs.stat(uri);
|
||||
}
|
||||
const res = await connection.sendRequest(FsStatRequest.type, uri.toString());
|
||||
return res;
|
||||
},
|
||||
readDirectory(uri: string): Promise<[string, FileType][]> {
|
||||
const handler = builtInHandlers[getScheme(uri)];
|
||||
if (handler) {
|
||||
return handler.readDirectory(uri);
|
||||
if (fileFs && uri.startsWith('file:')) {
|
||||
return fileFs.readDirectory(uri);
|
||||
}
|
||||
return connection.sendRequest(FsReadDirRequest.type, uri.toString());
|
||||
},
|
||||
getContent(uri: string, encoding?: string): Promise<string> {
|
||||
const handler = builtInHandlers[getScheme(uri)];
|
||||
if (handler) {
|
||||
return handler.getContent(uri, encoding);
|
||||
}
|
||||
return connection.sendRequest(FsContentRequest.type, { uri: uri.toString(), encoding });
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import * as assert from 'assert';
|
||||
import * as path from 'path';
|
||||
import { URI } from 'vscode-uri';
|
||||
import { getLanguageModes, WorkspaceFolder, TextDocument, CompletionList, CompletionItemKind, ClientCapabilities, TextEdit } from '../modes/languageModes';
|
||||
import { getNodeFSRequestService } from '../node/nodeFs';
|
||||
import { getNodeFileFS } from '../node/nodeFs';
|
||||
import { getDocumentContext } from '../utils/documentContext';
|
||||
export interface ItemDescription {
|
||||
label: string;
|
||||
@@ -59,7 +59,7 @@ export async function testCompletionFor(value: string, expected: { count?: numbe
|
||||
let position = document.positionAt(offset);
|
||||
const context = getDocumentContext(uri, workspace.folders);
|
||||
|
||||
const languageModes = getLanguageModes({ css: true, javascript: true }, workspace, ClientCapabilities.LATEST, getNodeFSRequestService());
|
||||
const languageModes = getLanguageModes({ css: true, javascript: true }, workspace, ClientCapabilities.LATEST, getNodeFileFS());
|
||||
const mode = languageModes.getModeAtPosition(document, position)!;
|
||||
|
||||
let list = await mode.doComplete!(document, position, context);
|
||||
|
||||
@@ -8,7 +8,7 @@ import * as assert from 'assert';
|
||||
import { getFoldingRanges } from '../modes/htmlFolding';
|
||||
import { TextDocument, getLanguageModes } from '../modes/languageModes';
|
||||
import { ClientCapabilities } from 'vscode-css-languageservice';
|
||||
import { getNodeFSRequestService } from '../node/nodeFs';
|
||||
import { getNodeFileFS } from '../node/nodeFs';
|
||||
|
||||
interface ExpectedIndentRange {
|
||||
startLine: number;
|
||||
@@ -22,7 +22,7 @@ async function assertRanges(lines: string[], expected: ExpectedIndentRange[], me
|
||||
settings: {},
|
||||
folders: [{ name: 'foo', uri: 'test://foo' }]
|
||||
};
|
||||
const languageModes = getLanguageModes({ css: true, javascript: true }, workspace, ClientCapabilities.LATEST, getNodeFSRequestService());
|
||||
const languageModes = getLanguageModes({ css: true, javascript: true }, workspace, ClientCapabilities.LATEST, getNodeFileFS());
|
||||
const actual = await getFoldingRanges(languageModes, document, nRanges, null);
|
||||
|
||||
let actualRanges = [];
|
||||
|
||||
@@ -10,7 +10,7 @@ import * as assert from 'assert';
|
||||
import { getLanguageModes, TextDocument, Range, FormattingOptions, ClientCapabilities } from '../modes/languageModes';
|
||||
|
||||
import { format } from '../modes/formatting';
|
||||
import { getNodeFSRequestService } from '../node/nodeFs';
|
||||
import { getNodeFileFS } from '../node/nodeFs';
|
||||
|
||||
suite('HTML Embedded Formatting', () => {
|
||||
|
||||
@@ -19,7 +19,7 @@ suite('HTML Embedded Formatting', () => {
|
||||
settings: options,
|
||||
folders: [{ name: 'foo', uri: 'test://foo' }]
|
||||
};
|
||||
const languageModes = getLanguageModes({ css: true, javascript: true }, workspace, ClientCapabilities.LATEST, getNodeFSRequestService());
|
||||
const languageModes = getLanguageModes({ css: true, javascript: true }, workspace, ClientCapabilities.LATEST, getNodeFileFS());
|
||||
|
||||
let rangeStartOffset = value.indexOf('|');
|
||||
let rangeEndOffset;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { WorkspaceEdit, TextDocument, getLanguageModes, ClientCapabilities } from '../modes/languageModes';
|
||||
import { getNodeFSRequestService } from '../node/nodeFs';
|
||||
import { getNodeFileFS } from '../node/nodeFs';
|
||||
|
||||
|
||||
async function testRename(value: string, newName: string, expectedDocContent: string): Promise<void> {
|
||||
@@ -17,7 +17,7 @@ async function testRename(value: string, newName: string, expectedDocContent: st
|
||||
settings: {},
|
||||
folders: [{ name: 'foo', uri: 'test://foo' }]
|
||||
};
|
||||
const languageModes = getLanguageModes({ css: true, javascript: true }, workspace, ClientCapabilities.LATEST, getNodeFSRequestService());
|
||||
const languageModes = getLanguageModes({ css: true, javascript: true }, workspace, ClientCapabilities.LATEST, getNodeFileFS());
|
||||
const javascriptMode = languageModes.getMode('javascript')
|
||||
const position = document.positionAt(offset);
|
||||
|
||||
@@ -49,7 +49,7 @@ async function testNoRename(value: string, newName: string): Promise<void> {
|
||||
settings: {},
|
||||
folders: [{ name: 'foo', uri: 'test://foo' }]
|
||||
};
|
||||
const languageModes = getLanguageModes({ css: true, javascript: true }, workspace, ClientCapabilities.LATEST, getNodeFSRequestService());
|
||||
const languageModes = getLanguageModes({ css: true, javascript: true }, workspace, ClientCapabilities.LATEST, getNodeFileFS());
|
||||
const javascriptMode = languageModes.getMode('javascript')
|
||||
const position = document.positionAt(offset);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import 'mocha';
|
||||
import * as assert from 'assert';
|
||||
import { getLanguageModes, ClientCapabilities, TextDocument, SelectionRange } from '../modes/languageModes';
|
||||
import { getSelectionRanges } from '../modes/selectionRanges';
|
||||
import { getNodeFSRequestService } from '../node/nodeFs';
|
||||
import { getNodeFileFS } from '../node/nodeFs';
|
||||
|
||||
async function assertRanges(content: string, expected: (number | string)[][]): Promise<void> {
|
||||
let message = `${content} gives selection range:\n`;
|
||||
@@ -19,7 +19,7 @@ async function assertRanges(content: string, expected: (number | string)[][]): P
|
||||
settings: {},
|
||||
folders: [{ name: 'foo', uri: 'test://foo' }]
|
||||
};
|
||||
const languageModes = getLanguageModes({ css: true, javascript: true }, workspace, ClientCapabilities.LATEST, getNodeFSRequestService());
|
||||
const languageModes = getLanguageModes({ css: true, javascript: true }, workspace, ClientCapabilities.LATEST, getNodeFileFS());
|
||||
|
||||
const document = TextDocument.create('test://foo.html', 'html', 1, content);
|
||||
const actualRanges = await getSelectionRanges(languageModes, document, [document.positionAt(offset)]);
|
||||
|
||||
@@ -7,7 +7,7 @@ import 'mocha';
|
||||
import * as assert from 'assert';
|
||||
import { TextDocument, getLanguageModes, ClientCapabilities, Range, Position } from '../modes/languageModes';
|
||||
import { newSemanticTokenProvider } from '../modes/semanticTokens';
|
||||
import { getNodeFSRequestService } from '../node/nodeFs';
|
||||
import { getNodeFileFS } from '../node/nodeFs';
|
||||
|
||||
interface ExpectedToken {
|
||||
startLine: number;
|
||||
@@ -22,7 +22,7 @@ async function assertTokens(lines: string[], expected: ExpectedToken[], ranges?:
|
||||
settings: {},
|
||||
folders: [{ name: 'foo', uri: 'test://foo' }]
|
||||
};
|
||||
const languageModes = getLanguageModes({ css: true, javascript: true }, workspace, ClientCapabilities.LATEST, getNodeFSRequestService());
|
||||
const languageModes = getLanguageModes({ css: true, javascript: true }, workspace, ClientCapabilities.LATEST, getNodeFileFS());
|
||||
const semanticTokensProvider = newSemanticTokenProvider(languageModes);
|
||||
|
||||
const legend = semanticTokensProvider.legend;
|
||||
|
||||
@@ -83,6 +83,11 @@ 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@^3.0.2:
|
||||
version "3.0.2"
|
||||
resolved "https://registry.yarnpkg.com/vscode-uri/-/vscode-uri-3.0.2.tgz#ecfd1d066cb8ef4c3a208decdbab9a8c23d055d0"
|
||||
integrity sha512-jkjy6pjU1fxUvI51P+gCsxg1u2n8LSt0W6KrCNQceaziKzff74GoWmjVG46KieVzybO1sttPQmYfrwSHey7GUA==
|
||||
|
||||
yallist@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
|
||||
|
||||
Reference in New Issue
Block a user