[rkward] rkward/windows: Fix detection of call end

Thomas Friedrichsmeier null at kde.org
Fri Feb 22 17:19:06 GMT 2019


Git commit c3092dfb96ee9ad3bdc76be00f3e5b3c7b2f8e2c by Thomas Friedrichsmeier.
Committed on 22/02/2019 at 17:12.
Pushed by tfry into branch 'master'.

Fix detection of call end

M  +19   -7    rkward/windows/rkcodecompletion.cpp

https://commits.kde.org/rkward/c3092dfb96ee9ad3bdc76be00f3e5b3c7b2f8e2c

diff --git a/rkward/windows/rkcodecompletion.cpp b/rkward/windows/rkcodecompletion.cpp
index df1cf176..038160a0 100644
--- a/rkward/windows/rkcodecompletion.cpp
+++ b/rkward/windows/rkcodecompletion.cpp
@@ -180,15 +180,24 @@ void RKCompletionManager::tryCompletion () {
 	updateVisibility ();
 }
 
+bool isCode (KTextEditor::Document* doc, int line, int column) {
+	KTextEditor::DefaultStyle style = doc->defaultStyleAt (KTextEditor::Cursor (line, column));
+	if (style == KTextEditor::dsComment) return false;
+	if (style == KTextEditor::dsString) return false;
+	if (style == KTextEditor::dsChar) return false;
+	return true;
+}
+
 void RKCompletionManager::updateCallHint () {
 	RK_TRACE (COMMANDEDITOR);
 
-	if (!update_call) return;
+	if (active && !update_call) return;
 	update_call = false;
 
 	int line = cached_position.line () + 1;
 	QString full_context;
 	int potential_symbol_end = -2;
+	int parenthesis_level = 0;
 	KTextEditor::Document *doc = _view->document ();
 	while (potential_symbol_end < -1 && line >= 0) {
 		--line;
@@ -201,10 +210,15 @@ void RKCompletionManager::updateCallHint () {
 		for (int i = pos; i >= 0; --i) {
 			QChar c = context_line.at (i);
 			if (c == '(') {
-				KTextEditor::DefaultStyle style = doc->defaultStyleAt (KTextEditor::Cursor (line, i));
-				if (style != KTextEditor::dsComment && style != KTextEditor::dsString && style != KTextEditor::dsChar) {
-					potential_symbol_end = i - 1;
-					break;
+				if (isCode (doc, line, i)) {
+					if (--parenthesis_level < 0) {
+						potential_symbol_end = i - 1;
+						break;
+					}
+				}
+			} else if (c == ')') {
+				if (isCode (doc, line, i)) {
+					++parenthesis_level;
 				}
 			}
 		}
@@ -270,8 +284,6 @@ void RKCompletionManager::updateVisibility () {
 		cc_iface->abortCompletion ();
 		active = false;
 	}
-
-	if (!active) update_call = true;
 }
 
 void RKCompletionManager::textInserted (KTextEditor::Document*, const KTextEditor::Cursor& position, const QString& text) {



More information about the rkward-tracker mailing list