https://bugs.kde.org/show_bug.cgi?id=524829

--- Comment #1 from Md. Jobayed Islam <[email protected]> ---
I think I found the cause and a possible solution to this. The gist of it is:
The language server percent encodes characters like + to %2B which causes a
mismatch with doc->url(), and DiagnosticsView::addMarksRec() returns early
without drawing underlines. Decoding the file path before the check fixes it
for me. Removing the false from urlFromRemote(..., false) in parseDiagnostics()
also fixes the problem but breaks symlinks. I didn't test for remote files or
on windows.

In apps/lib/diagnostics/diagnosticview.cpp:1251 DiagnosticsView::addMarksRec()
function, an if statement checks if the current document URL does not match the
URL sent with the LSP response. If it's true then the function quits and the
underlines (marks) are never drawn. This happens because in the case of file
paths containing the special characters I mentioned, they get percent encoded
by the language server, so they never match the current document's URL returned
by doc->url().

One possible solution I found was earlier in the data flow, where the server
response is being parsed. In addons/lspclient/lspclientserver.cpp:1245
parseDiagnostics() function, the uri is being set with urlFromRemote(), which
by default normalizes the URL. But for some reason the normalization parameter
is set to false here. Removing the false parameter solves the problem, but it
breaks underlines for symlinked files. Because normalizeUrl() resolves those
symlinks and returns the actual file URL. This again causes a mismatch with
doc->url() and the underlines get skipped.

To solve this symlink problem I skipped the whole normalization path
alltogether and opted to just decode the file path in
DiagnosticsView::addMarksRec() instead.

diff --git a/apps/lib/diagnostics/diagnosticview.cpp
b/apps/lib/diagnostics/diagnosticview.cpp
index 66e0af209e..c59e67c5b4 100644
--- a/apps/lib/diagnostics/diagnosticview.cpp
+++ b/apps/lib/diagnostics/diagnosticview.cpp
@@ -1247,8 +1247,14 @@ void DiagnosticsView::addMarks(KTextEditor::Document
*doc, QStandardItem *item)
 void DiagnosticsView::addMarksRec(KTextEditor::Document *doc, QStandardItem
*item)
 {
     Q_ASSERT(item);
+
+    QUrl itemUrl = item->data(Qt::UserRole).toUrl();
+    if (itemUrl.isLocalFile()) {
+        itemUrl = QUrl::fromLocalFile(itemUrl.toLocalFile());
+    }
+
     // We only care about @p doc items
-    if (item->type() == DiagnosticItem_File &&
item->data(Qt::UserRole).toUrl() != doc->url()) {
+    if (item->type() == DiagnosticItem_File && itemUrl != doc->url()) {
         return;
     }
     addMarks(doc, item);

This patch works for both regular and symlinked files.

Another thing to note is that, DiagnosticsView::addMarks(KTextEditor::Document
*doc, QStandardItem *item) already compares decoded strings. This was added for
the earlier report about + in file names (bug: 496361). But addMarksRec() still
compares raw QUrls. So adopting something like that would probably be a better
fix.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to