Quick open: support also line number notions "#Lll", "#nll", "#ll"

Authored by kossebau on Jan 13 2017, 2:31 AM.



Pasting a path extracted from a repo web link on cgit, github, gitlab, or lxr
to Quick Open currently needs manual editing of the line number notion.
This patch allows to open them directly.

Diff Detail

R33 KDevPlatform
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.
kossebau updated this revision to Diff 10118.Jan 13 2017, 2:31 AM
kossebau retitled this revision from to Quick open: support also line number notions "#Lll", "#nll", "#ll".
kossebau updated this object.
kossebau added a reviewer: KDevelop.
Restricted Application added a subscriber: kdevelop-devel. · View Herald TranscriptJan 13 2017, 2:31 AM
kfunk requested changes to this revision.Jan 13 2017, 8:15 AM
kfunk added a reviewer: kfunk.
kfunk added a subscriber: kfunk.

Please add tests in util/tests/test_texteditorhelpers.cpp.


Code looks a bit too branchy.

Maybe it'd make more sense if you'd just use on instance of QRegularExpressionMatch?

auto match = pattern.match(input);
if (!match.hasMatch()) {
    match2 = pattern.match(input);

// ... as before

For pattern2 match.captured(2).toInt() will always return 0, which should be handled fine by the original code.

This revision now requires changes to proceed.Jan 13 2017, 8:15 AM
kfunk added inline comments.Jan 13 2017, 8:17 AM

Meant match = pattern2.match(input); in line 3 of course...

kfunk added a comment.Jan 13 2017, 8:26 AM

Note: I'm wondering whether we should try to upstream this one way or the other to ktexteditor.git -- this feature (extract line + column numbers) from path-like strings is used in many places in both Kate & KTextEditor.

Another place: command-line handling, e.g. both kate and kdevelop accepted: kdevelop /path/to/file.cpp:100. The code which is currently handling this is https://github.com/KDE/kate/blob/master/urlinfo.h -- and I shamelessly copied that to kdevelop.git, too ;)

kfunk added a comment.Jan 13 2017, 9:38 AM

@kwrite-devel Please check whether a function such as this would make sense in ktexteditor.git:

struct UrlCursor
    QUrl url;
    Cursor cursor;
/// Parse @p pathLike input and extract the url part and the line/column information
/// Example: /path/to/file.cpp:111, /path/to/file.cpp#L111
KTextEditor::UrlCursor KTextEditorHelpers::extractCursor(const QString& pathLike);

This functionality is duplicated in at least kate + kdevelop, probaby other places, too.

Not sure where to put it and whether ktexteditor.git would be the right place to start with though.

This revision was automatically updated to reflect the committed changes.
kossebau marked 2 inline comments as done.