[Sciviews-commits] r181 - komodo/SciViews-K komodo/SciViews-K/components komodo/SciViews-K/pylib pkg/svMisc pkg/svMisc/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Aug 29 11:45:52 CEST 2009
Author: phgrosjean
Date: 2009-08-29 11:45:50 +0200 (Sat, 29 Aug 2009)
New Revision: 181
Modified:
komodo/SciViews-K/components/svRinterpreter.js
komodo/SciViews-K/pylib/lang_r.py
komodo/SciViews-K/sciviewsk-0.8.1-ko.xpi
pkg/svMisc/DESCRIPTION
pkg/svMisc/NEWS
pkg/svMisc/R/Complete.R
Log:
Several corrections and improvements to code intelligence (i.e., calltips and autocomplete)
Modified: komodo/SciViews-K/components/svRinterpreter.js
===================================================================
--- komodo/SciViews-K/components/svRinterpreter.js 2009-08-26 10:18:41 UTC (rev 180)
+++ komodo/SciViews-K/components/svRinterpreter.js 2009-08-29 09:45:50 UTC (rev 181)
@@ -130,8 +130,10 @@
classes["@activestate.com/koViewService;1"].
getService(Components.interfaces.koIViewService);
var ke = kvSvc.currentView.document.getView().scimoz;
+ // Record current position (could change, because asynch trigger of autoC)
+ var lastPos = ke.anchor;
var cmd = 'Complete("' + code + '", print = TRUE, types = "scintilla")';
- koLogger.debug("R> " + cmd);
+ koLogger.debug("Complete: ..." + code.substring(code.length - 20));
var res = rCommand("<<<h>>>" + cmd, false, null,
function (autoCstring) {
// these should be set only once?:
@@ -139,12 +141,18 @@
//ke.autoCSetFillUps(" []{}<>/():;%+-*@!\t\n\r=$`");
var autoCSeparatorChar = String.fromCharCode(ke.autoCSeparator);
autoCstring = autoCstring.replace(/^(.*)[\r\n]+/, "");
-
- var trigPos = RegExp.$1;
- //var trigPos = RegExp.$1.split(/;/g)[1];
-
+ // Get length of the triggering text
+ var trigLen = parseInt(RegExp.$1);
+ koLogger.debug("trigLen: " + trigLen);
+ // Is something returned by Complete()?
+ if (isNaN(trigLen)) { return; }
+ // There is a bug (or feature?) in Complete(): if it returns all the code, better set trigLen to 0!
+ if (trigLen == code.length) { trigLen = 0; }
+ // TODO: we need to sort AutoCString with uppercase first
+ // otherwise, the algorithm does not find them (try: typing T, then ctrl+J, then R)
+ // TODO: there is a problem with items with special character (conversion problems)
autoCstring = autoCstring.replace(/\r?\n/g, autoCSeparatorChar);
-
+
// code below taken from "CodeIntelCompletionUIHandler"
// var iface = Components.interfaces.koICodeIntelCompletionUIHandler;
// ke.registerImage(iface.ACIID_FUNCTION, ko.markers.
@@ -157,8 +165,16 @@
// getPixmap("chrome://komodo/skin/images/ac_namespace.xpm"));
// ke.registerImage(iface.ACIID_KEYWORD, ko.markers.
// getPixmap("chrome://komodo/skin/images/ac_interface.xpm"));
- ke.autoCChooseSingle = true;
- ke.autoCShow(trigPos, autoCstring);
+ ke.autoCChooseSingle = false;
+ // Take into account if we entered more characters
+ Delta = ke.anchor - lastPos;
+ koLogger.debug("Delta: " + Delta);
+ // Only display completion list if 0 <= Delta < 5
+ // Otherwise, it means we moved away for the triggering area
+ // and we are in a different context, most probably
+ if (Delta >= 0 & Delta < 5) {
+ ke.autoCShow(Delta + trigLen, autoCstring);
+ }
}
);
return res;
@@ -179,7 +195,7 @@
.getService(Components.interfaces.koILoggingService);
var koLogger = koLogging.getLogger("svRinterpreter");
-koLogger.setLevel(koLogging.DEBUG);
+//koLogger.setLevel(koLogging.DEBUG);
//// Komodo preferences access /////////////////////////////////////////////////
@@ -224,6 +240,8 @@
this.rCommand("<<<h>>>cat(localeToCharset()[1])", false, null,
function (s) {
+ // TODO: check s first, otherwise, we got an exception in next
+ // command if R is not running
this.converter.charset = s;
koLogger.debug("R character set is " + s);
}
Modified: komodo/SciViews-K/pylib/lang_r.py
===================================================================
--- komodo/SciViews-K/pylib/lang_r.py 2009-08-26 10:18:41 UTC (rev 180)
+++ komodo/SciViews-K/pylib/lang_r.py 2009-08-29 09:45:50 UTC (rev 181)
@@ -53,15 +53,11 @@
from codeintel2.common import *
from codeintel2.citadel import CitadelBuffer, CitadelLangIntel
from codeintel2.langintel import LangIntel
-from codeintel2.langintel import (ParenStyleCalltipIntelMixin,
- ProgLangTriggerIntelMixin)
+from codeintel2.langintel import ParenStyleCalltipIntelMixin, ProgLangTriggerIntelMixin
from codeintel2.udl import UDLLexer
from codeintel2.util import CompareNPunctLast
-from SilverCity.ScintillaConstants import (
- SCE_UDL_SSL_DEFAULT, SCE_UDL_SSL_IDENTIFIER,
- SCE_UDL_SSL_OPERATOR, SCE_UDL_SSL_VARIABLE, SCE_UDL_SSL_WORD,
-)
+from SilverCity.ScintillaConstants import SCE_UDL_SSL_DEFAULT, SCE_UDL_SSL_IDENTIFIER, SCE_UDL_SSL_OPERATOR, SCE_UDL_SSL_VARIABLE, SCE_UDL_SSL_WORD, SCE_UDL_SSL_COMMENT, SCE_UDL_SSL_COMMENTBLOCK
try:
from xpcom.server import UnwrapObject
@@ -2697,8 +2693,8 @@
lang = lang
# Used by ProgLangTriggerIntelMixin.preceding_trg_from_pos()
- trg_chars = tuple('$@[') # Could also add ','
- calltip_trg_chars = tuple('(') # Idem here
+ trg_chars = tuple('$@[( ')
+ calltip_trg_chars = tuple('(')
##
# Implicit triggering event, i.e. when typing in the editor.
@@ -2715,6 +2711,34 @@
style = accessor.style_at_pos(last_pos)
if DEBUG:
print "trg_from_pos: char: %r, style: %d" % (char, accessor.style_at_pos(last_pos), )
+ if char == " " and (not (style in (SCE_UDL_SSL_COMMENT, SCE_UDL_SSL_COMMENTBLOCK))):
+ # Look the char just before all spaces, tabs or carriage return
+ # We do not trigger it if we are in a comment!
+ p = last_pos-1
+ min_p = max(0, p-500) # Don't bother looking more than 500 chars
+ if DEBUG:
+ print "Checking char just before spaces"
+ while p >= min_p:
+ #accessor.style_at_pos(p) in jsClassifier.comment_styles:
+ ch = accessor.char_at_pos(p)
+ st = accessor.style_at_pos(p)
+ p -= 1
+ if (not (ch in " \t\v\r\n")) and \
+ (not (st in (SCE_UDL_SSL_COMMENT, SCE_UDL_SSL_COMMENTBLOCK))):
+ break
+ if ch == ",":
+ # Calculate a completion list for function arguments
+ if DEBUG:
+ print "triggered:: complete arguments"
+ return Trigger(self.lang, TRG_FORM_CPLN, "arguments",
+ pos, implicit)
+ elif ch == "=":
+ # TODO: Try to provide correct completion for function arguments
+ if DEBUG:
+ print "triggered:: complete identifiers"
+ return Trigger(self.lang, TRG_FORM_CPLN, "identifiers",
+ pos, implicit)
+ return None
if char == '$' or char == '@':
# Variable completion trigger.
if DEBUG:
@@ -2762,6 +2786,34 @@
if DEBUG:
print "pos: %d, curr_pos: %d" % (pos, curr_pos)
print "char: %r, style: %d" % (char, style)
+ if char == " " and (not (style in (SCE_UDL_SSL_COMMENT, SCE_UDL_SSL_COMMENTBLOCK))):
+ # Look the char just before all spaces, tabs or carriage return
+ # We do not trigger it if we are in a comment!
+ p = last_pos-1
+ min_p = max(0, p-500) # Don't bother looking more than 500 chars
+ if DEBUG:
+ print "Checking char just before spaces"
+ while p >= min_p:
+ #accessor.style_at_pos(p) in jsClassifier.comment_styles:
+ ch = accessor.char_at_pos(p)
+ st = accessor.style_at_pos(p)
+ p -= 1
+ if (not (ch in " \t\v\r\n")) and \
+ (not (st in (SCE_UDL_SSL_COMMENT, SCE_UDL_SSL_COMMENTBLOCK))):
+ break
+ if ch == ",":
+ # Calculate a completion list for function arguments
+ if DEBUG:
+ print "triggered:: complete arguments"
+ return Trigger(self.lang, TRG_FORM_CPLN, "arguments",
+ pos, implicit=False)
+ elif ch == "=":
+ # TODO: Try to provide correct completion for function arguments
+ if DEBUG:
+ print "triggered:: complete identifiers"
+ return Trigger(self.lang, TRG_FORM_CPLN, "identifiers",
+ pos, implicit=False)
+ return None
if char == '$'or char == '@':
return Trigger(self.lang, TRG_FORM_CPLN, "variables",
pos, implicit=False)
@@ -2773,7 +2825,7 @@
if DEBUG:
print "triggered:: function calltip"
return Trigger(self.lang, TRG_FORM_CALLTIP,
- "call-signature", pos, implicit)
+ "call-signature", pos, implicit=False)
elif style in (SCE_UDL_SSL_VARIABLE, ):
start, end = accessor.contiguous_style_range_from_pos(last_pos)
if DEBUG:
@@ -2799,8 +2851,6 @@
##
# Provide the list of completions or the calltip string.
# Completions are a list of tuple (type, name) items.
- #
- # Note: This example is *not* asynchronous.
def async_eval_at_trg(self, buf, trg, ctlr):
if _xpcom_:
trg = UnwrapObject(trg)
@@ -2829,10 +2879,18 @@
self._autocomplete(buf, start, end)
ctlr.done("success")
return
+
+ if trg.id == (self.lang, TRG_FORM_CPLN, "arguments"):
+ # Return all arguments of current function.
+ #ctlr.set_cplns(self._get_all_known_arguments(buf))
+ self._autocomplete(buf, pos, pos)
+ ctlr.done("success")
+ return
if trg.id == (self.lang, TRG_FORM_CALLTIP, "call-signature"):
# Get function calltip.
- working_text = buf.accessor.text_range(max(0, pos-50), pos-1)
+ working_text = buf.accessor.text_range(max(0, pos-500), pos-1)
+ complete_zone = buf.accessor.text_range(pos, pos)
calltip = R.calltip(working_text)
# This is done asynchronously by the R.calltip() function
#if calltip:
@@ -2849,7 +2907,7 @@
def _autocomplete(self, buf, start, end):
# Get autocompletion list.
- working_text = buf.accessor.text_range(max(0, start-50), end)
+ working_text = buf.accessor.text_range(max(0, start-500), end)
complete_zone = buf.accessor.text_range(start, end)
complete = R.complete(working_text)
return complete
Modified: komodo/SciViews-K/sciviewsk-0.8.1-ko.xpi
===================================================================
(Binary files differ)
Modified: pkg/svMisc/DESCRIPTION
===================================================================
--- pkg/svMisc/DESCRIPTION 2009-08-26 10:18:41 UTC (rev 180)
+++ pkg/svMisc/DESCRIPTION 2009-08-29 09:45:50 UTC (rev 181)
@@ -4,8 +4,8 @@
Imports: utils, methods
Depends: R (>= 2.6.0)
Description: Supporting functions for the GUI API (various utilitary functions)
-Version: 0.9-52
-Date: 2009-08-10
+Version: 0.9-53
+Date: 2009-08-29
Author: Philippe Grosjean, Romain Francois & Kamil Barton
Maintainer: Philippe Grosjean <phgrosjean at sciviews.org>
License: GPL (>= 2)
Modified: pkg/svMisc/NEWS
===================================================================
--- pkg/svMisc/NEWS 2009-08-26 10:18:41 UTC (rev 180)
+++ pkg/svMisc/NEWS 2009-08-29 09:45:50 UTC (rev 181)
@@ -1,5 +1,11 @@
= svMisc News
+== Changes in svMisc 0.9-53
+
+* Complete() now sorts items alphabetically and does not return completions
+ as factor type in the data frame any more.
+
+
== Changes in svMisc 0.9-52
* Complete() now manages cases where code is like "iris[", "iris[[", or where
Modified: pkg/svMisc/R/Complete.R
===================================================================
--- pkg/svMisc/R/Complete.R 2009-08-26 10:18:41 UTC (rev 180)
+++ pkg/svMisc/R/Complete.R 2009-08-29 09:45:50 UTC (rev 181)
@@ -4,6 +4,8 @@
ComplEnv <- utils:::.CompletionEnv
finalize <- function (completions) {
+ # Sort completion items alphabetically
+ completions <- sort(completions)
if (add.types) {
tl <- numeric(length(completions))
tl[grep(" = $", completions)] <- 4L
@@ -14,7 +16,8 @@
tl[i] <- ifelse(sapply(completions[i],
function(x) existsFunction(x)), 1L, 2L)
tl <- factor(tl, levels = 1:5, labels = types)
- ret <- data.frame(completion = completions, type = tl)
+ ret <- data.frame(completion = completions, type = tl,
+ stringsAsFactors = FALSE)
} else {
ret <- completions
}
More information about the Sciviews-commits
mailing list