Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Results keyboard navigation, keyboard shortcuts and fixes #67

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Filios92
Copy link

@Filios92 Filios92 commented Feb 4, 2018

Hi,

Here's a bunch of features I added some time ago and would like to share, could be merged to master.

  • mainly keyboard navigation of results with vim-like j/k and with page up/page down. Also watching selection change for highlighting result on mouse click, as a side effect navigation with arrows also works :)
  • closing opened tabs/views with results with keyboard shortcut, I find it useful (["ctrl+l", "ctrl+x"])
  • keyboard shortcut for rebuilding database (["ctrl+l", "ctrl+f"])
  • fix for results such as the ones found in case statements ("case SYMBOL:") which were falling in the '(.*):$' regex. Changed in code and syntax file for Lookup Results
  • on rebuilding the database, when none is found, set root path to the first path in project paths, even if there is more than one
  • and if it has more than one treat the next ones as additional source dirs. Not 100% sure about use cases for that (except for mine), so made it an option, disabled by default

@vanrijn
Copy link
Collaborator

vanrijn commented Apr 5, 2018

Hi @Filios92!! I meant to answer months ago and got way behind. So sorry about that. Thanks so much for the patch! I'll look through this now. =:)

Copy link
Collaborator

@vanrijn vanrijn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate all the hard work you've done here, but you've submitted a large chunk of changes that are for different features. I'd rather review each piece of functionality individually. As I see it, the logical groups here are:

  1. Allow multiple project directories to be passed to cscope for database operations
  2. Add arguments to the CscopeVisiter class so that movement can be added
  3. Add keybindings and commands for the above
  4. Change the way results are displayed in a way I don't understand

So... this change is too big as it is. I'd like to focus on the first 2 pieces of functionality first and then look at the other pieces separately. Also, please add comments generously as to exactly what the code is that you're proposing be added. There's a lot of very non-obvious changes you're proposing here.

If you can do that, I'd appreciate it and we can re-look at this patch. =:)

Thanks!

root_re = re.compile(r'In folder (.+)')
filepath_re = re.compile(r'^(.+):$')
filepath_re = re.compile(r'^(((?!scope: ).)+):$')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this change please? Why the change in regexp?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If line with symbol ends with ':' it is catched by this regex (seen below), which leads to such error when trying to open results lower than that.

Unable to open file: E:\Dev\C\sandbox\cscope_tmp\    17 [scope: main] case ENUM_TESTCASE_1

@@ -9,7 +9,7 @@
<array>
<dict>
<key>match</key>
<string>(.*):$</string>
<string>^(((?!scope: ).)*):$</string>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why you changed this please? I'm not aware of a problem with this right now, so I'm not sure what this is trying to fix.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If line with symbol ends with ':' it is catched by this regex (seen below, result treated like filename), fix prevents it.
zrzut ekranu 2018-04-08 17 15 21


// On default build command, whether to treat folders in project (after the 1st one) as
// additional source directories
"auto_next_source_dirs": false,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious about the use case here. I've never been part of a project so big that it is split into multiple directories and is not contained within a common parent folder. Can you help me understand what kind of scenario would require this or how you have things set up such that this is useful?

Also, I wonder if we even need auto_next_source_dirs or if we can do the right thing automatically?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of this reason I didn't want to make it default option :) In my case the other folders contain library-like project (used by other 'main' projects also) or headers of this library, it is handy to have these sources in the same project. Sublime Text automatically indexes all folders in the project for definitions, so I guess this is similar behavior.
Also, it wasn't possible to update or create database with more than 1 folder in project, because of restriction ... len(project_info_paths) == 1

@@ -51,6 +51,50 @@
"command": "cscope_visiter",
"context": [{"key": "selector", "operand": "text.find-in-files"}]
},
{
"keys": ["j"],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd rather leave out the sublime-keymap changes at least for the first round and just make the changes that are required to support it. Can you remove these sublime-keymap changes for at least this first review and let's get through all the other changes first?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

@@ -41,6 +42,14 @@ def get_setting(key, default=None, view=None):
pass
return get_settings().get(key, default)

def update_result_selection(view, selection_index, selection, update_sel=True):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused on what this is doing here too. Can you please help me understand what this is doing that it wasn't already doing? Also, I suspect that this will not work with Sublime Text 2. Thus far, while I'm not actively supporting Sublime Text 2, I've been making sure I at least don't break it with changes. Can you verify that this will at least not cause errors in ST2?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I keep results and currently selected results in view settings of every Cscope results.
I checked on ST2 and fixed scrolling to result and disabled class for mouse support.
But. The master branch wasn't working on ST2 :) Minor problems:

  • trailing comma in settings
  • ValueError: zero length fields name in format cause of lack of indices in the format specs

cscope.py Outdated
if self.view.settings().get('syntax') == CSCOPE_SYNTAX_FILE:
if args.get('direction'):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you help me understand what you're doing here? I gather the concept is to allow navigation in the results buffer using direction increments? Is this assuming there's only 1 cscope results window? I frequently have multiple cscope results windows. I'm not sure what the goal is here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, keyboard navigation. I also have multiple cscope results windows, no problems. Saved results and currently selected result are held in settings 'results' and 'cscope_results_sel' per cscope results buffer/view.

cscope.py Outdated
what = {
'up': -1,
'down': 1,
'up2': -20,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are going to do this, I think maybe up/down/pageup/pagedown would be better than up/down/up2/down2 as far as names go.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, changed

cscope.py Outdated
if command_mode in [0, 4, 6, 8]:
if nested:
match_string = ("{0:>6}\n{1:>6} [scope: {2}] {3}").format("..", match["line"], match["scope"], match["instance"])
match_string['head'] = ("{0:>6}\n").format("..")
match_string['main'] = ("{0:>6} [scope: {1}] {2}").format(match["line"], match["scope"], match["instance"])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, going to need help understand what you're doing here too, please, in each of these. I didn't write these regexps originally, so I honestly don't understand what they were doing completely nor what you're changing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regexes just format results appearance. I only split them into the 'head' part with the separator ('..') or file path and 'main' part with proper result line, which was needed for keyboard navigation and selecting/highlighting. Effectively there is no difference in appearance.

I would also add the option to the settings for disabling the separator between results altogether.

@vanrijn
Copy link
Collaborator

vanrijn commented Nov 19, 2018

Hey @Filios92 , I’m so sorry this has gone so long since I last looked at it. I really do appreciate the work you’ve done here. Unfortunately, I am not going to be able to contribute to this project anymore for the foreseeable future, and I’m not going to be able to work through this and get it included. Maybe @ameyp might be able to see this through to completion?

Also, would you be interested in helping to maintain this plugin long term? If so, please say so and maybe we can get you added as a contributor so you can merge this change in and help keep this little plugin chugging along? =:)

Again, I’m so sorry I can’t keep working with you on this PR. I definitely do not like leaving this halfway done but my hands are tied. =:(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants