sphaerophoria/atom-rtags-plus

showing relative file path in "Rtags References" window

Opened this issue · 1 comments

Currently the absolute path is shown in the "Rtags References" window. In case the absolute path is long, the second column could get shifted to the far left, sometimes it can go outside of the visible area, which will require user to use the scrollbar to see the second column.

Showing relative file path in the first column, can allow user to see both the file path and the reference in one visible area, which would be a great improvement in usability.

Cheers.

I also find this small utility to shorten path on stackoverflow.

https://stackoverflow.com/a/46361872/622496

function pathShorten(str, maxLength, removeFilename) {
    var splitter = str.indexOf('/')>-1 ? '/' : "\\",
        tokens = str.split(splitter), 
        removeFilename = !!removeFilename,
        maxLength = maxLength || 25,
        drive = str.indexOf(':')>-1 ? tokens[0] : "",  
        fileName = tokens[tokens.length - 1],
        len = removeFilename ? drive.length  : drive.length + fileName.length,    
        remLen = maxLength - len - 5, // remove the current lenth and also space for 3 dots and 2 slashes
        path, lenA, lenB, pathA, pathB;    
    //remove first and last elements from the array
    tokens.splice(0, 1);
    tokens.splice(tokens.length - 1, 1);
    //recreate our path
    path = tokens.join(splitter);
    //handle the case of an odd length
    lenA = Math.ceil(remLen / 2);
    lenB = Math.floor(remLen / 2);
    //rebuild the path from beginning and end
    pathA = path.substring(0, lenA);
    pathB = path.substring(path.length - lenB);
    path = drive + splitter + pathA + "..." + pathB + splitter ;
    path = path + (removeFilename ? "" : fileName); 
    //console.log(tokens, maxLength, drive, fileName, len, remLen, pathA, pathB);
    return path;
}

With the above function, here is the small hack I'm using for now.

git diff lib/view/references-tree-view.coffee                                                                                         # ~/.atom/packages/atom-rtags-plus
diff --git a/lib/view/references-tree-view.coffee b/lib/view/references-tree-view.coffee
index 3be7090..9702fa5 100644
--- a/lib/view/references-tree-view.coffee
+++ b/lib/view/references-tree-view.coffee
@@ -103,7 +103,7 @@ class RtagsReferenceNode extends Node
 
     else
       keyView = $(document.createElement('span'))
-      keyView.text("#{@data.path}:#{displayLine}:#{displayColumn}")
+      keyView.text("#{util.pathShorten(@data.path.substr(27), 36, false)}:#{displayLine}:#{displayColumn}")
       @expander.hide()
 
     contentView = $(document.createElement('td')).addClass('text-highlight').css('white-space', 'nowrap').width('100%')