Commit 9c8e3b75 authored by Franco Pariani's avatar Franco Pariani
Browse files

Autocomplete hints from included files

parent 3ff23a41
......@@ -152,6 +152,9 @@
list.push(default_sets[i]);
}
}
// included sets
hintsSetsFromIncludedFiles(editor.options.files, editor, curWord, list);
}else{
// get variables of function
var previous_block = "";
......@@ -197,6 +200,8 @@
}
}
}
// included enums
hintsEnumsFromIncludedFiles(editor.options.files, editor, curWord, list);
// get functions
var re_funs = new RegExp(FUNS.source, "g");
for (var dir = -1; dir <= 1; dir += 2) {
......@@ -211,6 +216,8 @@
}
}
}
// included functions
hintsFunctionsFromIncludedFiles(editor.options.files, editor, curWord, list);
// add default functions
var default_functions = hintWords.EN_functions();
for (var i = 0; i < default_functions.length; i++) {
......@@ -227,6 +234,95 @@
return {list: list, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)};
});
var INCLUIR = /include\s+([\w\_\d]+)/;
function hintsFunctionsFromIncludedFiles(all_files, editor, curWord, list){
var re_digits = new RegExp(/^\d+$/, "g");
var includes = new RegExp(INCLUIR.source, "g");
var content = editor.getValue();
var file;
while (file = includes.exec(content)) {
var files = all_files.archivos.filter(
function(a){
return a.nombre === file[1];
});
for (var f = 0; f < files.length; f++){
var seen = {};
var m;
var re_funs = new RegExp(FUNS.source, "g");
var file_content = files[f].contenido;
while (m = re_funs.exec(file_content)) {
if (!re_digits.exec(m[1]) && (!curWord || m[1].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, m[1])) {
seen[m[1]] = true;
list.push(m[1]);
}
}
}
}
}
function hintsSetsFromIncludedFiles(all_files, editor, curWord, list){
var re_digits = new RegExp(/^\d+$/, "g");
var includes = new RegExp(INCLUIR.source, "g");
var content = editor.getValue();
var file;
while (file = includes.exec(content)) {
var files = all_files.archivos.filter(
function(a){
return a.nombre === file[1];
});
for (var f = 0; f < files.length; f++){
var seen = {};
var m;
var re_sets = new RegExp(SET.source, "g");
var file_content = files[f].contenido;
while (m = re_sets.exec(file_content)) {
if (!re_digits.exec(m[1]) && (!curWord || m[1].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, m[1])) {
seen[m[1]] = true;
list.push(m[1]);
}
}
}
}
}
function hintsEnumsFromIncludedFiles(all_files, editor, curWord, list){
var re_digits = new RegExp(/^\d+$/, "g");
var includes = new RegExp(INCLUIR.source, "g");
var content = editor.getValue();
var file;
while (file = includes.exec(content)) {
var files = all_files.archivos.filter(
function(a){
return a.nombre === file[1];
});
for (var f = 0; f < files.length; f++){
var seen = {};
var m;
var re_enums = new RegExp(ENUMS.source, "g");
var file_content = files[f].contenido;
while (m = re_enums.exec(file_content)) {
var enums = m[1].replace(/\s/g,'').split(',');
for (var i = 0; i < enums.length; i++) {
if (!re_digits.exec(enums[i]) && (!curWord || enums[i].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, enums[i])) {
seen[enums[i]] = true;
list.push(enums[i]);
}
}
}
}
}
}
function normal(source, setState) {
if (source.eatWhile(whiteCharRE)) {
return null;
......
......@@ -149,6 +149,9 @@
list.push(default_sets[i]);
}
}
// included sets
hintsSetsFromIncludedFiles(editor.options.files, editor, curWord, list);
}else{
// get variables of function
var previous_block = "";
......@@ -194,6 +197,8 @@
}
}
}
// included enums
hintsEnumsFromIncludedFiles(editor.options.files, editor, curWord, list);
// get functions
var re_funs = new RegExp(FUNS.source, "g");
for (var dir = -1; dir <= 1; dir += 2) {
......@@ -208,6 +213,8 @@
}
}
}
// included functions
hintsFunctionsFromIncludedFiles(editor.options.files, editor, curWord, list);
// add default functions
var default_functions = hintWords.ES_functions();
for (var i = 0; i < default_functions.length; i++) {
......@@ -224,6 +231,95 @@
return {list: list, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)};
});
var INCLUIR = /incluir\s+([\w\_\d]+)/;
function hintsFunctionsFromIncludedFiles(all_files, editor, curWord, list){
var re_digits = new RegExp(/^\d+$/, "g");
var includes = new RegExp(INCLUIR.source, "g");
var content = editor.getValue();
var file;
while (file = includes.exec(content)) {
var files = all_files.archivos.filter(
function(a){
return a.nombre === file[1];
});
for (var f = 0; f < files.length; f++){
var seen = {};
var m;
var re_funs = new RegExp(FUNS.source, "g");
var file_content = files[f].contenido;
while (m = re_funs.exec(file_content)) {
if (!re_digits.exec(m[1]) && (!curWord || m[1].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, m[1])) {
seen[m[1]] = true;
list.push(m[1]);
}
}
}
}
}
function hintsSetsFromIncludedFiles(all_files, editor, curWord, list){
var re_digits = new RegExp(/^\d+$/, "g");
var includes = new RegExp(INCLUIR.source, "g");
var content = editor.getValue();
var file;
while (file = includes.exec(content)) {
var files = all_files.archivos.filter(
function(a){
return a.nombre === file[1];
});
for (var f = 0; f < files.length; f++){
var seen = {};
var m;
var re_sets = new RegExp(SET.source, "g");
var file_content = files[f].contenido;
while (m = re_sets.exec(file_content)) {
if (!re_digits.exec(m[1]) && (!curWord || m[1].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, m[1])) {
seen[m[1]] = true;
list.push(m[1]);
}
}
}
}
}
function hintsEnumsFromIncludedFiles(all_files, editor, curWord, list){
var re_digits = new RegExp(/^\d+$/, "g");
var includes = new RegExp(INCLUIR.source, "g");
var content = editor.getValue();
var file;
while (file = includes.exec(content)) {
var files = all_files.archivos.filter(
function(a){
return a.nombre === file[1];
});
for (var f = 0; f < files.length; f++){
var seen = {};
var m;
var re_enums = new RegExp(ENUMS.source, "g");
var file_content = files[f].contenido;
while (m = re_enums.exec(file_content)) {
var enums = m[1].replace(/\s/g,'').split(',');
for (var i = 0; i < enums.length; i++) {
if (!re_digits.exec(enums[i]) && (!curWord || enums[i].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, enums[i])) {
seen[enums[i]] = true;
list.push(enums[i]);
}
}
}
}
}
}
function normal(source, setState) {
if (source.eatWhile(whiteCharRE)) {
return null;
......
......@@ -103,7 +103,8 @@ export class MateFunComponent {
hintOptions: {
completeSingle: false,
closeCharacters: /[^\d\w\_]/
}
},
files: null
};
themes = ['3024-day', '3024-night', 'abcdef', 'ambiance-mobile', 'ambiance', 'base16-dark', 'base16-light', 'bespin', 'blackboard', 'cobalt', 'colorforth', 'dracula', 'duotone-dark', 'duotone-light', 'eclipse', 'elegant', 'erlang-dark', 'hopscotch', 'icecoder', 'isotope', 'lesser-dark', 'liquibyte', 'material', 'mbo', 'mdn-like', 'midnight', 'monokai', 'neat', 'neo', 'night', 'panda-syntax', 'paraiso-dark', 'paraiso-light', 'pastel-on-dark', 'railscasts', 'rubyblue', 'seti', 'solarized', 'the-matrix', 'tomorrow-night-bright', 'tomorrow-night-eighties', 'ttcn', 'twilight', 'vibrant-ink', 'xq-dark', 'xq-light', 'yeti', 'zenburn']
version: string = npm.version;
......@@ -447,8 +448,10 @@ export class MateFunComponent {
archivoModificado(event){
if (this.hintsCheck && !event.ctrlKey && !event.altKey){
if (/^[\w\_\d]$/.test(event.key) || event.key == 'Enter')
if (/^[\w\_\d]$/.test(event.key) || event.key == 'Enter'){
this.codemirror.instance.options.files = this.archivosTree;
this.codemirror.instance.showHint(event);
}
if(this.copiaNombreArchivo!=this.archivo.nombre || this.copiaContenidoArchivo != this.archivo.contenido){
this.modificado = true;
}else{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment