mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 16:15:41 +01:00
implemented setModeConfiguration for typescriptDefaults and javascriptDefaults
This commit is contained in:
parent
212670ceb4
commit
4532feefb7
2 changed files with 222 additions and 35 deletions
|
|
@ -226,6 +226,73 @@ interface OutputFile {
|
||||||
text: string;
|
text: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ModeConfiguration {
|
||||||
|
/**
|
||||||
|
* Defines whether the built-in completionItemProvider is enabled.
|
||||||
|
*/
|
||||||
|
readonly completionItems?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines whether the built-in hoverProvider is enabled.
|
||||||
|
*/
|
||||||
|
readonly hovers?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines whether the built-in documentSymbolProvider is enabled.
|
||||||
|
*/
|
||||||
|
readonly documentSymbols?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines whether the built-in definitions provider is enabled.
|
||||||
|
*/
|
||||||
|
readonly definitions?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines whether the built-in references provider is enabled.
|
||||||
|
*/
|
||||||
|
readonly references?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines whether the built-in references provider is enabled.
|
||||||
|
*/
|
||||||
|
readonly documentHighlights?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines whether the built-in rename provider is enabled.
|
||||||
|
*/
|
||||||
|
readonly rename?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines whether the built-in diagnostic provider is enabled.
|
||||||
|
*/
|
||||||
|
readonly diagnostics?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines whether the built-in document formatting range edit provider is enabled.
|
||||||
|
*/
|
||||||
|
readonly documentRangeFormattingEdits?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines whether the built-in signature help provider is enabled.
|
||||||
|
*/
|
||||||
|
readonly signatureHelp?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines whether the built-in onType formatting edit provider is enabled.
|
||||||
|
*/
|
||||||
|
readonly onTypeFormattingEdits?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines whether the built-in code actions provider is enabled.
|
||||||
|
*/
|
||||||
|
readonly codeActions?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines whether the built-in inlay hints provider is enabled.
|
||||||
|
*/
|
||||||
|
readonly inlayHints?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export interface LanguageServiceDefaults {
|
export interface LanguageServiceDefaults {
|
||||||
/**
|
/**
|
||||||
* Event fired when compiler options or diagnostics options are changed.
|
* Event fired when compiler options or diagnostics options are changed.
|
||||||
|
|
@ -241,6 +308,9 @@ export interface LanguageServiceDefaults {
|
||||||
|
|
||||||
readonly inlayHintsOptions: InlayHintsOptions;
|
readonly inlayHintsOptions: InlayHintsOptions;
|
||||||
|
|
||||||
|
readonly modeConfiguration: ModeConfiguration;
|
||||||
|
setModeConfiguration(modeConfiguration: ModeConfiguration): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current extra libs registered with the language service.
|
* Get the current extra libs registered with the language service.
|
||||||
*/
|
*/
|
||||||
|
|
@ -491,12 +561,14 @@ class LanguageServiceDefaultsImpl implements LanguageServiceDefaults {
|
||||||
private _workerOptions!: WorkerOptions;
|
private _workerOptions!: WorkerOptions;
|
||||||
private _onDidExtraLibsChangeTimeout: number;
|
private _onDidExtraLibsChangeTimeout: number;
|
||||||
private _inlayHintsOptions!: InlayHintsOptions;
|
private _inlayHintsOptions!: InlayHintsOptions;
|
||||||
|
private _modeConfiguration!: ModeConfiguration;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
compilerOptions: CompilerOptions,
|
compilerOptions: CompilerOptions,
|
||||||
diagnosticsOptions: DiagnosticsOptions,
|
diagnosticsOptions: DiagnosticsOptions,
|
||||||
workerOptions: WorkerOptions,
|
workerOptions: WorkerOptions,
|
||||||
inlayHintsOptions: InlayHintsOptions
|
inlayHintsOptions: InlayHintsOptions,
|
||||||
|
modeConfiguration: ModeConfiguration
|
||||||
) {
|
) {
|
||||||
this._extraLibs = Object.create(null);
|
this._extraLibs = Object.create(null);
|
||||||
this._removedExtraLibs = Object.create(null);
|
this._removedExtraLibs = Object.create(null);
|
||||||
|
|
@ -505,6 +577,7 @@ class LanguageServiceDefaultsImpl implements LanguageServiceDefaults {
|
||||||
this.setDiagnosticsOptions(diagnosticsOptions);
|
this.setDiagnosticsOptions(diagnosticsOptions);
|
||||||
this.setWorkerOptions(workerOptions);
|
this.setWorkerOptions(workerOptions);
|
||||||
this.setInlayHintsOptions(inlayHintsOptions);
|
this.setInlayHintsOptions(inlayHintsOptions);
|
||||||
|
this.setModeConfiguration(modeConfiguration);
|
||||||
this._onDidExtraLibsChangeTimeout = -1;
|
this._onDidExtraLibsChangeTimeout = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -516,6 +589,10 @@ class LanguageServiceDefaultsImpl implements LanguageServiceDefaults {
|
||||||
return this._onDidExtraLibsChange.event;
|
return this._onDidExtraLibsChange.event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get modeConfiguration(): ModeConfiguration {
|
||||||
|
return this._modeConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
get workerOptions(): WorkerOptions {
|
get workerOptions(): WorkerOptions {
|
||||||
return this._workerOptions;
|
return this._workerOptions;
|
||||||
}
|
}
|
||||||
|
|
@ -650,22 +727,45 @@ class LanguageServiceDefaultsImpl implements LanguageServiceDefaults {
|
||||||
getEagerModelSync() {
|
getEagerModelSync() {
|
||||||
return this._eagerModelSync;
|
return this._eagerModelSync;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setModeConfiguration(modeConfiguration: ModeConfiguration): void {
|
||||||
|
this._modeConfiguration = modeConfiguration || Object.create(null);
|
||||||
|
this._onDidChange.fire(undefined);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const typescriptVersion: string = tsversion;
|
export const typescriptVersion: string = tsversion;
|
||||||
|
|
||||||
|
const modeConfigurationDefault: Required<ModeConfiguration> = {
|
||||||
|
completionItems: true,
|
||||||
|
hovers: true,
|
||||||
|
documentSymbols: true,
|
||||||
|
definitions: true,
|
||||||
|
references: true,
|
||||||
|
documentHighlights: true,
|
||||||
|
rename: true,
|
||||||
|
diagnostics: true,
|
||||||
|
documentRangeFormattingEdits: true,
|
||||||
|
signatureHelp: true,
|
||||||
|
onTypeFormattingEdits: true,
|
||||||
|
codeActions: true,
|
||||||
|
inlayHints: true
|
||||||
|
};
|
||||||
|
|
||||||
export const typescriptDefaults: LanguageServiceDefaults = new LanguageServiceDefaultsImpl(
|
export const typescriptDefaults: LanguageServiceDefaults = new LanguageServiceDefaultsImpl(
|
||||||
{ allowNonTsExtensions: true, target: ScriptTarget.Latest },
|
{ allowNonTsExtensions: true, target: ScriptTarget.Latest },
|
||||||
{ noSemanticValidation: false, noSyntaxValidation: false, onlyVisible: false },
|
{ noSemanticValidation: false, noSyntaxValidation: false, onlyVisible: false },
|
||||||
{},
|
{},
|
||||||
{}
|
{},
|
||||||
|
modeConfigurationDefault
|
||||||
);
|
);
|
||||||
|
|
||||||
export const javascriptDefaults: LanguageServiceDefaults = new LanguageServiceDefaultsImpl(
|
export const javascriptDefaults: LanguageServiceDefaults = new LanguageServiceDefaultsImpl(
|
||||||
{ allowNonTsExtensions: true, allowJs: true, target: ScriptTarget.Latest },
|
{ allowNonTsExtensions: true, allowJs: true, target: ScriptTarget.Latest },
|
||||||
{ noSemanticValidation: true, noSyntaxValidation: false, onlyVisible: false },
|
{ noSemanticValidation: true, noSyntaxValidation: false, onlyVisible: false },
|
||||||
{},
|
{},
|
||||||
{}
|
{},
|
||||||
|
modeConfigurationDefault
|
||||||
);
|
);
|
||||||
|
|
||||||
export const getTypeScriptWorker = (): Promise<(...uris: Uri[]) => Promise<TypeScriptWorker>> => {
|
export const getTypeScriptWorker = (): Promise<(...uris: Uri[]) => Promise<TypeScriptWorker>> => {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import { WorkerManager } from './workerManager';
|
||||||
import type { TypeScriptWorker } from './tsWorker';
|
import type { TypeScriptWorker } from './tsWorker';
|
||||||
import { LanguageServiceDefaults } from './monaco.contribution';
|
import { LanguageServiceDefaults } from './monaco.contribution';
|
||||||
import * as languageFeatures from './languageFeatures';
|
import * as languageFeatures from './languageFeatures';
|
||||||
import { languages, Uri } from '../../fillers/monaco-editor-core';
|
import { languages, IDisposable, Uri } from '../../fillers/monaco-editor-core';
|
||||||
|
|
||||||
let javaScriptWorker: (...uris: Uri[]) => Promise<TypeScriptWorker>;
|
let javaScriptWorker: (...uris: Uri[]) => Promise<TypeScriptWorker>;
|
||||||
let typeScriptWorker: (...uris: Uri[]) => Promise<TypeScriptWorker>;
|
let typeScriptWorker: (...uris: Uri[]) => Promise<TypeScriptWorker>;
|
||||||
|
|
@ -44,46 +44,133 @@ function setupMode(
|
||||||
defaults: LanguageServiceDefaults,
|
defaults: LanguageServiceDefaults,
|
||||||
modeId: string
|
modeId: string
|
||||||
): (...uris: Uri[]) => Promise<TypeScriptWorker> {
|
): (...uris: Uri[]) => Promise<TypeScriptWorker> {
|
||||||
|
const disposables: IDisposable[] = [];
|
||||||
|
const providers: IDisposable[] = [];
|
||||||
|
|
||||||
const client = new WorkerManager(modeId, defaults);
|
const client = new WorkerManager(modeId, defaults);
|
||||||
|
disposables.push(client);
|
||||||
|
|
||||||
const worker = (...uris: Uri[]): Promise<TypeScriptWorker> => {
|
const worker = (...uris: Uri[]): Promise<TypeScriptWorker> => {
|
||||||
return client.getLanguageServiceWorker(...uris);
|
return client.getLanguageServiceWorker(...uris);
|
||||||
};
|
};
|
||||||
|
|
||||||
const libFiles = new languageFeatures.LibFiles(worker);
|
const libFiles = new languageFeatures.LibFiles(worker);
|
||||||
|
|
||||||
languages.registerCompletionItemProvider(modeId, new languageFeatures.SuggestAdapter(worker));
|
function registerProviders(): void {
|
||||||
languages.registerSignatureHelpProvider(
|
const { modeConfiguration } = defaults;
|
||||||
modeId,
|
|
||||||
new languageFeatures.SignatureHelpAdapter(worker)
|
disposeAll(providers);
|
||||||
);
|
|
||||||
languages.registerHoverProvider(modeId, new languageFeatures.QuickInfoAdapter(worker));
|
if (modeConfiguration.completionItems) {
|
||||||
languages.registerDocumentHighlightProvider(
|
providers.push(
|
||||||
modeId,
|
languages.registerCompletionItemProvider(
|
||||||
new languageFeatures.OccurrencesAdapter(worker)
|
modeId,
|
||||||
);
|
new languageFeatures.SuggestAdapter(worker)
|
||||||
languages.registerDefinitionProvider(
|
)
|
||||||
modeId,
|
);
|
||||||
new languageFeatures.DefinitionAdapter(libFiles, worker)
|
}
|
||||||
);
|
if (modeConfiguration.signatureHelp) {
|
||||||
languages.registerReferenceProvider(
|
providers.push(
|
||||||
modeId,
|
languages.registerSignatureHelpProvider(
|
||||||
new languageFeatures.ReferenceAdapter(libFiles, worker)
|
modeId,
|
||||||
);
|
new languageFeatures.SignatureHelpAdapter(worker)
|
||||||
languages.registerDocumentSymbolProvider(modeId, new languageFeatures.OutlineAdapter(worker));
|
)
|
||||||
languages.registerDocumentRangeFormattingEditProvider(
|
);
|
||||||
modeId,
|
}
|
||||||
new languageFeatures.FormatAdapter(worker)
|
if (modeConfiguration.hovers) {
|
||||||
);
|
providers.push(
|
||||||
languages.registerOnTypeFormattingEditProvider(
|
languages.registerHoverProvider(modeId, new languageFeatures.QuickInfoAdapter(worker))
|
||||||
modeId,
|
);
|
||||||
new languageFeatures.FormatOnTypeAdapter(worker)
|
}
|
||||||
);
|
if (modeConfiguration.documentHighlights) {
|
||||||
languages.registerCodeActionProvider(modeId, new languageFeatures.CodeActionAdaptor(worker));
|
providers.push(
|
||||||
languages.registerRenameProvider(modeId, new languageFeatures.RenameAdapter(libFiles, worker));
|
languages.registerDocumentHighlightProvider(
|
||||||
languages.registerInlayHintsProvider(modeId, new languageFeatures.InlayHintsAdapter(worker));
|
modeId,
|
||||||
new languageFeatures.DiagnosticsAdapter(libFiles, defaults, modeId, worker);
|
new languageFeatures.OccurrencesAdapter(worker)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (modeConfiguration.definitions) {
|
||||||
|
providers.push(
|
||||||
|
languages.registerDefinitionProvider(
|
||||||
|
modeId,
|
||||||
|
new languageFeatures.DefinitionAdapter(libFiles, worker)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (modeConfiguration.references) {
|
||||||
|
providers.push(
|
||||||
|
languages.registerReferenceProvider(
|
||||||
|
modeId,
|
||||||
|
new languageFeatures.ReferenceAdapter(libFiles, worker)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (modeConfiguration.documentSymbols) {
|
||||||
|
providers.push(
|
||||||
|
languages.registerDocumentSymbolProvider(
|
||||||
|
modeId,
|
||||||
|
new languageFeatures.OutlineAdapter(worker)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (modeConfiguration.rename) {
|
||||||
|
providers.push(
|
||||||
|
languages.registerRenameProvider(
|
||||||
|
modeId,
|
||||||
|
new languageFeatures.RenameAdapter(libFiles, worker)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (modeConfiguration.documentRangeFormattingEdits) {
|
||||||
|
providers.push(
|
||||||
|
languages.registerDocumentRangeFormattingEditProvider(
|
||||||
|
modeId,
|
||||||
|
new languageFeatures.FormatAdapter(worker)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (modeConfiguration.onTypeFormattingEdits) {
|
||||||
|
providers.push(
|
||||||
|
languages.registerOnTypeFormattingEditProvider(
|
||||||
|
modeId,
|
||||||
|
new languageFeatures.FormatOnTypeAdapter(worker)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (modeConfiguration.codeActions) {
|
||||||
|
providers.push(
|
||||||
|
languages.registerCodeActionProvider(modeId, new languageFeatures.CodeActionAdaptor(worker))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (modeConfiguration.inlayHints) {
|
||||||
|
providers.push(
|
||||||
|
languages.registerInlayHintsProvider(modeId, new languageFeatures.InlayHintsAdapter(worker))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (modeConfiguration.diagnostics) {
|
||||||
|
providers.push(new languageFeatures.DiagnosticsAdapter(libFiles, defaults, modeId, worker));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
registerProviders();
|
||||||
|
|
||||||
|
disposables.push(asDisposable(providers));
|
||||||
|
|
||||||
|
//return asDisposable(disposables);
|
||||||
|
|
||||||
return worker;
|
return worker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function asDisposable(disposables: IDisposable[]): IDisposable {
|
||||||
|
return { dispose: () => disposeAll(disposables) };
|
||||||
|
}
|
||||||
|
|
||||||
|
function disposeAll(disposables: IDisposable[]) {
|
||||||
|
while (disposables.length) {
|
||||||
|
disposables.pop()!.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export { WorkerManager } from './workerManager';
|
export { WorkerManager } from './workerManager';
|
||||||
export * from './languageFeatures';
|
export * from './languageFeatures';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue