[rkward] rkward/windows: Fix some file name completion problems

Thomas Friedrichsmeier null at kde.org
Sat May 2 12:24:39 BST 2020


Git commit c766af0340fca47f4f6ec71f56b9de96a21f7eb5 by Thomas Friedrichsmeier.
Committed on 02/05/2020 at 11:23.
Pushed by tfry into branch 'master'.

Fix some file name completion problems
- Race condition, when completing on dir with many files
- Occasionally wrong range getting replaced.

M  +14   -1    rkward/windows/rkcodecompletion.cpp
M  +2    -1    rkward/windows/rkcodecompletion.h

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

diff --git a/rkward/windows/rkcodecompletion.cpp b/rkward/windows/rkcodecompletion.cpp
index 109ac112..1d3628bc 100644
--- a/rkward/windows/rkcodecompletion.cpp
+++ b/rkward/windows/rkcodecompletion.cpp
@@ -130,7 +130,6 @@ void RKCompletionManager::userTriggeredCompletion () {
 }
 
 void RKCompletionManager::tryCompletion () {
-	// TODO: merge this with RKConsole::doTabCompletion () somehow
 	RK_TRACE (COMMANDEDITOR);
 	if (!cc_iface) {
 		// NOTE: This should not be possible, because the connections  have not been set up in the constructor, in this case.
@@ -176,6 +175,7 @@ void RKCompletionManager::tryCompletion () {
 		completion_model->updateCompletionList (QString ());
 		file_completion_model->updateCompletionList (QString ());
 	}
+	RK_DEBUG(EDITOR, DL_DEBUG, "completion symbol range %d, %d -> %d, %d", symbol_range.start().line(), symbol_range.start().column(), symbol_range.end().line(), symbol_range.end().column());
 
 	updateCallHint ();
 
@@ -489,6 +489,12 @@ int RKCompletionModelBase::rowCount (const QModelIndex& parent) const {
 	return 0;  // no children on completion entries
 }
 
+void RKCompletionModelBase::executeCompletionItem (KTextEditor::View *view, const KTextEditor::Range & word, const QModelIndex &index) const {
+// I have no idea, why this is needed at all, but sometimes (and inconsitently!) the default implementation will replace the wrong range, without this.
+// Importantly, the RKFileCompletionModel replaces with the wrong range, the *second* time it gets called.
+	KTextEditor::CodeCompletionModel::executeCompletionItem(view, const_cast<RKCompletionModelBase*>(this)->completionRange(view, word.end()), index);
+}
+
 //////////////////////// RKCodeCompletionModel ////////////////////
 
 RKCodeCompletionModel::RKCodeCompletionModel (RKCompletionManager *manager) : RKCompletionModelBase (manager) {
@@ -793,6 +799,9 @@ void RKFileCompletionModelWorker::run () {
 	KUrlCompletion comp;
 	comp.setDir (QUrl::fromLocalFile (QDir::currentPath ()));
 	comp.makeCompletion (string);
+	while (comp.isRunning()) {
+		msleep(50);
+	}
 	QStringList files = comp.allMatches ();
 
 	QStringList exes;
@@ -851,6 +860,10 @@ void RKFileCompletionModel::completionsReady (const QString& string, const QStri
 	}
 }
 
+KTextEditor::Range RKFileCompletionModel::completionRange (KTextEditor::View *, const KTextEditor::Cursor &) {
+	return manager->currentSymbolRange ();
+}
+
 QVariant RKFileCompletionModel::data (const QModelIndex& index, int role) const {
 	if (isHeaderItem (index)) {
 		if (role == Qt::DisplayRole) return i18n ("Local file names");
diff --git a/rkward/windows/rkcodecompletion.h b/rkward/windows/rkcodecompletion.h
index 33325dae..1604cd88 100644
--- a/rkward/windows/rkcodecompletion.h
+++ b/rkward/windows/rkcodecompletion.h
@@ -98,7 +98,7 @@ public:
 	QString filterString (KTextEditor::View *, const KTextEditor::Range &, const KTextEditor::Cursor &) override { return QString (); };
 	bool shouldAbortCompletion (KTextEditor::View *, const KTextEditor::Range &, const QString &) override { return false; }
 	KTextEditor::CodeCompletionModelControllerInterface::MatchReaction matchingItem (const QModelIndex &) override { return KTextEditor::CodeCompletionModelControllerInterface::None; };
-
+	void executeCompletionItem (KTextEditor::View *view, const KTextEditor::Range & word, const QModelIndex &index) const override;
 	int rowCount (const QModelIndex &parent) const override;
 	QModelIndex index (int row, int column, const QModelIndex &parent = QModelIndex ()) const override;
 	QModelIndex parent (const QModelIndex &index) const override;
@@ -185,6 +185,7 @@ public:
 	explicit RKFileCompletionModel (RKCompletionManager *manager);
 	~RKFileCompletionModel ();
 
+	KTextEditor::Range completionRange (KTextEditor::View *view, const KTextEditor::Cursor &position) override;
 	void updateCompletionList (const QString& fragment);
 	QVariant data (const QModelIndex& index, int role=Qt::DisplayRole) const override;
 	QString partialCompletion (bool *exact);



More information about the rkward-tracker mailing list