diff --git a/src/js/filemanager.js b/src/js/filemanager.js index 63a28821a..9a33fd53d 100644 --- a/src/js/filemanager.js +++ b/src/js/filemanager.js @@ -3,7 +3,6 @@ /* global angular, $, async, monaco */ require.config({ paths: { 'vs': '3rdparty/vs' }}); -require(['vs/editor/editor.main'], function() {}); // create main application module var app = angular.module('Application', ['angular-md5', 'ui-notification', 'ngDrag', 'ui.bootstrap']); @@ -72,6 +71,17 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio { name: 'root', value: 0 } ]; + var LANGUAGES = []; + require(['vs/editor/editor.main'], function() { + LANGUAGES = monaco.languages.getLanguages(); + }); + + function getLanguage(filename) { + var ext = '.' + filename.split('.').pop(); + var language = LANGUAGES.find(function (l) { return !!l.extensions.find(function (e) { return e === ext; }); }) || ''; + return language ? language.id : ''; + } + function sanitize(filePath) { filePath = filePath.split('/').filter(function (a) { return !!a; }).reduce(function (a, v) { if (v === '.'); // do nothing @@ -364,7 +374,7 @@ app.controller('FileManagerController', ['$scope', '$timeout', 'Client', functio $('#textEditorModal').modal('show'); var filePath = sanitize($scope.cwd + '/' + entry.fileName); - var language = 'javascript'; + var language = getLanguage(entry.fileName); Client.filesGet($scope.appId, filePath, false, function (error, result) { if (error) return Client.error(error);