mirror of
				https://github.com/avatao-content/frontend-tutorial-framework
				synced 2025-11-04 13:52:55 +00:00 
			
		
		
		
	Implement language autodetection (take that brace)
This commit is contained in:
		@@ -30,6 +30,7 @@ export const config = {
 | 
			
		||||
    showDeployButton: true,
 | 
			
		||||
    reloadIframeOnDeploy: true,
 | 
			
		||||
    showConsoleOnDeploy: true,
 | 
			
		||||
    autoDetectFileLanguage: true
 | 
			
		||||
  },
 | 
			
		||||
  terminal: {
 | 
			
		||||
    route: 'shell'
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										36
									
								
								src/app/ide/language-map.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								src/app/ide/language-map.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
// Copyright (C) 2018 Avatao.com Innovative Learning Kft.
 | 
			
		||||
// All Rights Reserved. See LICENSE file for details.
 | 
			
		||||
 | 
			
		||||
export const LanguageMap: { [extension: string]: string; } = {
 | 
			
		||||
    bat: 'bat',
 | 
			
		||||
    clje: 'clojure',
 | 
			
		||||
    coffee: 'coffee',
 | 
			
		||||
    c: 'cpp',
 | 
			
		||||
    h: 'cpp',
 | 
			
		||||
    cpp: 'cpp',
 | 
			
		||||
    hpp: 'cpp',
 | 
			
		||||
    cs: 'csharp',
 | 
			
		||||
    fs: 'fsharp',
 | 
			
		||||
    go: 'go',
 | 
			
		||||
    html: 'html',
 | 
			
		||||
    java: 'java',
 | 
			
		||||
    js: 'javascript',
 | 
			
		||||
    ts: 'typescript',
 | 
			
		||||
    lua: 'lua',
 | 
			
		||||
    md: 'markdown',
 | 
			
		||||
    m: 'objective-c',
 | 
			
		||||
    mm: 'objective-c',
 | 
			
		||||
    php: 'php',
 | 
			
		||||
    py: 'python',
 | 
			
		||||
    r: 'r',
 | 
			
		||||
    rb: 'ruby',
 | 
			
		||||
    rs: 'rust',
 | 
			
		||||
    rlib: 'rust',
 | 
			
		||||
    sql: 'sql',
 | 
			
		||||
    swift: 'swift',
 | 
			
		||||
    xml: 'xml',
 | 
			
		||||
    yml: 'yaml',
 | 
			
		||||
    css: 'css',
 | 
			
		||||
    less: 'less',
 | 
			
		||||
    scss: 'scss'
 | 
			
		||||
};
 | 
			
		||||
		Reference in New Issue
	
	Block a user