Skip to content

Open source file on KDE Invent instead of looking up on lxr.kde.org

Kisaragi Hiu requested to merge moonlight/lokalize:open-on-invent into master

The file context line in each PO entry often contain file and the line. However, the LXR lookup throws away the line information, slowing down context lookup a lot.

This MR replaces lookup on lxr.kde.org with project ID → Invent repo path lookup through https://projects.kde.org/api/. The new openKDEInvent function uses the https://projects.kde.org/api/v1/identifier/<id> api to retrieve the repository path, constructs a KDE Invent path out of it, then visits it with the system browser.

This allows the browser to open the line immediately, as well as reading the context on Invent rather than LXR, where it's harder to browse adjacent files.

Some potential issues and why I think they're not too bad:

  • Perhaps the KDE project id → repo path mapping could be embedded in Lokalize. This isn't good, as it means a new Lokalize release would be needed to see new projects.
  • This uses https://projects.kde.org/api/, and I'm not sure how actively supported this API is. This should be fine though, as it seems quite up-to-date and is apparently based on sysadmin/repo-metadata. - This MR currently uses on a questionable hack to work around some KDE projects' po files having context paths that aren't relative to the repository root. For instance, kate.po contains strings from both Kate and KWrite, and its context lines are relative to apps/.
    • This could be removed, and rely on asking projects to make sure their context lines are relative to the project root
    • Or it could be replaced with an authenticated search using the search API (GET https://invent.kde.org/api/v4/projects/utilities%2Fkate/search?scope=blobs&search=filename:kateexternaltoolsview.cpp, take the first response's path, then open the browser with that path + the line number)
    • Or the MR could fall back to using LXR if all requests saw 0 results
    • This now falls back to LXR if the file is not found at repo root, tested through KDE Invent's public GitLab API.
  • Opening the src link now requires two extra network requests. This is not an issue when not connected to the internet, as it also fails without this MR, and is still worth it when connected, as a long wait is better than context-switching to finding the line on LXR.
Edited by Kisaragi Hiu

Merge request reports