mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +00:00
Split ILanguageService.create
into createById
and createByMimeType
This commit is contained in:
parent
5df48870b7
commit
cb3bc8a60e
|
@ -38,19 +38,28 @@ export interface ILanguageService {
|
|||
isRegisteredLanguageId(languageId: string): boolean;
|
||||
getRegisteredLanguageIds(): string[];
|
||||
getRegisteredLanguageNames(): string[];
|
||||
getExtensions(alias: string): string[];
|
||||
getFilenames(alias: string): string[];
|
||||
getExtensions(alias: string): string[]; // TODO
|
||||
getFilenames(alias: string): string[]; // TODO
|
||||
getMimeTypeForLanguageId(languageId: string): string | null;
|
||||
getLanguageName(languageId: string): string | null;
|
||||
getLanguageIdForLanguageName(languageName: string): string | null;
|
||||
getLanguageIdForMimeType(mimeType: string): string | null;
|
||||
getLanguageIdForLanguageName(languageName: string): string | null; // TODO
|
||||
getLanguageIdForMimeType(mimeType: string | null | undefined): string | null;
|
||||
getLanguageIdByFilepathOrFirstLine(resource: URI, firstLine?: string): string | null;
|
||||
validateLanguageId(languageId: string): string | null;
|
||||
getConfigurationFiles(languageId: string): URI[];
|
||||
|
||||
// --- instantiation
|
||||
create(commaSeparatedMimetypesOrCommaSeparatedIds: string | undefined): ILanguageSelection;
|
||||
createByLanguageName(languageName: string): ILanguageSelection;
|
||||
/**
|
||||
* Will fall back to 'plaintext' if `languageId` is unknown.
|
||||
*/
|
||||
createById(languageId: string | null | undefined): ILanguageSelection;
|
||||
/**
|
||||
* Will fall back to 'plaintext' if `mimeType` is unknown.
|
||||
*/
|
||||
createByMimeType(mimeType: string | null | undefined): ILanguageSelection;
|
||||
/**
|
||||
* Will fall back to 'plaintext' if the `languageId` cannot be determined.
|
||||
*/
|
||||
createByFilepathOrFirstLine(resource: URI | null, firstLine?: string): ILanguageSelection;
|
||||
|
||||
triggerMode(commaSeparatedMimetypesOrCommaSeparatedIds: string): void;
|
||||
|
|
|
@ -11,6 +11,7 @@ import { LanguagesRegistry } from 'vs/editor/common/services/languagesRegistry';
|
|||
import { ILanguageSelection, ILanguageService } from 'vs/editor/common/services/languageService';
|
||||
import { firstOrDefault } from 'vs/base/common/arrays';
|
||||
import { ILanguageIdCodec } from 'vs/editor/common/modes';
|
||||
import { PLAINTEXT_MODE_ID } from 'vs/editor/common/modes/modesRegistry';
|
||||
|
||||
class LanguageSelection implements ILanguageSelection {
|
||||
|
||||
|
@ -76,7 +77,7 @@ export class LanguageService extends Disposable implements ILanguageService {
|
|||
super.dispose();
|
||||
}
|
||||
|
||||
public isRegisteredLanguageId(languageId: string): boolean {
|
||||
public isRegisteredLanguageId(languageId: string | null | undefined): boolean {
|
||||
return this._registry.isRegisteredLanguageId(languageId);
|
||||
}
|
||||
|
||||
|
@ -108,7 +109,7 @@ export class LanguageService extends Disposable implements ILanguageService {
|
|||
return this._registry.getLanguageIdForLanguageName(alias);
|
||||
}
|
||||
|
||||
public getLanguageIdForMimeType(mimeType: string): string | null {
|
||||
public getLanguageIdForMimeType(mimeType: string | null | undefined): string | null {
|
||||
return this._registry.getLanguageIdForMimeType(mimeType);
|
||||
}
|
||||
|
||||
|
@ -132,16 +133,17 @@ export class LanguageService extends Disposable implements ILanguageService {
|
|||
|
||||
// --- instantiation
|
||||
|
||||
public create(commaSeparatedMimetypesOrCommaSeparatedIds: string | undefined): ILanguageSelection {
|
||||
public createById(languageId: string | null | undefined): ILanguageSelection {
|
||||
return new LanguageSelection(this.onLanguagesMaybeChanged, () => {
|
||||
const languageId = this.getModeId(commaSeparatedMimetypesOrCommaSeparatedIds);
|
||||
return this._createModeAndGetLanguageIdentifier(languageId);
|
||||
const validLanguageId = (languageId && this.isRegisteredLanguageId(languageId) ? languageId : PLAINTEXT_MODE_ID);
|
||||
this._getOrCreateMode(validLanguageId);
|
||||
return validLanguageId;
|
||||
});
|
||||
}
|
||||
|
||||
public createByLanguageName(languageName: string): ILanguageSelection {
|
||||
public createByMimeType(mimeType: string | null | undefined): ILanguageSelection {
|
||||
return new LanguageSelection(this.onLanguagesMaybeChanged, () => {
|
||||
const languageId = this._getModeIdByLanguageName(languageName);
|
||||
const languageId = this.getLanguageIdForMimeType(mimeType);
|
||||
return this._createModeAndGetLanguageIdentifier(languageId);
|
||||
});
|
||||
}
|
||||
|
@ -153,7 +155,7 @@ export class LanguageService extends Disposable implements ILanguageService {
|
|||
});
|
||||
}
|
||||
|
||||
private _createModeAndGetLanguageIdentifier(languageId: string | null): string {
|
||||
private _createModeAndGetLanguageIdentifier(languageId: string | null | undefined): string {
|
||||
// Fall back to plain text if no mode was found
|
||||
const validLanguageId = this.validateLanguageId(languageId || 'plaintext') || NULL_MODE_ID;
|
||||
this._getOrCreateMode(validLanguageId);
|
||||
|
@ -166,10 +168,6 @@ export class LanguageService extends Disposable implements ILanguageService {
|
|||
this._getOrCreateMode(languageId || 'plaintext');
|
||||
}
|
||||
|
||||
private _getModeIdByLanguageName(languageName: string): string | null {
|
||||
return this._registry.getModeIdFromLanguageName(languageName);
|
||||
}
|
||||
|
||||
private _getOrCreateMode(languageId: string): void {
|
||||
if (!this._encounteredLanguages.has(languageId)) {
|
||||
this._encounteredLanguages.add(languageId);
|
||||
|
|
|
@ -257,7 +257,10 @@ export class LanguagesRegistry extends Disposable {
|
|||
}
|
||||
}
|
||||
|
||||
public isRegisteredLanguageId(languageId: string): boolean {
|
||||
public isRegisteredLanguageId(languageId: string | null | undefined): boolean {
|
||||
if (!languageId) {
|
||||
return false;
|
||||
}
|
||||
return hasOwnProperty.call(this._languages, languageId);
|
||||
}
|
||||
|
||||
|
@ -283,7 +286,10 @@ export class LanguagesRegistry extends Disposable {
|
|||
return this._lowercaseNameMap[languageNameLower];
|
||||
}
|
||||
|
||||
public getLanguageIdForMimeType(mimeType: string): string | null {
|
||||
public getLanguageIdForMimeType(mimeType: string | null | undefined): string | null {
|
||||
if (!mimeType) {
|
||||
return null;
|
||||
}
|
||||
if (hasOwnProperty.call(this._mimeTypesMap, mimeType)) {
|
||||
return this._mimeTypesMap[mimeType];
|
||||
}
|
||||
|
@ -326,7 +332,7 @@ export class LanguagesRegistry extends Disposable {
|
|||
);
|
||||
}
|
||||
|
||||
public validateLanguageId(languageId: string | null): string | null {
|
||||
public validateLanguageId(languageId: string | null | undefined): string | null {
|
||||
if (!languageId || languageId === NULL_MODE_ID) {
|
||||
return NULL_MODE_ID;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ import { IModelService } from 'vs/editor/common/services/modelService';
|
|||
import { ILanguageSelection, ILanguageService } from 'vs/editor/common/services/languageService';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { StandaloneCodeEditorServiceImpl } from 'vs/editor/standalone/browser/standaloneCodeServiceImpl';
|
||||
import { Mimes } from 'vs/base/common/mime';
|
||||
import { PLAINTEXT_MODE_ID } from 'vs/editor/common/modes/modesRegistry';
|
||||
|
||||
/**
|
||||
* Description of an action contribution
|
||||
|
@ -437,7 +437,8 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon
|
|||
|
||||
let model: ITextModel | null;
|
||||
if (typeof _model === 'undefined') {
|
||||
model = createTextModel(modelService, languageService, options.value || '', options.language || Mimes.text, undefined);
|
||||
const languageId = languageService.getLanguageIdForMimeType(options.language) || options.language || PLAINTEXT_MODE_ID;
|
||||
model = createTextModel(modelService, languageService, options.value || '', languageId, undefined);
|
||||
this._ownsModel = true;
|
||||
} else {
|
||||
model = _model;
|
||||
|
@ -573,9 +574,9 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon
|
|||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function createTextModel(modelService: IModelService, languageService: ILanguageService, value: string, language: string | undefined, uri: URI | undefined): ITextModel {
|
||||
export function createTextModel(modelService: IModelService, languageService: ILanguageService, value: string, languageId: string | undefined, uri: URI | undefined): ITextModel {
|
||||
value = value || '';
|
||||
if (!language) {
|
||||
if (!languageId) {
|
||||
const firstLF = value.indexOf('\n');
|
||||
let firstLine = value;
|
||||
if (firstLF !== -1) {
|
||||
|
@ -583,7 +584,7 @@ export function createTextModel(modelService: IModelService, languageService: IL
|
|||
}
|
||||
return doCreateModel(modelService, value, languageService.createByFilepathOrFirstLine(uri || null, firstLine), uri);
|
||||
}
|
||||
return doCreateModel(modelService, value, languageService.create(language), uri);
|
||||
return doCreateModel(modelService, value, languageService.createById(languageId), uri);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -148,11 +148,13 @@ export function createDiffNavigator(diffEditor: IStandaloneDiffEditor, opts?: ID
|
|||
* You can specify the language that should be set for this model or let the language be inferred from the `uri`.
|
||||
*/
|
||||
export function createModel(value: string, language?: string, uri?: URI): ITextModel {
|
||||
const languageService = StaticServices.languageService.get();
|
||||
const languageId = languageService.getLanguageIdForMimeType(language) || language;
|
||||
return createTextModel(
|
||||
StaticServices.modelService.get(),
|
||||
StaticServices.languageService.get(),
|
||||
languageService,
|
||||
value,
|
||||
language,
|
||||
languageId,
|
||||
uri
|
||||
);
|
||||
}
|
||||
|
@ -161,7 +163,7 @@ export function createModel(value: string, language?: string, uri?: URI): ITextM
|
|||
* Change the language for a model.
|
||||
*/
|
||||
export function setModelLanguage(model: ITextModel, languageId: string): void {
|
||||
StaticServices.modelService.get().setMode(model, StaticServices.languageService.get().create(languageId));
|
||||
StaticServices.modelService.get().setMode(model, StaticServices.languageService.get().createById(languageId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -469,7 +469,7 @@ suite('ModelSemanticColoring', () => {
|
|||
}
|
||||
}));
|
||||
|
||||
const textModel = disposables.add(modelService.createModel('Hello world', languageService.create('testMode')));
|
||||
const textModel = disposables.add(modelService.createModel('Hello world', languageService.createById('testMode')));
|
||||
|
||||
// wait for the provider to be called
|
||||
await inFirstCall.wait();
|
||||
|
@ -532,7 +532,7 @@ suite('ModelSemanticColoring', () => {
|
|||
return result;
|
||||
}
|
||||
|
||||
const textModel = modelService.createModel('Hello world 2', languageService.create('testMode2'));
|
||||
const textModel = modelService.createModel('Hello world 2', languageService.createById('testMode2'));
|
||||
try {
|
||||
let result = await getDocumentSemanticTokens(textModel, null, null, CancellationToken.None);
|
||||
assert.ok(result, `We should have tokens (1)`);
|
||||
|
|
|
@ -57,7 +57,7 @@ export class MainThreadLanguages implements MainThreadLanguagesShape {
|
|||
const uri = URI.revive(resource);
|
||||
const ref = await this._resolverService.createModelReference(uri);
|
||||
try {
|
||||
this._modelService.setMode(ref.object.textEditorModel, this._languageService.create(languageId));
|
||||
this._modelService.setMode(ref.object.textEditorModel, this._languageService.createById(languageId));
|
||||
} finally {
|
||||
ref.dispose();
|
||||
}
|
||||
|
|
|
@ -1207,12 +1207,13 @@ export class ChangeModeAction extends Action {
|
|||
languageId = detectedLanguage;
|
||||
}
|
||||
if (languageId) {
|
||||
languageSelection = this.languageService.create(languageId);
|
||||
languageSelection = this.languageService.createById(languageId);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
languageSelection = this.languageService.createByLanguageName(pick.label);
|
||||
const languageId = this.languageService.getLanguageIdForLanguageName(pick.label.toLowerCase());
|
||||
languageSelection = this.languageService.createById(languageId);
|
||||
|
||||
if (resource) {
|
||||
// fire and forget to not slow things down
|
||||
|
|
|
@ -203,7 +203,7 @@ export class TextResourceEditor extends AbstractTextResourceEditor {
|
|||
|
||||
// Finally apply languageId to model if specified
|
||||
if (candidateLanguageId !== PLAINTEXT_MODE_ID) {
|
||||
this.modelService.setMode(textModel, this.languageService.create(candidateLanguageId));
|
||||
this.modelService.setMode(textModel, this.languageService.createById(candidateLanguageId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ export class BaseTextEditorModel extends EditorModel implements ITextEditorModel
|
|||
return;
|
||||
}
|
||||
|
||||
this.modelService.setMode(this.textEditorModel, this.languageService.create(mode));
|
||||
this.modelService.setMode(this.textEditorModel, this.languageService.createById(mode));
|
||||
}
|
||||
|
||||
getMode(): string | undefined {
|
||||
|
@ -179,7 +179,7 @@ export class BaseTextEditorModel extends EditorModel implements ITextEditorModel
|
|||
}
|
||||
|
||||
// otherwise take the preferred mode for granted
|
||||
return languageService.create(preferredMode);
|
||||
return languageService.createById(preferredMode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -197,7 +197,7 @@ export class BaseTextEditorModel extends EditorModel implements ITextEditorModel
|
|||
|
||||
// mode (only if specific and changed)
|
||||
if (preferredMode && preferredMode !== PLAINTEXT_MODE_ID && this.textEditorModel.getLanguageId() !== preferredMode) {
|
||||
this.modelService.setMode(this.textEditorModel, this.languageService.create(preferredMode));
|
||||
this.modelService.setMode(this.textEditorModel, this.languageService.createById(preferredMode));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -416,7 +416,7 @@ export class BulkEditPreviewProvider implements ITextModelContentProvider {
|
|||
const sourceModel = ref.object.textEditorModel;
|
||||
model = this._modelService.createModel(
|
||||
createTextBufferFactoryFromSnapshot(sourceModel.createSnapshot()),
|
||||
this._languageService.create(sourceModel.getLanguageId()),
|
||||
this._languageService.createById(sourceModel.getLanguageId()),
|
||||
previewUri
|
||||
);
|
||||
ref.dispose();
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
import { URI as uri } from 'vs/base/common/uri';
|
||||
import { localize } from 'vs/nls';
|
||||
import { guessMimeTypes, Mimes } from 'vs/base/common/mime';
|
||||
import { guessMimeTypes } from 'vs/base/common/mime';
|
||||
import { ITextModel } from 'vs/editor/common/model';
|
||||
import { IModelService } from 'vs/editor/common/services/modelService';
|
||||
import { ILanguageService } from 'vs/editor/common/services/languageService';
|
||||
|
@ -17,6 +17,7 @@ import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerServ
|
|||
import { EditOperation } from 'vs/editor/common/core/editOperation';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { CancellationTokenSource } from 'vs/base/common/cancellation';
|
||||
import { PLAINTEXT_MODE_ID } from 'vs/editor/common/modes/modesRegistry';
|
||||
|
||||
/**
|
||||
* Debug URI format
|
||||
|
@ -94,7 +95,7 @@ export class DebugContentProvider implements IWorkbenchContribution, ITextModelC
|
|||
}
|
||||
const createErrModel = (errMsg?: string) => {
|
||||
this.debugService.sourceIsNotAvailable(resource);
|
||||
const languageSelection = this.languageService.create(Mimes.text);
|
||||
const languageSelection = this.languageService.createById(PLAINTEXT_MODE_ID);
|
||||
const message = errMsg
|
||||
? localize('canNotResolveSourceWithError', "Could not load source '{0}': {1}.", resource.path, errMsg)
|
||||
: localize('canNotResolveSource', "Could not load source '{0}'.", resource.path);
|
||||
|
@ -134,7 +135,7 @@ export class DebugContentProvider implements IWorkbenchContribution, ITextModelC
|
|||
} else {
|
||||
// create text model
|
||||
const mime = response.body.mimeType || guessMimeTypes(resource)[0];
|
||||
const languageSelection = this.languageService.create(mime);
|
||||
const languageSelection = this.languageService.createByMimeType(mime);
|
||||
return this.modelService.createModel(response.body.content, languageSelection, resource);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -198,7 +198,7 @@ export class TextFileContentProvider extends Disposable implements ITextModelCon
|
|||
|
||||
let languageSelector: ILanguageSelection;
|
||||
if (textFileModel) {
|
||||
languageSelector = this.languageService.create(textFileModel.getLanguageId());
|
||||
languageSelector = this.languageService.createById(textFileModel.getLanguageId());
|
||||
} else {
|
||||
languageSelector = this.languageService.createByFilepathOrFirstLine(savedFileResource);
|
||||
}
|
||||
|
|
|
@ -513,7 +513,7 @@ export class InteractiveEditor extends EditorPane {
|
|||
|
||||
if (selectedOrSuggested) {
|
||||
const language = selectedOrSuggested.supportedLanguages[0];
|
||||
const newMode = language ? this.#languageService.create(language).languageId : PLAINTEXT_MODE_ID;
|
||||
const newMode = language ? this.#languageService.createById(language).languageId : PLAINTEXT_MODE_ID;
|
||||
textModel.setMode(newMode);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ abstract class CodeRendererContrib extends Disposable implements IOutputTransfor
|
|||
container.style.height = `${editorHeight + 8}px`;
|
||||
}));
|
||||
|
||||
const mode = this.languageService.create(languageId);
|
||||
const mode = this.languageService.createById(languageId);
|
||||
const textModel = this.modelService.createModel(value, mode, undefined, false);
|
||||
editor.setModel(textModel);
|
||||
|
||||
|
|
|
@ -596,7 +596,7 @@ abstract class AbstractElementRenderer extends Disposable {
|
|||
this.layout({ metadataHeight: true });
|
||||
this._metadataEditorDisposeStore.add(this._metadataEditor);
|
||||
|
||||
const mode = this.languageService.create('jsonc');
|
||||
const mode = this.languageService.createById('jsonc');
|
||||
const originalMetadataSource = getFormatedMetadataJSON(this.notebookEditor.textModel!,
|
||||
this.cell.type === 'insert'
|
||||
? this.cell.modified!.metadata || {}
|
||||
|
@ -630,7 +630,7 @@ abstract class AbstractElementRenderer extends Disposable {
|
|||
const originalOutputsSource = getFormatedOutputJSON(this.cell.original?.outputs || []);
|
||||
const modifiedOutputsSource = getFormatedOutputJSON(this.cell.modified?.outputs || []);
|
||||
if (originalOutputsSource !== modifiedOutputsSource) {
|
||||
const mode = this.languageService.create('json');
|
||||
const mode = this.languageService.createById('json');
|
||||
const originalModel = this.modelService.createModel(originalOutputsSource, mode, undefined, true);
|
||||
const modifiedModel = this.modelService.createModel(modifiedOutputsSource, mode, undefined, true);
|
||||
this._outputEditorDisposeStore.add(originalModel);
|
||||
|
@ -690,7 +690,7 @@ abstract class AbstractElementRenderer extends Disposable {
|
|||
}, {});
|
||||
this._outputEditorDisposeStore.add(this._outputEditor);
|
||||
|
||||
const mode = this.languageService.create('json');
|
||||
const mode = this.languageService.createById('json');
|
||||
const originaloutputSource = getFormatedOutputJSON(
|
||||
this.notebookEditor.textModel!.transientOptions.transientOutputs
|
||||
? []
|
||||
|
|
|
@ -275,7 +275,7 @@ class CellContentProvider implements ITextModelContentProvider {
|
|||
}
|
||||
};
|
||||
const languageId = this._languageService.getLanguageIdForLanguageName(cell.language);
|
||||
const languageSelection = languageId ? this._languageService.create(languageId) : (cell.cellKind === CellKind.Markup ? this._languageService.create('markdown') : this._languageService.createByFilepathOrFirstLine(resource, cell.textBuffer.getLineContent(1)));
|
||||
const languageSelection = languageId ? this._languageService.createById(languageId) : (cell.cellKind === CellKind.Markup ? this._languageService.createById('markdown') : this._languageService.createByFilepathOrFirstLine(resource, cell.textBuffer.getLineContent(1)));
|
||||
result = this._modelService.createModel(
|
||||
bufferFactory,
|
||||
languageSelection,
|
||||
|
@ -349,7 +349,7 @@ class CellInfoContentProvider {
|
|||
const ref = await this._notebookModelResolverService.resolve(data.notebook);
|
||||
let result: ITextModel | null = null;
|
||||
|
||||
const mode = this._languageService.create('json');
|
||||
const mode = this._languageService.createById('json');
|
||||
|
||||
for (const cell of ref.object.notebook.cells) {
|
||||
if (cell.handle === data.handle) {
|
||||
|
@ -382,7 +382,7 @@ class CellInfoContentProvider {
|
|||
if (streamOutputData) {
|
||||
return {
|
||||
content: streamOutputData,
|
||||
mode: this._languageService.create('plaintext')
|
||||
mode: this._languageService.createById('plaintext')
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -396,7 +396,7 @@ class CellInfoContentProvider {
|
|||
}, cell: NotebookCellTextModel) {
|
||||
let result: { content: string, mode: ILanguageSelection } | undefined = undefined;
|
||||
|
||||
const mode = this._languageService.create('json');
|
||||
const mode = this._languageService.createById('json');
|
||||
const op = cell.outputs.find(op => op.outputId === data.outputId);
|
||||
const streamOutputData = this.parseStreamOutput(op);
|
||||
if (streamOutputData) {
|
||||
|
|
|
@ -92,7 +92,7 @@ export class NotebookCellTextModel extends Disposable implements ICell {
|
|||
}
|
||||
|
||||
if (this._textModel) {
|
||||
const languageId = this._languageService.create(newLanguageId);
|
||||
const languageId = this._languageService.createById(newLanguageId);
|
||||
this._textModel.setMode(languageId.languageId);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookS
|
|||
import { mock } from 'vs/base/test/common/mock';
|
||||
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
|
||||
import { DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { Mimes } from 'vs/base/common/mime';
|
||||
import { PLAINTEXT_MODE_ID } from 'vs/editor/common/modes/modesRegistry';
|
||||
import { insertCellAtIndex } from 'vs/workbench/contrib/notebook/browser/controller/cellOperations';
|
||||
|
||||
suite('NotebookEditorKernelManager', () => {
|
||||
|
@ -157,6 +157,6 @@ class TestNotebookKernel implements INotebookKernel {
|
|||
}
|
||||
|
||||
constructor(opts?: { languages: string[] }) {
|
||||
this.supportedLanguages = opts?.languages ?? [Mimes.text];
|
||||
this.supportedLanguages = opts?.languages ?? [PLAINTEXT_MODE_ID];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import { mock } from 'vs/base/test/common/mock';
|
|||
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
|
||||
import { DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
|
||||
import { Mimes } from 'vs/base/common/mime';
|
||||
import { PLAINTEXT_MODE_ID } from 'vs/editor/common/modes/modesRegistry';
|
||||
|
||||
suite('NotebookKernelService', () => {
|
||||
|
||||
|
@ -179,7 +179,7 @@ class TestNotebookKernel implements INotebookKernel {
|
|||
}
|
||||
|
||||
constructor(opts?: { languages?: string[], label?: string, viewType?: string }) {
|
||||
this.supportedLanguages = opts?.languages ?? [Mimes.text];
|
||||
this.supportedLanguages = opts?.languages ?? [PLAINTEXT_MODE_ID];
|
||||
this.label = opts?.label ?? this.label;
|
||||
this.viewType = opts?.viewType ?? this.viewType;
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ export class FileOutputChannelModel extends Disposable implements IOutputChannel
|
|||
|
||||
constructor(
|
||||
private readonly modelUri: URI,
|
||||
private readonly mimeType: string,
|
||||
private readonly mimeType: 'text/x-code-log-output' | 'text/x-code-output',
|
||||
private readonly file: URI,
|
||||
@IFileService private readonly fileService: IFileService,
|
||||
@IModelService private readonly modelService: IModelService,
|
||||
|
@ -163,7 +163,7 @@ export class FileOutputChannelModel extends Disposable implements IOutputChannel
|
|||
if (this.model) {
|
||||
this.model.setValue(content);
|
||||
} else {
|
||||
this.model = this.modelService.createModel(content, this.languageService.create(this.mimeType), this.modelUri);
|
||||
this.model = this.modelService.createModel(content, this.languageService.createByMimeType(this.mimeType), this.modelUri);
|
||||
this.fileHandler.watch(this.etag);
|
||||
const disposable = this.model.onWillDispose(() => {
|
||||
this.cancelModelUpdate();
|
||||
|
@ -324,7 +324,7 @@ class OutputChannelBackedByFile extends FileOutputChannelModel implements IOutpu
|
|||
constructor(
|
||||
id: string,
|
||||
modelUri: URI,
|
||||
mimeType: string,
|
||||
mimeType: 'text/x-code-log-output' | 'text/x-code-output',
|
||||
file: URI,
|
||||
@IFileService fileService: IFileService,
|
||||
@IModelService modelService: IModelService,
|
||||
|
@ -371,7 +371,7 @@ export class DelegatedOutputChannelModel extends Disposable implements IOutputCh
|
|||
constructor(
|
||||
id: string,
|
||||
modelUri: URI,
|
||||
mimeType: string,
|
||||
mimeType: 'text/x-code-log-output' | 'text/x-code-output',
|
||||
outputDir: Promise<URI>,
|
||||
@IInstantiationService private readonly instantiationService: IInstantiationService,
|
||||
@IFileService private readonly fileService: IFileService,
|
||||
|
@ -380,7 +380,7 @@ export class DelegatedOutputChannelModel extends Disposable implements IOutputCh
|
|||
this.outputChannelModel = this.createOutputChannelModel(id, modelUri, mimeType, outputDir);
|
||||
}
|
||||
|
||||
private async createOutputChannelModel(id: string, modelUri: URI, mimeType: string, outputDirPromise: Promise<URI>): Promise<IOutputChannelModel> {
|
||||
private async createOutputChannelModel(id: string, modelUri: URI, mimeType: 'text/x-code-log-output' | 'text/x-code-output', outputDirPromise: Promise<URI>): Promise<IOutputChannelModel> {
|
||||
const outputDir = await outputDirPromise;
|
||||
const file = resources.joinPath(outputDir, `${id.replace(/[\\/:\*\?"<>\|]/g, '')}.log`);
|
||||
await this.fileService.createFile(file);
|
||||
|
|
|
@ -17,7 +17,7 @@ export const IOutputChannelModelService = createDecorator<IOutputChannelModelSer
|
|||
export interface IOutputChannelModelService {
|
||||
readonly _serviceBrand: undefined;
|
||||
|
||||
createOutputChannelModel(id: string, modelUri: URI, mimeType: string, file?: URI): IOutputChannelModel;
|
||||
createOutputChannelModel(id: string, modelUri: URI, mimeType: 'text/x-code-log-output' | 'text/x-code-output', file?: URI): IOutputChannelModel;
|
||||
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ export abstract class AbstractOutputChannelModelService {
|
|||
@IInstantiationService protected readonly instantiationService: IInstantiationService
|
||||
) { }
|
||||
|
||||
createOutputChannelModel(id: string, modelUri: URI, mimeType: string, file?: URI): IOutputChannelModel {
|
||||
createOutputChannelModel(id: string, modelUri: URI, mimeType: 'text/x-code-log-output' | 'text/x-code-output', file?: URI): IOutputChannelModel {
|
||||
return file ? this.instantiationService.createInstance(FileOutputChannelModel, modelUri, mimeType, file) : this.instantiationService.createInstance(DelegatedOutputChannelModel, id, modelUri, mimeType, this.outputDir);
|
||||
}
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ class PerfModelContentProvider implements ITextModelContentProvider {
|
|||
|
||||
if (!this._model || this._model.isDisposed()) {
|
||||
dispose(this._modelDisposables);
|
||||
const langId = this._languageService.create('markdown');
|
||||
const langId = this._languageService.createById('markdown');
|
||||
this._model = this._modelService.getModel(resource) || this._modelService.createModel('Loading...', langId, resource);
|
||||
|
||||
this._modelDisposables.push(langId.onDidChange(e => {
|
||||
|
|
|
@ -122,7 +122,7 @@ export class PreferencesContribution implements IWorkbenchContribution {
|
|||
let schema = schemaRegistry.getSchemaContributions().schemas[uri.toString()];
|
||||
if (schema) {
|
||||
const modelContent = JSON.stringify(schema);
|
||||
const languageSelection = this.languageService.create('jsonc');
|
||||
const languageSelection = this.languageService.createById('jsonc');
|
||||
const model = this.modelService.createModel(modelContent, languageSelection, uri);
|
||||
const disposables = new DisposableStore();
|
||||
disposables.add(schemaRegistry.onDidChangeSchema(schemaUri => {
|
||||
|
|
|
@ -1649,7 +1649,7 @@ class SCMInputWidget extends Disposable {
|
|||
this.configurationService.updateValue('editor.wordBasedSuggestions', false, { resource: uri }, ConfigurationTarget.MEMORY);
|
||||
}
|
||||
|
||||
const textModel = this.modelService.getModel(uri) ?? this.modelService.createModel('', this.languageService.create('scminput'), uri);
|
||||
const textModel = this.modelService.getModel(uri) ?? this.modelService.createModel('', this.languageService.createById('scminput'), uri);
|
||||
this.inputEditor.setModel(textModel);
|
||||
|
||||
// Validation
|
||||
|
|
|
@ -71,7 +71,7 @@ class ReplacePreviewModel extends Disposable {
|
|||
const ref = this._register(await this.textModelResolverService.createModelReference(fileResource));
|
||||
const sourceModel = ref.object.textEditorModel;
|
||||
const sourceModelModeId = sourceModel.getLanguageId();
|
||||
const replacePreviewModel = this.modelService.createModel(createTextBufferFactoryFromSnapshot(sourceModel.createSnapshot()), this.languageService.create(sourceModelModeId), replacePreviewUri);
|
||||
const replacePreviewModel = this.modelService.createModel(createTextBufferFactoryFromSnapshot(sourceModel.createSnapshot()), this.languageService.createById(sourceModelModeId), replacePreviewUri);
|
||||
this._register(fileMatch.onChange(({ forceUpdateModel }) => this.update(sourceModel, replacePreviewModel, fileMatch, forceUpdateModel)));
|
||||
this._register(this.searchWorkbenchService.searchModel.onReplaceTermChanged(() => this.update(sourceModel, replacePreviewModel, fileMatch)));
|
||||
this._register(fileMatch.onDispose(() => replacePreviewModel.dispose())); // TODO@Sandeep we should not dispose a model directly but rather the reference (depends on https://github.com/microsoft/vscode/issues/17073)
|
||||
|
|
|
@ -67,7 +67,7 @@ class SearchEditorModelFactory {
|
|||
}
|
||||
|
||||
return Promise.resolve({
|
||||
resultsModel: modelService.getModel(resource) ?? modelService.createModel('', languageService.create('search-result'), resource),
|
||||
resultsModel: modelService.getModel(resource) ?? modelService.createModel('', languageService.createById('search-result'), resource),
|
||||
configurationModel: new SearchConfigurationModel(config)
|
||||
});
|
||||
})();
|
||||
|
@ -100,7 +100,7 @@ class SearchEditorModelFactory {
|
|||
}
|
||||
|
||||
return Promise.resolve({
|
||||
resultsModel: modelService.createModel(contents ?? '', languageService.create('search-result'), resource),
|
||||
resultsModel: modelService.createModel(contents ?? '', languageService.createById('search-result'), resource),
|
||||
configurationModel: new SearchConfigurationModel(config)
|
||||
});
|
||||
})();
|
||||
|
@ -134,7 +134,7 @@ class SearchEditorModelFactory {
|
|||
|
||||
const { text, config } = await instantiationService.invokeFunction(parseSavedSearchEditor, existingFile);
|
||||
return ({
|
||||
resultsModel: modelService.createModel(text ?? '', languageService.create('search-result'), resource),
|
||||
resultsModel: modelService.createModel(text ?? '', languageService.createById('search-result'), resource),
|
||||
configurationModel: new SearchConfigurationModel(config)
|
||||
});
|
||||
})();
|
||||
|
@ -151,7 +151,7 @@ class SearchEditorModelFactory {
|
|||
if (!model && backup) {
|
||||
const factory = await createTextBufferFactoryFromStream(backup.value);
|
||||
|
||||
model = modelService.createModel(factory, languageService.create('search-result'), resource);
|
||||
model = modelService.createModel(factory, languageService.createById('search-result'), resource);
|
||||
}
|
||||
|
||||
if (model) {
|
||||
|
@ -159,7 +159,7 @@ class SearchEditorModelFactory {
|
|||
const { text, config } = parseSerializedSearchEditor(existingFile);
|
||||
modelService.destroyModel(resource);
|
||||
return ({
|
||||
resultsModel: modelService.createModel(text ?? '', languageService.create('search-result'), resource),
|
||||
resultsModel: modelService.createModel(text ?? '', languageService.createById('search-result'), resource),
|
||||
configurationModel: new SearchConfigurationModel(config)
|
||||
});
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ export class TestingContentProvider implements IWorkbenchContribution, ITextMode
|
|||
text = message;
|
||||
} else if (message) {
|
||||
text = message.value;
|
||||
language = this.languageService.create('markdown');
|
||||
language = this.languageService.createById('markdown');
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1293,7 +1293,7 @@ class UserDataRemoteContentProvider implements ITextModelContentProvider {
|
|||
|
||||
provideTextContent(uri: URI): Promise<ITextModel> | null {
|
||||
if (uri.scheme === USER_DATA_SYNC_SCHEME) {
|
||||
return this.userDataSyncService.resolveContent(uri).then(content => this.modelService.createModel(content || '', this.languageService.create('jsonc'), uri));
|
||||
return this.userDataSyncService.resolveContent(uri).then(content => this.modelService.createModel(content || '', this.languageService.createById('jsonc'), uri));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ export class WalkThroughSnippetContentProvider implements ITextModelContentProvi
|
|||
renderer.code = (code, lang) => {
|
||||
i++;
|
||||
const languageId = this.languageService.getLanguageIdForLanguageName(lang) || '';
|
||||
const languageSelection = this.languageService.create(languageId);
|
||||
const languageSelection = this.languageService.createById(languageId);
|
||||
// Create all models for this resource in one go... we'll need them all and we don't want to re-parse markdown each time
|
||||
const model = this.modelService.createModel(code, languageSelection, resource.with({ fragment: `${i}.${lang}` }));
|
||||
if (i === j) { codeEditorModel = model; }
|
||||
|
|
|
@ -122,7 +122,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic
|
|||
if (this.isDefaultSettingsResource(uri)) {
|
||||
|
||||
const target = this.getConfigurationTargetFromDefaultSettingsResource(uri);
|
||||
const languageSelection = this.languageService.create('jsonc');
|
||||
const languageSelection = this.languageService.createById('jsonc');
|
||||
const model = this._register(this.modelService.createModel('', languageSelection, uri));
|
||||
|
||||
let defaultSettings: DefaultSettings | undefined;
|
||||
|
@ -150,14 +150,14 @@ export class PreferencesService extends Disposable implements IPreferencesServic
|
|||
|
||||
if (this.defaultSettingsRawResource.toString() === uri.toString()) {
|
||||
const defaultRawSettingsEditorModel = this.instantiationService.createInstance(DefaultRawSettingsEditorModel, this.getDefaultSettings(ConfigurationTarget.USER_LOCAL));
|
||||
const languageSelection = this.languageService.create('jsonc');
|
||||
const languageSelection = this.languageService.createById('jsonc');
|
||||
const model = this._register(this.modelService.createModel(defaultRawSettingsEditorModel.content, languageSelection, uri));
|
||||
return model;
|
||||
}
|
||||
|
||||
if (this.defaultKeybindingsResource.toString() === uri.toString()) {
|
||||
const defaultKeybindingsEditorModel = this.instantiationService.createInstance(DefaultKeybindingsEditorModel, uri);
|
||||
const languageSelection = this.languageService.create('jsonc');
|
||||
const languageSelection = this.languageService.createById('jsonc');
|
||||
const model = this._register(this.modelService.createModel(defaultKeybindingsEditorModel.content, languageSelection, uri));
|
||||
return model;
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ suite('Workbench - TextModelResolverService', () => {
|
|||
provideTextContent: async function (resource: URI): Promise<ITextModel | null> {
|
||||
if (resource.scheme === 'test') {
|
||||
let modelContent = 'Hello Test';
|
||||
let languageSelection = accessor.languageService.create('json');
|
||||
let languageSelection = accessor.languageService.createById('json');
|
||||
|
||||
return accessor.modelService.createModel(modelContent, languageSelection, resource);
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ suite('Workbench - TextModelResolverService', () => {
|
|||
await waitForIt;
|
||||
|
||||
let modelContent = 'Hello Test';
|
||||
let languageSelection = accessor.languageService.create('json');
|
||||
let languageSelection = accessor.languageService.createById('json');
|
||||
return accessor.modelService.createModel(modelContent, languageSelection, resource);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -34,7 +34,7 @@ suite('TextDiffEditorModel', () => {
|
|||
provideTextContent: async function (resource: URI): Promise<ITextModel | null> {
|
||||
if (resource.scheme === 'test') {
|
||||
let modelContent = 'Hello Test';
|
||||
let languageSelection = accessor.languageService.create('json');
|
||||
let languageSelection = accessor.languageService.createById('json');
|
||||
|
||||
return accessor.modelService.createModel(modelContent, languageSelection, resource);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ suite('TextResourceEditorInput', () => {
|
|||
|
||||
test('basics', async () => {
|
||||
const resource = URI.from({ scheme: 'inmemory', authority: null!, path: 'thePath' });
|
||||
accessor.modelService.createModel('function test() {}', accessor.languageService.create('text'), resource);
|
||||
accessor.modelService.createModel('function test() {}', accessor.languageService.createById(PLAINTEXT_MODE_ID), resource);
|
||||
|
||||
const input = instantiationService.createInstance(TextResourceEditorInput, resource, 'The Name', 'The Description', undefined, undefined);
|
||||
|
||||
|
@ -47,7 +47,7 @@ suite('TextResourceEditorInput', () => {
|
|||
});
|
||||
|
||||
const resource = URI.from({ scheme: 'inmemory', authority: null!, path: 'thePath' });
|
||||
accessor.modelService.createModel('function test() {}', accessor.languageService.create('text'), resource);
|
||||
accessor.modelService.createModel('function test() {}', accessor.languageService.createById(PLAINTEXT_MODE_ID), resource);
|
||||
|
||||
const input = instantiationService.createInstance(TextResourceEditorInput, resource, 'The Name', 'The Description', 'resource-input-test', undefined);
|
||||
|
||||
|
@ -68,7 +68,7 @@ suite('TextResourceEditorInput', () => {
|
|||
});
|
||||
|
||||
const resource = URI.from({ scheme: 'inmemory', authority: null!, path: 'thePath' });
|
||||
accessor.modelService.createModel('function test() {}', accessor.languageService.create('text'), resource);
|
||||
accessor.modelService.createModel('function test() {}', accessor.languageService.createById(PLAINTEXT_MODE_ID), resource);
|
||||
|
||||
const input = instantiationService.createInstance(TextResourceEditorInput, resource, 'The Name', 'The Description', undefined, undefined);
|
||||
input.setPreferredMode('resource-input-test');
|
||||
|
@ -80,7 +80,7 @@ suite('TextResourceEditorInput', () => {
|
|||
|
||||
test('preferred contents (via ctor)', async () => {
|
||||
const resource = URI.from({ scheme: 'inmemory', authority: null!, path: 'thePath' });
|
||||
accessor.modelService.createModel('function test() {}', accessor.languageService.create('text'), resource);
|
||||
accessor.modelService.createModel('function test() {}', accessor.languageService.createById(PLAINTEXT_MODE_ID), resource);
|
||||
|
||||
const input = instantiationService.createInstance(TextResourceEditorInput, resource, 'The Name', 'The Description', undefined, 'My Resource Input Contents');
|
||||
|
||||
|
@ -97,7 +97,7 @@ suite('TextResourceEditorInput', () => {
|
|||
|
||||
test('preferred contents (via setPreferredContents)', async () => {
|
||||
const resource = URI.from({ scheme: 'inmemory', authority: null!, path: 'thePath' });
|
||||
accessor.modelService.createModel('function test() {}', accessor.languageService.create('text'), resource);
|
||||
accessor.modelService.createModel('function test() {}', accessor.languageService.createById(PLAINTEXT_MODE_ID), resource);
|
||||
|
||||
const input = instantiationService.createInstance(TextResourceEditorInput, resource, 'The Name', 'The Description', undefined, undefined);
|
||||
input.setPreferredContents('My Resource Input Contents');
|
||||
|
|
Loading…
Reference in a new issue