[html] clean up request service: add CustomDataRequestService #135459

This commit is contained in:
Martin Aeschlimann
2021-11-29 11:25:04 +01:00
parent 414c15079b
commit 3d8b5674c7
19 changed files with 95 additions and 178 deletions

View File

@@ -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);
});
});