From aab8550250d540f3c4c51411a2fa20ee139f6169 Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Sun, 18 Aug 2019 16:06:09 +0100 Subject: [PATCH] Index every 3 secs & improved, plus other tweaks --- lib/ice-coder.js | 53 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/lib/ice-coder.js b/lib/ice-coder.js index 5ef83c8..3b4cb35 100644 --- a/lib/ice-coder.js +++ b/lib/ice-coder.js @@ -65,6 +65,7 @@ var ICEcoder = { debounce: "", // Contains debounce timeout object editorFocusInstance: "", // Name of editor instance that has focus openSeconds: 0, // Number of seconds ICEcoder has been open for + indexing: false, // Indicates if ICEcoder is currently indexing ready: false, // Indicates if ICEcoder is ready for action // Set our aliases @@ -134,13 +135,15 @@ var ICEcoder = { if(!unsavedFiles && ICEcoder.autoLogoutMins > 0 && top.ICEcoder.autoLogoutTimer >= top.ICEcoder.autoLogoutMins*60) { top.ICEcoder.logout('autoLogout'); } - // Finally, increase number of seconds ICEcoder has been open for by 1 + // Increase number of seconds ICEcoder has been open for by 1 top.ICEcoder.openSeconds++; // Every 5 mins, ping our file to keep the session alive if (top.ICEcoder.openSeconds % 300 == 0) { top.ICEcoder.filesFrame.contentWindow.frames['pingActive'].location.href = "lib/session-active-ping.php"; } - if (top.ICEcoder.openSeconds % 1 == 0) { + // Every 3 seconds, re-index if we're not already busy + if (!top.ICEcoder.indexing && !top.ICEcoder.loadingFile && top.ICEcoder.serverQueueItems.length === 0 && top.ICEcoder.openSeconds % 3 == 0) { + top.ICEcoder.indexing = true; // Get new data fetch('lib/indexer.php') .then(function(response) { @@ -148,6 +151,7 @@ var ICEcoder = { return response.json(); }).then(function(data) { top.ICEcoder.indexData = data; + top.ICEcoder.indexing = false; }); } },1000); @@ -656,26 +660,31 @@ var ICEcoder = { // Get result and number of results for word in functions and classes from index JSON object list result = null; numResults = 0; - for(i in top.ICEcoder.indexData.functions) { + var filePath = top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1]; + var filePathExt = filePath.substr(filePath.lastIndexOf(".")+1); + for(i in top.ICEcoder.indexData.functions[filePathExt]) { if (i === word) { - result = top.ICEcoder.indexData.functions[i]; + result = top.ICEcoder.indexData.functions[filePathExt][i]; numResults++; } }; - for(i in top.ICEcoder.indexData.classes) { + for(i in top.ICEcoder.indexData.classes[filePathExt]) { if (i === word) { - result = top.ICEcoder.indexData.classes[i]; + result = top.ICEcoder.indexData.classes[filePathExt][i]; numResults++; } }; - // If we have a single result, we can jump to where it's defined - if (numResults === 1) { - top.ICEcoder.openFile(result.fullPath.replace(top.docRoot,"")); + // If we have a single result and the cursor isn't already on the definition of it we can jump to where it's defined + if (numResults === 1 && [null,"def"].indexOf(cM.getTokenTypeAt(cM.getCursor())) === -1) { + top.ICEcoder.openFile(result.filePath.replace(top.docRoot,"")); top.ICEcoder.goFindAfterOpenInt = setInterval(function(){ - if (top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1] == result.fullPath.replace(top.docRoot,"") && !top.ICEcoder.loadingFile) { + if (top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1] == result.filePath.replace(top.docRoot,"") && !top.ICEcoder.loadingFile) { cM = top.ICEcoder.getcMInstance(); - cM.setSelection({line: result.range.from.line, ch: result.range.from.ch}, {line: result.range.to.line, ch: result.range.to.ch}); + setTimeout(function() { + top.ICEcoder.goToLine(result.range.from.line+1); + cM.setSelection({line: result.range.from.line, ch: result.range.from.ch}, {line: result.range.to.line, ch: result.range.to.ch}); + },20); clearInterval(top.ICEcoder.goFindAfterOpenInt); } },20); @@ -725,26 +734,36 @@ var ICEcoder = { var coordsChar = cM.coordsChar({left: top.ICEcoder.mouseX-top.ICEcoder.maxFilesW, top: top.ICEcoder.mouseY-72}); var word = (cM.getRange(cM.findWordAt(coordsChar).anchor, cM.findWordAt(coordsChar).head)); + // If it's not a word, return early + if (word === "") { + get('tooltip').style.display = "none"; + return true; + } + // Get result and number of results for word in functions and classes from index JSON object list var result = null; var numResults = 0; - for(i in top.ICEcoder.indexData.functions) { + var filePath = top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1]; + var filePathExt = filePath.substr(filePath.lastIndexOf(".")+1); + for(i in top.ICEcoder.indexData.functions[filePathExt]) { if (i === word) { - result = top.ICEcoder.indexData.functions[i]; + result = top.ICEcoder.indexData.functions[filePathExt][i]; numResults++; } }; - for(i in top.ICEcoder.indexData.classes) { + for(i in top.ICEcoder.indexData.classes[filePathExt]) { if (i === word) { - result = top.ICEcoder.indexData.classes[i]; + result = top.ICEcoder.indexData.classes[filePathExt][i]; numResults++; } }; - // If we have a single result, and that result is for another file we can display the tooltip - if (numResults === 1 && result.fullPath.replace(top.docRoot,"") !== top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1]) { + + // If we have a single result and the mouse pointer is not over the definition of it (that would be pointless), show tooltip + if (numResults === 1 && [null,"def"].indexOf(cM.getTokenTypeAt(coordsChar)) === -1) { get('tooltip').style.display = "block"; get('tooltip').style.left = (top.ICEcoder.mouseX-top.ICEcoder.maxFilesW+10) + "px"; get('tooltip').style.top = (top.ICEcoder.mouseY-30) + "px"; + get('tooltip').style.zIndex = "1"; get('tooltip').innerHTML = result.params; // Else hide it } else {