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

Allow passing in a mime-type to setModelLanguage #164495

Merged
merged 1 commit into from Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/vs/editor/standalone/browser/standaloneEditor.ts
Expand Up @@ -33,6 +33,7 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { EditorCommand, ServicesAccessor } from 'vs/editor/browser/editorExtensions';
import { IMenuItem, MenuRegistry, MenuId } from 'vs/platform/actions/common/actions';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { PLAINTEXT_LANGUAGE_ID } from 'vs/editor/common/languages/modesRegistry';

/**
* Create a new editor under `domElement`.
Expand Down Expand Up @@ -235,9 +236,10 @@ export function createModel(value: string, language?: string, uri?: URI): ITextM
/**
* Change the language for a model.
*/
export function setModelLanguage(model: ITextModel, languageId: string): void {
export function setModelLanguage(model: ITextModel, mimeTypeOrLanguageId: string): void {
const languageService = StandaloneServices.get(ILanguageService);
const modelService = StandaloneServices.get(IModelService);
const languageId = languageService.getLanguageIdByMimeType(mimeTypeOrLanguageId) || mimeTypeOrLanguageId || PLAINTEXT_LANGUAGE_ID;
modelService.setMode(model, languageService.createById(languageId));
}

Expand Down
2 changes: 1 addition & 1 deletion src/vs/monaco.d.ts
Expand Up @@ -978,7 +978,7 @@ declare namespace monaco.editor {
/**
* Change the language for a model.
*/
export function setModelLanguage(model: ITextModel, languageId: string): void;
export function setModelLanguage(model: ITextModel, mimeTypeOrLanguageId: string): void;

/**
* Set the markers for a model.
Expand Down