mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
Add new "files.defaultLanguage" configuration setting
This change adds a new configuration setting that sets the default language mode of new untitled files created with Ctrl+N (workbench.action.files.newUntitledFile). This activates the user's desired language mode when a new untitled file is created. Fixes #8729.
This commit is contained in:
parent
37d0a6f5db
commit
dfa42afcb8
|
@ -32,6 +32,11 @@ export class SettingsDocument {
|
|||
return this.provideExcludeCompletionItems(location, range);
|
||||
}
|
||||
|
||||
// files.defaultLanguage
|
||||
if (location.path[0] === 'files.defaultLanguage') {
|
||||
return this.provideDefaultLanguageCompletionItems(location, range);
|
||||
}
|
||||
|
||||
return this.provideLanguageOverridesCompletionItems(location, position);
|
||||
}
|
||||
|
||||
|
@ -192,6 +197,18 @@ export class SettingsDocument {
|
|||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
private provideDefaultLanguageCompletionItems(location: Location, range: vscode.Range): vscode.ProviderResult<vscode.CompletionItem[]> {
|
||||
// Suggestion model word matching includes a starting quote
|
||||
// Hence exclude it from the proposal range
|
||||
range = new vscode.Range(new vscode.Position(range.start.line, range.start.character + 1), range.end);
|
||||
|
||||
return vscode.languages.getLanguages().then(languages => {
|
||||
return languages.map(l => {
|
||||
return this.newSimpleCompletionItem(l, range, '', l + '"');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private newSimpleCompletionItem(text: string, range: vscode.Range, description?: string, insertText?: string): vscode.CompletionItem {
|
||||
const item = new vscode.CompletionItem(text);
|
||||
item.kind = vscode.CompletionItemKind.Value;
|
||||
|
|
|
@ -575,6 +575,7 @@ export interface IFilesConfiguration {
|
|||
exclude: glob.IExpression;
|
||||
watcherExclude: { [filepattern: string]: boolean };
|
||||
encoding: string;
|
||||
defaultLanguage: string;
|
||||
trimTrailingWhitespace: boolean;
|
||||
autoSave: string;
|
||||
autoSaveDelay: number;
|
||||
|
|
|
@ -265,6 +265,10 @@ configurationRegistry.registerConfiguration({
|
|||
nls.localize('hotExit.onExitAndWindowClose', 'Hot exit will be triggered when the application is closed, that is when the last window is closed on Windows/Linux or when the workbench.action.quit command is triggered (command pallete, keybinding, menu), and also for any window with a folder opened regardless of whether it\'s the last window. All windows without folders opened will be restored upon next launch. To restore folder windows as they were before shutdown set "window.reopenFolders" to "all".')
|
||||
],
|
||||
'description': nls.localize('hotExit', "Controls whether unsaved files are remembered between sessions, allowing the save prompt when exiting the editor to be skipped.", HotExitConfiguration.ON_EXIT, HotExitConfiguration.ON_EXIT_AND_WINDOW_CLOSE)
|
||||
},
|
||||
'files.defaultLanguage': {
|
||||
'type': 'string',
|
||||
'description': nls.localize('defaultLanguage', "The default language mode that is assigned to new files.")
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -8,6 +8,8 @@ import URI from 'vs/base/common/uri';
|
|||
import { createDecorator, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import arrays = require('vs/base/common/arrays');
|
||||
import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput';
|
||||
import { IFilesConfiguration } from 'vs/platform/files/common/files';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import Event, { Emitter, once } from 'vs/base/common/event';
|
||||
|
||||
export const IUntitledEditorService = createDecorator<IUntitledEditorService>('untitledEditorService');
|
||||
|
@ -89,7 +91,8 @@ export class UntitledEditorService implements IUntitledEditorService {
|
|||
private _onDidDisposeModel: Emitter<URI>;
|
||||
|
||||
constructor(
|
||||
@IInstantiationService private instantiationService: IInstantiationService
|
||||
@IInstantiationService private instantiationService: IInstantiationService,
|
||||
@IConfigurationService private configurationService: IConfigurationService
|
||||
) {
|
||||
this._onDidChangeContent = new Emitter<URI>();
|
||||
this._onDidChangeDirty = new Emitter<URI>();
|
||||
|
@ -185,6 +188,11 @@ export class UntitledEditorService implements IUntitledEditorService {
|
|||
} while (Object.keys(UntitledEditorService.CACHE).indexOf(resource.toString()) >= 0);
|
||||
}
|
||||
|
||||
const configuration = this.configurationService.getConfiguration<IFilesConfiguration>();
|
||||
if (!modeId && configuration.files && configuration.files.defaultLanguage) {
|
||||
modeId = configuration.files.defaultLanguage;
|
||||
}
|
||||
|
||||
const input = this.instantiationService.createInstance(UntitledEditorInput, resource, hasAssociatedFilePath, modeId, initialValue);
|
||||
|
||||
const contentListener = input.onDidModelChangeContent(() => {
|
||||
|
|
Loading…
Reference in a new issue