提交 fb887afc 编写于 作者: S Sandeep Somavarapu

#1587 Read the editor settings for language and update the editor

上级 8ba62c61
......@@ -33,6 +33,7 @@ import { ServiceCollection } from 'vs/platform/instantiation/common/serviceColle
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IThemeService } from 'vs/workbench/services/themes/common/themeService';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { IModeService } from 'vs/editor/common/services/modeService';
/**
* The text editor that leverages the diff text editor for the editing experience.
......@@ -52,9 +53,10 @@ export class TextDiffEditor extends BaseTextEditor {
@IConfigurationService configurationService: IConfigurationService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IThemeService themeService: IThemeService,
@IEditorGroupService private editorGroupService: IEditorGroupService
@IEditorGroupService private editorGroupService: IEditorGroupService,
@IModeService modeService: IModeService
) {
super(TextDiffEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService);
super(TextDiffEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, modeService);
}
public getTitle(): string {
......
......@@ -10,7 +10,7 @@ import { Dimension, Builder } from 'vs/base/browser/builder';
import objects = require('vs/base/common/objects');
import types = require('vs/base/common/types');
import { CodeEditor } from 'vs/editor/browser/codeEditor';
import { EditorInput, EditorOptions } from 'vs/workbench/common/editor';
import { EditorInput, EditorOptions, toResource } from 'vs/workbench/common/editor';
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { IEditorViewState, IEditor, IEditorOptions } from 'vs/editor/common/editorCommon';
import { Position } from 'vs/platform/editor/common/editor';
......@@ -20,6 +20,8 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IThemeService } from 'vs/workbench/services/themes/common/themeService';
import { Scope } from 'vs/workbench/common/memento';
import { getCodeEditor } from 'vs/editor/common/services/codeEditorService';
import { IModeService } from 'vs/editor/common/services/modeService';
const TEXT_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'textEditorViewState';
......@@ -49,7 +51,8 @@ export abstract class BaseTextEditor extends BaseEditor {
@IInstantiationService private _instantiationService: IInstantiationService,
@IStorageService private storageService: IStorageService,
@IConfigurationService private configurationService: IConfigurationService,
@IThemeService private themeService: IThemeService
@IThemeService private themeService: IThemeService,
@IModeService private modeService: IModeService
) {
super(id, telemetryService);
......@@ -91,6 +94,10 @@ export abstract class BaseTextEditor extends BaseEditor {
// Specific editor options always overwrite user configuration
const editorConfiguration = types.isObject(configuration.editor) ? objects.clone(configuration.editor) : Object.create(null);
const language = this.getLanguage();
if (language) {
objects.assign(editorConfiguration, this.configurationService.getConfiguration<IEditorConfiguration>({ language, section: 'editor' }));
}
objects.assign(editorConfiguration, this.getConfigurationOverrides());
return editorConfiguration;
......@@ -110,6 +117,11 @@ export abstract class BaseTextEditor extends BaseEditor {
// Editor for Text
this._editorContainer = parent;
this.editorControl = this.createEditorControl(parent, this.computeConfiguration(this.configurationService.getConfiguration<IEditorConfiguration>()));
const codeEditor = getCodeEditor(this);
if (codeEditor) {
this.toUnbind.push(codeEditor.onDidChangeModelLanguage(e => this.updateEditorConfiguration()));
this.toUnbind.push(codeEditor.onDidChangeModel(e => this.updateEditorConfiguration()));
}
}
/**
......@@ -129,7 +141,7 @@ export abstract class BaseTextEditor extends BaseEditor {
// Update editor options after having set the input. We do this because there can be
// editor input specific options (e.g. an ARIA label depending on the input showing)
this.editorControl.updateOptions(this.getConfigurationOverrides());
this.updateEditorConfiguration();
});
}
......@@ -211,6 +223,30 @@ export abstract class BaseTextEditor extends BaseEditor {
return null;
}
private updateEditorConfiguration(): void {
this.editorControl.updateOptions(this.computeConfiguration(this.configurationService.getConfiguration<IEditorConfiguration>()));
}
private getLanguage(): string {
const codeEditor = getCodeEditor(this);
if (codeEditor) {
const model = codeEditor.getModel();
if (model) {
return model.getLanguageIdentifier().language;
}
}
if (this.input) {
const resource = toResource(this.input);
if (resource) {
const modeId = this.modeService.getModeIdByFilenameOrFirstLine(resource.fsPath);
if (modeId) {
return this.modeService.getLanguageName(modeId);
}
}
}
return null;
}
public dispose(): void {
// Destroy Editor Control
......
......@@ -21,6 +21,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { IThemeService } from 'vs/workbench/services/themes/common/themeService';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { IModeService } from 'vs/editor/common/services/modeService';
/**
* An editor implementation that is capable of showing the contents of resource inputs. Uses
......@@ -37,9 +38,10 @@ export class TextResourceEditor extends BaseTextEditor {
@IConfigurationService configurationService: IConfigurationService,
@IThemeService themeService: IThemeService,
@IUntitledEditorService private untitledEditorService: IUntitledEditorService,
@IEditorGroupService private editorGroupService: IEditorGroupService
@IEditorGroupService private editorGroupService: IEditorGroupService,
@IModeService modeService: IModeService
) {
super(TextResourceEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService);
super(TextResourceEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, modeService);
this.toUnbind.push(this.untitledEditorService.onDidChangeDirty(e => this.onUntitledDirtyChange(e)));
}
......
......@@ -31,6 +31,7 @@ import { CancelAction } from 'vs/platform/message/common/message';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IThemeService } from 'vs/workbench/services/themes/common/themeService';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { IModeService } from 'vs/editor/common/services/modeService';
/**
* An implementation of editor for file system resources.
......@@ -50,9 +51,10 @@ export class TextFileEditor extends BaseTextEditor {
@IConfigurationService configurationService: IConfigurationService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IThemeService themeService: IThemeService,
@IEditorGroupService private editorGroupService: IEditorGroupService
@IEditorGroupService private editorGroupService: IEditorGroupService,
@IModeService modeService: IModeService
) {
super(TextFileEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService);
super(TextFileEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, modeService);
// Clear view state for deleted files
this.toUnbind.push(this.fileService.onFileChanges(e => this.onFilesChanged(e)));
......
......@@ -23,6 +23,7 @@ import { SwitchOutputAction, SwitchOutputActionItem, ClearOutputAction } from 'v
import { IThemeService } from 'vs/workbench/services/themes/common/themeService';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { IModeService } from 'vs/editor/common/services/modeService';
export class OutputPanel extends TextResourceEditor {
private toDispose: IDisposable[];
......@@ -38,9 +39,10 @@ export class OutputPanel extends TextResourceEditor {
@IOutputService private outputService: IOutputService,
@IUntitledEditorService untitledEditorService: IUntitledEditorService,
@IContextKeyService private contextKeyService: IContextKeyService,
@IEditorGroupService editorGroupService: IEditorGroupService
@IEditorGroupService editorGroupService: IEditorGroupService,
@IModeService modeService: IModeService
) {
super(telemetryService, instantiationService, storageService, configurationService, themeService, untitledEditorService, editorGroupService);
super(telemetryService, instantiationService, storageService, configurationService, themeService, untitledEditorService, editorGroupService, modeService);
this.scopedInstantiationService = instantiationService;
this.toDispose = [];
......
......@@ -112,9 +112,9 @@ export class DefaultPreferencesEditor extends BaseTextEditor {
@IUntitledEditorService private untitledEditorService: IUntitledEditorService,
@IPreferencesService private preferencesService: IPreferencesService,
@IModelService private modelService: IModelService,
@IModeService private modeService: IModeService
@IModeService modeService: IModeService,
) {
super(DefaultPreferencesEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService);
super(DefaultPreferencesEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, modeService);
this.delayedFilterLogging = new Delayer<void>(1000);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册