From d74a58b3c8ff39dbc074fd8c827c65db9e2fcec0 Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Sun, 3 Jun 2012 11:36:07 +0200 Subject: [PATCH 1/4] [notebook] deduplicate completion results remove context completion that are duplicates from introspection completion fixes #1840 --- .../html/notebook/static/js/completer.js | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/completer.js b/IPython/frontend/html/notebook/static/js/completer.js index 636d6104a..c4966c514 100644 --- a/IPython/frontend/html/notebook/static/js/completer.js +++ b/IPython/frontend/html/notebook/static/js/completer.js @@ -116,12 +116,28 @@ var IPython = (function (IPython) { var cur = this.editor.getCursor(); var results = CodeMirror.contextHint(this.editor); + var filterd_results = Array(); + console.log('results',results) + //remove results from context completion + //that are already in kernel completion + for(var elm in results) + { + if(matches.indexOf(results[elm]['str']) == -1) + { + //filterd_results.push(elm); + console.log('adding',results[elm]) + } + else + { + console.log('skipping ',results[elm]); + } + } // append the introspection result, in order, at at the beginning of // the table and compute the replacement range from current cursor // positon and matched_text length. for (var i = matches.length - 1; i >= 0; --i) { - results.unshift({ + filterd_results.unshift({ str: matches[i], type: "introspection", from: { @@ -136,7 +152,7 @@ var IPython = (function (IPython) { } // one the 2 sources results have been merge, deal with it - this.raw_result = results; + this.raw_result = filterd_results; // if empty result return if (!this.raw_result || !this.raw_result.length) return; From 9cfdea0d1c2d495017d951809ed4bef4c1db1c02 Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Sun, 3 Jun 2012 13:18:43 +0200 Subject: [PATCH 2/4] take care of token starting by '.' (dot) --- .../html/notebook/static/js/completer.js | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/completer.js b/IPython/frontend/html/notebook/static/js/completer.js index c4966c514..358affcf5 100644 --- a/IPython/frontend/html/notebook/static/js/completer.js +++ b/IPython/frontend/html/notebook/static/js/completer.js @@ -9,7 +9,20 @@ var IPython = (function (IPython) { var key = IPython.utils.keycodes; // what is the common start of all completions - + function _existing_completion(item, completion_array) + { + if(item.substr(0,1) == '.') + { + for( var c in completion_array ) + { + if(completion_array[c].substr(-item.length) == item) + { return true; } + } + return false; + } + else + {return completion_array.indexOf(item) != -1} + } function shared_start(B) { if (B.length == 1) { @@ -117,19 +130,13 @@ var IPython = (function (IPython) { var cur = this.editor.getCursor(); var results = CodeMirror.contextHint(this.editor); var filterd_results = Array(); - console.log('results',results) //remove results from context completion //that are already in kernel completion for(var elm in results) { - if(matches.indexOf(results[elm]['str']) == -1) + if(_existing_completion(results[elm]['str'],matches) == false) { - //filterd_results.push(elm); - console.log('adding',results[elm]) - } - else - { - console.log('skipping ',results[elm]); + filterd_results.push(results[elm]); } } From 795cb7bb21f318a3f27b08c40170359cf8517b47 Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Mon, 4 Jun 2012 12:00:23 +0200 Subject: [PATCH 3/4] bracket on same line --- .../html/notebook/static/js/completer.js | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/completer.js b/IPython/frontend/html/notebook/static/js/completer.js index 358affcf5..f43d58cb9 100644 --- a/IPython/frontend/html/notebook/static/js/completer.js +++ b/IPython/frontend/html/notebook/static/js/completer.js @@ -9,19 +9,15 @@ var IPython = (function (IPython) { var key = IPython.utils.keycodes; // what is the common start of all completions - function _existing_completion(item, completion_array) - { - if(item.substr(0,1) == '.') - { - for( var c in completion_array ) - { + function _existing_completion(item, completion_array){ + if(item.substr(0,1) == '.') { + for( var c in completion_array ) { if(completion_array[c].substr(-item.length) == item) { return true; } } return false; } - else - {return completion_array.indexOf(item) != -1} + else {return completion_array.indexOf(item) != -1} } function shared_start(B) { @@ -132,12 +128,9 @@ var IPython = (function (IPython) { var filterd_results = Array(); //remove results from context completion //that are already in kernel completion - for(var elm in results) - { + for(var elm in results) { if(_existing_completion(results[elm]['str'],matches) == false) - { - filterd_results.push(results[elm]); - } + { filterd_results.push(results[elm]); } } // append the introspection result, in order, at at the beginning of From 567b6bbcd2a1b62c629946e4b60426fea680fb1d Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Tue, 5 Jun 2012 09:26:21 +0200 Subject: [PATCH 4/4] don't need to check for leading dot --- .../html/notebook/static/js/completer.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/completer.js b/IPython/frontend/html/notebook/static/js/completer.js index f43d58cb9..a51c8b079 100644 --- a/IPython/frontend/html/notebook/static/js/completer.js +++ b/IPython/frontend/html/notebook/static/js/completer.js @@ -8,18 +8,15 @@ var IPython = (function (IPython) { // easyier key mapping var key = IPython.utils.keycodes; - // what is the common start of all completions function _existing_completion(item, completion_array){ - if(item.substr(0,1) == '.') { - for( var c in completion_array ) { - if(completion_array[c].substr(-item.length) == item) - { return true; } - } - return false; - } - else {return completion_array.indexOf(item) != -1} + for( var c in completion_array ) { + if(completion_array[c].substr(-item.length) == item) + { return true; } + } + return false; } + // what is the common start of all completions function shared_start(B) { if (B.length == 1) { return B[0]; @@ -129,7 +126,7 @@ var IPython = (function (IPython) { //remove results from context completion //that are already in kernel completion for(var elm in results) { - if(_existing_completion(results[elm]['str'],matches) == false) + if(_existing_completion(results[elm]['str'], matches) == false) { filterd_results.push(results[elm]); } }