Implement language autodetection (take that brace)
This commit is contained in:
@@ -9,6 +9,7 @@ import { ProcessManagerService } from '../services/processmanager.service';
|
||||
import { DeploymentNotificationService } from '../services/deployment-notification.service';
|
||||
import { config } from '../config';
|
||||
import { CommandMessage } from '../message-types/command-message';
|
||||
import { LanguageMap } from './language-map';
|
||||
|
||||
|
||||
enum DeployButtonState {
|
||||
@@ -45,10 +46,9 @@ export class IdeComponent implements OnInit {
|
||||
showDeployButton: boolean = config.ide.showDeployButton;
|
||||
autosave = null;
|
||||
|
||||
language: string = config.ide.defaultLanguage;
|
||||
editorOptions = {
|
||||
theme: 'vs-dark',
|
||||
language: 'python',
|
||||
language: config.ide.defaultLanguage,
|
||||
glyphMargin: false,
|
||||
minimap: {enabled: false}
|
||||
};
|
||||
@@ -128,6 +128,9 @@ export class IdeComponent implements OnInit {
|
||||
if (this.codeState === CodeState.SAVED) {
|
||||
this.updateFileData(data);
|
||||
}
|
||||
if (config.ide.autoDetectFileLanguage) {
|
||||
this.autoDetectEditorLanguage(data.filename);
|
||||
}
|
||||
}
|
||||
|
||||
writeHandler(data: CommandMessage) {
|
||||
@@ -138,6 +141,21 @@ export class IdeComponent implements OnInit {
|
||||
this.updateFileData(data);
|
||||
}
|
||||
|
||||
autoDetectEditorLanguage(filename: string) {
|
||||
const extension = filename.substr(filename.lastIndexOf('.') + 1);
|
||||
let language = LanguageMap[extension];
|
||||
language = (language === undefined) ? 'text' : language;
|
||||
this.setEditorLanguage(language);
|
||||
}
|
||||
|
||||
setEditorLanguage(lang: string) {
|
||||
this.editorOptions = Object.assign(
|
||||
{},
|
||||
this.editorOptions,
|
||||
{ language: lang }
|
||||
);
|
||||
}
|
||||
|
||||
resetAutoSaveCountdown() {
|
||||
if (this.autosave) {
|
||||
clearInterval(this.autosave);
|
||||
|
||||
Reference in New Issue
Block a user