Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rely on IConfigurationService change event to update model options #13994

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions packages/monaco/src/browser/monaco-text-model-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ export interface MonacoEditorModelFactory {
export class MonacoTextModelService implements ITextModelService {
declare readonly _serviceBrand: undefined;

/**
* This component does some asynchronous work before being fully initialized.
*
* @deprecated since 1.25.0. Is instantly resolved.
*/
readonly ready: Promise<void> = Promise.resolve();

protected readonly _models = new ReferenceCollection<string, MonacoEditorModel>(
uri => this.loadModel(new URI(uri))
);
Expand Down Expand Up @@ -121,10 +114,6 @@ export class MonacoTextModelService implements ITextModelService {
await this.editorPreferences.ready;
const resource = await this.resourceProvider(uri);
const model = await (await this.createModel(resource)).load();
this.updateModel(model);
model.textEditorModel.onDidChangeLanguage(() => this.updateModel(model));
const disposable = this.editorPreferences.onPreferenceChanged(change => this.updateModel(model, change));
model.onDispose(() => disposable.dispose());
return model;
}

Expand Down Expand Up @@ -154,37 +143,6 @@ export class MonacoTextModelService implements ITextModelService {
return undefined;
}

protected updateModel(model: MonacoEditorModel, change?: EditorPreferenceChange): void {
if (!change) {
model.textEditorModel.updateOptions(this.getModelOptions(model));
} else if (change.affects(model.uri, model.languageId)) {
const modelOption = this.toModelOption(change.preferenceName);
if (modelOption) {
model.textEditorModel.updateOptions(this.getModelOptions(model));
}
}
}

/** @deprecated pass MonacoEditorModel instead */
protected getModelOptions(uri: string): ITextModelUpdateOptions;
protected getModelOptions(model: MonacoEditorModel): ITextModelUpdateOptions;
protected getModelOptions(arg: string | MonacoEditorModel): ITextModelUpdateOptions {
const uri = typeof arg === 'string' ? arg : arg.uri;
const overrideIdentifier = typeof arg === 'string' ? undefined : arg.languageId;
return {
tabSize: this.editorPreferences.get({ preferenceName: 'editor.tabSize', overrideIdentifier }, undefined, uri),
// @monaco-uplift: when available, switch to 'editor.indentSize' preference.
indentSize: this.editorPreferences.get({ preferenceName: 'editor.tabSize', overrideIdentifier }, undefined, uri),
insertSpaces: this.editorPreferences.get({ preferenceName: 'editor.insertSpaces', overrideIdentifier }, undefined, uri),
bracketColorizationOptions: {
enabled: this.editorPreferences.get({ preferenceName: 'editor.bracketPairColorization.enabled', overrideIdentifier }, undefined, uri),
independentColorPoolPerBracketType: this.editorPreferences.get(
{ preferenceName: 'editor.bracketPairColorization.independentColorPoolPerBracketType', overrideIdentifier }, undefined, uri),
},
trimAutoWhitespace: this.editorPreferences.get({ preferenceName: 'editor.trimAutoWhitespace', overrideIdentifier }, undefined, uri),
};
}

registerTextModelContentProvider(scheme: string, provider: ITextModelContentProvider): IDisposable {
return {
dispose(): void {
Expand Down
Loading