Try to figure out the file language for monaco

This commit is contained in:
Johannes Zellner
2020-07-14 16:41:40 +02:00
parent 3a54e662c2
commit 6956cfa32d

View File

@@ -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);