registerHTMLLanguageService not available in AMD version. Fixes microsoft/monaco-editor#2525

This commit is contained in:
Martin Aeschlimann 2021-06-14 16:01:46 +02:00
parent 14d67a892e
commit d27f333f4b
No known key found for this signature in database
GPG key ID: 2609A01E695523E3
2 changed files with 61 additions and 71 deletions

54
monaco.d.ts vendored
View file

@ -21,7 +21,7 @@ declare namespace monaco.languages.html {
readonly wrapAttributes: 'auto' | 'force' | 'force-aligned' | 'force-expand-multiline'; readonly wrapAttributes: 'auto' | 'force' | 'force-aligned' | 'force-expand-multiline';
} }
export interface CompletionConfiguration { export interface CompletionConfiguration {
[providerId: string]: boolean; readonly [providerId: string]: boolean;
} }
export interface Options { export interface Options {
/** /**
@ -113,18 +113,18 @@ declare namespace monaco.languages.html {
*/ */
export function registerHTMLLanguageService( export function registerHTMLLanguageService(
languageId: string, languageId: string,
options: Options, options?: Options,
modeConfiguration: ModeConfiguration modeConfiguration?: ModeConfiguration
): LanguageServiceRegistration; ): LanguageServiceRegistration;
export interface HTMLDataConfiguration { export interface HTMLDataConfiguration {
/** /**
* Defines whether the standard HTML tags and attributes are shown * Defines whether the standard HTML tags and attributes are shown
*/ */
useDefaultDataProvider?: boolean; readonly useDefaultDataProvider?: boolean;
/** /**
* Provides a set of custom data providers. * Provides a set of custom data providers.
*/ */
dataProviders?: { readonly dataProviders?: {
[providerId: string]: HTMLDataV1; [providerId: string]: HTMLDataV1;
}; };
} }
@ -133,40 +133,40 @@ declare namespace monaco.languages.html {
* https://github.com/microsoft/vscode-html-languageservice/blob/main/docs/customData.md * https://github.com/microsoft/vscode-html-languageservice/blob/main/docs/customData.md
*/ */
export interface HTMLDataV1 { export interface HTMLDataV1 {
version: 1 | 1.1; readonly version: 1 | 1.1;
tags?: ITagData[]; readonly tags?: ITagData[];
globalAttributes?: IAttributeData[]; readonly globalAttributes?: IAttributeData[];
valueSets?: IValueSet[]; readonly valueSets?: IValueSet[];
} }
export interface IReference { export interface IReference {
name: string; readonly name: string;
url: string; readonly url: string;
} }
export interface ITagData { export interface ITagData {
name: string; readonly name: string;
description?: string | MarkupContent; readonly description?: string | MarkupContent;
attributes: IAttributeData[]; readonly attributes: IAttributeData[];
references?: IReference[]; readonly references?: IReference[];
} }
export interface IAttributeData { export interface IAttributeData {
name: string; readonly name: string;
description?: string | MarkupContent; readonly description?: string | MarkupContent;
valueSet?: string; readonly valueSet?: string;
values?: IValueData[]; readonly values?: IValueData[];
references?: IReference[]; readonly references?: IReference[];
} }
export interface IValueData { export interface IValueData {
name: string; readonly name: string;
description?: string | MarkupContent; readonly description?: string | MarkupContent;
references?: IReference[]; readonly references?: IReference[];
} }
export interface IValueSet { export interface IValueSet {
name: string; readonly name: string;
values: IValueData[]; readonly values: IValueData[];
} }
export interface MarkupContent { export interface MarkupContent {
kind: MarkupKind; readonly kind: MarkupKind;
value: string; readonly value: string;
} }
export type MarkupKind = 'plaintext' | 'markdown'; export type MarkupKind = 'plaintext' | 'markdown';
} }

View file

@ -22,7 +22,7 @@ export interface HTMLFormatConfiguration {
} }
export interface CompletionConfiguration { export interface CompletionConfiguration {
[providerId: string]: boolean; readonly [providerId: string]: boolean;
} }
export interface Options { export interface Options {
@ -167,23 +167,12 @@ const formatDefaults: Required<HTMLFormatConfiguration> = {
wrapAttributes: 'auto' wrapAttributes: 'auto'
}; };
const htmlOptionsDefault: Required<Options> = { const optionsDefault: Required<Options> = {
format: formatDefaults, format: formatDefaults,
suggest: { html5: true, angular1: true, ionic: true }, suggest: {},
data: { useDefaultDataProvider: true } data: { useDefaultDataProvider: true }
}; };
const handlebarOptionsDefault: Required<Options> = {
format: formatDefaults,
suggest: { html5: true },
data: { useDefaultDataProvider: true }
};
const razorOptionsDefault: Required<Options> = {
format: formatDefaults,
suggest: { html5: true, razor: true },
data: { useDefaultDataProvider: true }
};
function getConfigurationDefault(languageId: string): Required<ModeConfiguration> { function getConfigurationDefault(languageId: string): Required<ModeConfiguration> {
return { return {
@ -208,27 +197,28 @@ const razorLanguageId = 'razor';
export const htmlLanguageService = registerHTMLLanguageService( export const htmlLanguageService = registerHTMLLanguageService(
htmlLanguageId, htmlLanguageId,
htmlOptionsDefault, optionsDefault,
getConfigurationDefault(htmlLanguageId) getConfigurationDefault(htmlLanguageId)
); );
export const htmlDefaults = htmlLanguageService.defaults; export const htmlDefaults = htmlLanguageService.defaults;
export const handlebarLanguageService = registerHTMLLanguageService( export const handlebarLanguageService = registerHTMLLanguageService(
handlebarsLanguageId, handlebarsLanguageId,
handlebarOptionsDefault, optionsDefault,
getConfigurationDefault(handlebarsLanguageId) getConfigurationDefault(handlebarsLanguageId)
); );
export const handlebarDefaults = handlebarLanguageService.defaults; export const handlebarDefaults = handlebarLanguageService.defaults;
export const razorLanguageService = registerHTMLLanguageService( export const razorLanguageService = registerHTMLLanguageService(
razorLanguageId, razorLanguageId,
razorOptionsDefault, optionsDefault,
getConfigurationDefault(razorLanguageId) getConfigurationDefault(razorLanguageId)
); );
export const razorDefaults = razorLanguageService.defaults; export const razorDefaults = razorLanguageService.defaults;
// export to the global based API // export to the global based API
(<any>languages).html = { htmlDefaults, razorDefaults, handlebarDefaults }; (<any>languages).html = { htmlDefaults, razorDefaults, handlebarDefaults, htmlLanguageService, handlebarLanguageService, razorLanguageService, registerHTMLLanguageService };
// --- Registration to monaco editor --- // --- Registration to monaco editor ---
@ -249,8 +239,8 @@ export interface LanguageServiceRegistration extends IDisposable {
*/ */
export function registerHTMLLanguageService( export function registerHTMLLanguageService(
languageId: string, languageId: string,
options: Options, options: Options = optionsDefault,
modeConfiguration: ModeConfiguration modeConfiguration: ModeConfiguration = getConfigurationDefault(languageId)
): LanguageServiceRegistration { ): LanguageServiceRegistration {
const defaults = new LanguageServiceDefaultsImpl(languageId, options, modeConfiguration); const defaults = new LanguageServiceDefaultsImpl(languageId, options, modeConfiguration);
let mode: IDisposable | undefined; let mode: IDisposable | undefined;
@ -275,11 +265,11 @@ export interface HTMLDataConfiguration {
/** /**
* Defines whether the standard HTML tags and attributes are shown * Defines whether the standard HTML tags and attributes are shown
*/ */
useDefaultDataProvider?: boolean; readonly useDefaultDataProvider?: boolean;
/** /**
* Provides a set of custom data providers. * Provides a set of custom data providers.
*/ */
dataProviders?: { [providerId: string]: HTMLDataV1 }; readonly dataProviders?: { [providerId: string]: HTMLDataV1 };
} }
/** /**
@ -287,40 +277,40 @@ export interface HTMLDataConfiguration {
* https://github.com/microsoft/vscode-html-languageservice/blob/main/docs/customData.md * https://github.com/microsoft/vscode-html-languageservice/blob/main/docs/customData.md
*/ */
export interface HTMLDataV1 { export interface HTMLDataV1 {
version: 1 | 1.1; readonly version: 1 | 1.1;
tags?: ITagData[]; readonly tags?: ITagData[];
globalAttributes?: IAttributeData[]; readonly globalAttributes?: IAttributeData[];
valueSets?: IValueSet[]; readonly valueSets?: IValueSet[];
} }
export interface IReference { export interface IReference {
name: string; readonly name: string;
url: string; readonly url: string;
} }
export interface ITagData { export interface ITagData {
name: string; readonly name: string;
description?: string | MarkupContent; readonly description?: string | MarkupContent;
attributes: IAttributeData[]; readonly attributes: IAttributeData[];
references?: IReference[]; readonly references?: IReference[];
} }
export interface IAttributeData { export interface IAttributeData {
name: string; readonly name: string;
description?: string | MarkupContent; readonly description?: string | MarkupContent;
valueSet?: string; readonly valueSet?: string;
values?: IValueData[]; readonly values?: IValueData[];
references?: IReference[]; readonly references?: IReference[];
} }
export interface IValueData { export interface IValueData {
name: string; readonly name: string;
description?: string | MarkupContent; readonly description?: string | MarkupContent;
references?: IReference[]; readonly references?: IReference[];
} }
export interface IValueSet { export interface IValueSet {
name: string; readonly name: string;
values: IValueData[]; readonly values: IValueData[];
} }
export interface MarkupContent { export interface MarkupContent {
kind: MarkupKind; readonly kind: MarkupKind;
value: string; readonly value: string;
} }
export declare type MarkupKind = 'plaintext' | 'markdown'; export declare type MarkupKind = 'plaintext' | 'markdown';