Skip to content

Commit

Permalink
Using new WebIntellisense (maybe a little buggy still)
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Rosconi committed Jul 13, 2014
1 parent 9001a01 commit 80fd683
Show file tree
Hide file tree
Showing 12 changed files with 1,310 additions and 163 deletions.
3 changes: 2 additions & 1 deletion IfSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "static", "static", "{45519D
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "custom", "custom", "{3AAFA64D-CBB6-488E-B395-6A1E7CB554CE}"
ProjectSection(SolutionItems) = preProject
ipython-profile\static\custom\codemirror-intellisense.js = ipython-profile\static\custom\codemirror-intellisense.js
ipython-profile\static\custom\custom.css = ipython-profile\static\custom\custom.css
ipython-profile\static\custom\custom.js = ipython-profile\static\custom\custom.js
ipython-profile\static\custom\fsharp.js = ipython-profile\static\custom\fsharp.js
ipython-profile\static\custom\ifsharp_logo.png = ipython-profile\static\custom\ifsharp_logo.png
ipython-profile\static\custom\webintellisense-codemirror.js = ipython-profile\static\custom\webintellisense-codemirror.js
ipython-profile\static\custom\webintellisense.js = ipython-profile\static\custom\webintellisense.js
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "files", "files", "{F420A7BF-AF5F-4C69-99D3-C0DA09FA1F19}"
Expand Down
119 changes: 119 additions & 0 deletions ipython-profile/static/custom/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,125 @@ th {
background-color: #ececec;
}

.br-intellisense {
min-width: 220px;
max-height: 176px;
min-height: 22px;
z-index: 10;
overflow: auto;
position: absolute;
background-color: white;
border: 1px solid #E5C365;
box-shadow: 2px 3px 5px rgba(0, 0, 0, .2);
padding: 0;
margin: 5px;
display: none;
-moz-user-select: none;
-ms-user-select: none;
-webkit-user-select: none;
user-select: none;
}

.br-documentation {
min-width: 200px;
padding: 3px;
overflow: auto;
position: absolute;
z-index: 10;
background-color: #E7E8EC;
border: 1px solid #CCCEDB;
box-shadow: 2px 3px 5px rgba(0,0,0,.2);
font-family: 'Segoe UI';
font-size: 10pt;
white-space: pre-line;
display: none;
}

.br-listlink {
font-family: 'Segoe UI';
font-size: 10pt;
list-style: none;
cursor: pointer;
border: 1px solid white;
white-space: nowrap;
overflow: hidden;
}

.br-listlink:hover {
background-color: #FDF4BF;
}

.br-selected {
background-color: #FDF4BF;
border: 1px dotted black;
}

.br-icon {
width: 16px;
height: 16px;
display: inline-block;
vertical-align: text-top;
margin: 2px;
}

.br-methods {
min-width: 220px;
min-height: 22px;
z-index: 10;
padding: 3px;
overflow: auto;
position: absolute;
background-color: #E7E8EC;
border: 1px solid #CCCEDB;
margin: 5px;
display: none;
font-family: 'Segoe UI';
font-size: 10pt;
}

.br-methods-text {
margin-left: 75px;
}

.br-methods-arrows {
width: 75px;
float: left;
font-family: Calibri;
font-weight: bold;
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

.br-methods-arrow {
cursor: pointer;
}

.br-methods-arrow-text {
font-weight: normal;
margin-left: 2px;
margin-right: 2px;
}

.br-tooltip {
min-width: 220px;
max-height: 176px;
min-height: 22px;
z-index: 10;
position: absolute;
background-color: #E7E8EC;
border: 1px solid #CCCEDB;
box-shadow: 2px 3px 5px rgba(0, 0, 0, .2);
padding: 5px;
margin: 5px;
display: none;
font-size: 12px;
font-family: Monaco, Menlo, 'Ubuntu Mono', Consolas, source-code-pro, monospace;
overflow: auto;
}

.br-errormarker {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAQCAYAAAAxtt7zAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAadEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My41LjExR/NCNwAAABdJREFUKFNjGNbgPxihAZggiiSEw8AAAMxEB/k37k01AAAAAElFTkSuQmCC);
background-repeat: repeat-x;
Expand Down
22 changes: 17 additions & 5 deletions ipython-profile/static/custom/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ $([IPython.events]).on('app_initialized.NotebookApp', function ()
return results;
}

require(['custom/codemirror-intellisense'], function ()
require(['custom/webintellisense', 'custom/webintellisense-codemirror'], function ()
{
// applies intellisense hooks onto a cell
function applyIntellisense(cell)
Expand All @@ -75,19 +75,31 @@ $([IPython.events]).on('app_initialized.NotebookApp', function ()
var editor = cell.code_mirror;
if (editor.intellisense == null)
{
var intellisense = new CodeMirrorIntellisense(editor);
cell.force_highlight('fsharp');
cell.code_mirror.setOption('theme', 'neat');
editor.intellisense = new Intellisense(editor, function (callback, position)
editor.intellisense = intellisense;

intellisense.addDeclarationTrigger({ keyCode: 190 }); // `.`
intellisense.addDeclarationTrigger({ keyCode: 32, ctrlKey: true, preventDefault: true, type: 'down' }); // `ctrl+space`
intellisense.addMethodsTrigger({ keyCode: 57, shiftKey: true }); // `(`
intellisense.addMethodsTrigger({ keyCode: 48, shiftKey: true });// `)`
intellisense.addMethodsTrigger({ keyCode: 8 }); // `backspace`
intellisense.onMethod(function (item, position)
{

});
intellisense.onDeclaration(function (item, position)
{
var cells = getCodeCells();
var codes = cells.codes;
var cursor = cells.selectedCell.code_mirror.doc.getCursor();
var callbacks = { shell: {}, iopub: {} };

// v2
callbacks.shell.reply = function (data)
callbacks.shell.reply = function (msg)
{
callback(data.content.matches);
intellisense.setDeclarations(msg.content.matches);
};

callbacks.iopub.output = function (msg)
Expand All @@ -98,7 +110,7 @@ $([IPython.events]).on('app_initialized.NotebookApp', function ()
// v1
callbacks.complete_reply = function (data)
{
callback(data.matches);
intellisense.setDeclarations(data.matches);
};

callbacks.output = function (msgType, content, metadata)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,150 +1,5 @@
var Intellisense = function (editor, userCallback)
{
function getDocumentHead(doc)
{
doc = doc || document;
return doc.head || doc.getElementsByTagName("head")[0] || doc.documentElement;
}

function hasCssString(id, doc)
{
var index = 0, sheets;
doc = doc || document;

if (doc.createStyleSheet && (sheets = doc.styleSheets))
{
while (index < sheets.length)
if (sheets[index++].owningElement.id === id) return true;
}
else if ((sheets = doc.getElementsByTagName("style")))
{
while (index < sheets.length)
if (sheets[index++].id === id) return true;
}
return false;
}

function importCssString(cssText, id, doc)
{
doc = doc || document;
// If style is already imported return immediately.
if (id && hasCssString(id, doc))
return null;

if (doc.createStyleSheet)
{
var style = doc.createStyleSheet();
style.cssText = cssText;
if (id) style.owningElement.id = id;
}
else
{
var style = doc.createElement("style");
style.appendChild(doc.createTextNode(cssText));
if (id) style.id = id;
getDocumentHead(doc).appendChild(style);
}
}

// check to see if an element has a css class
function hasCssClass(el, name)
{
var classes = el.className.split(/\s+/g);
return classes.indexOf(name) !== -1;
}

// adds a css class from an element
function addCssClass(el, name)
{
if (!hasCssClass(el, name))
{
el.className += " " + name;
}
}

// removes a css class from an element
function removeCssClass(el, name)
{
var classes = el.className.split(/\s+/g);
while (true)
{
var index = classes.indexOf(name);
if (index == -1)
{
break;
}
classes.splice(index, 1);
}
el.className = classes.join(" ");
}

function lastIndexOfAny(str, arr, start)
{
var max = -1;
for (var i = 0; i < arr.length; i++)
{
var val = str.lastIndexOf(arr[i], start);
max = Math.max(max, val);
}
return max;
}

var cssText =
".br-intellisense {" +
" min-width: 220px;" +
" max-height: 176px;" +
" min-height: 22px;" +
" z-index: 10;" +
" padding: 0;" +
" overflow: auto;" +
" position: absolute;" +
" background-color: white;" +
" border: 1px solid #E5C365;" +
" box-shadow: 2px 3px 5px rgba(0, 0, 0, .2);" +
" padding: 0;" +
" margin: 5px;" +
" display: none;" +
"}" +
".br-documentation {" +
" min-width: 200px;" +
" padding: 3px;" +
" overflow: auto;" +
" position: absolute;" +
" z-index: 10;" +
" background-color: #E7E8EC;" +
" border: 1px solid #CCCEDB;" +
" box-shadow: 2px 3px 5px rgba(0,0,0,.2);" +
" font-family: 'Segoe UI';" +
" font-size: 10pt;" +
" white-space: pre-line;" +
" display: none;" +
"}" +
".br-listlink {" +
" font-family: 'Segoe UI';" +
" font-size: 10pt;" +
" list-style: none;" +
" cursor: pointer;" +
" border: 1px solid white;" +
" white-space: nowrap;" +
" overflow: hidden;" +
"}" +
".br-listlink:hover {" +
" background-color: #FDF4BF;" +
"}" +
".br-selected {" +
" background-color: #FDF4BF;" +
" border: 1px dotted black;" +
"}" +
".br-icon {" +
" width: 16px;" +
" height: 16px;" +
" display: inline-block;" +
" vertical-align: text-top;" +
" margin: 2px;" +
"}";

importCssString(cssText, 'br-intellisense');

var self = this;

// data element
Expand Down
Loading

0 comments on commit 80fd683

Please sign in to comment.