Skip to content

Commit

Permalink
Merge pull request #30 from tillt/master
Browse files Browse the repository at this point in the history
Added symbol_info and virtual_function_implementations.
  • Loading branch information
rampage644 authored Aug 29, 2016
2 parents caf2ca3 + d11c4b2 commit 8636cd3
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 27 deletions.
7 changes: 4 additions & 3 deletions Default (Linux).sublime-keymap
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[
{"keys": ["ctrl+shift+u"], "command": "rtags_location", "args": {"switch": "-r"} },
{"keys": ["ctrl+shift+i"], "command": "rtags_cursor", "args": {"switch": "-U"} },
{"keys": ["f2"], "command": "rtags_location", "args": {"switch": "-f"} },
{"keys": ["ctrl+shift+u"], "command": "rtags_location", "args": {"switches": ["--absolute-path", "-r"]} },
{"keys": ["ctrl+shift+x"], "command": "rtags_location", "args": {"switches": ["--absolute-path", "-k", "-r"]} },
{"keys": ["ctrl+shift+i"], "command": "rtags_symbol_info", "args": {"switches": ["--absolute-path", "--symbol-info"]} },
{"keys": ["f2"], "command": "rtags_location", "args": {"switches": ["--absolute-path", "-f"]} },
{"keys": ["ctrl+shift+b"], "command": "rtags_go_backward" },
]
3 changes: 2 additions & 1 deletion Default (OSX).sublime-keymap
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[
{"keys": ["ctrl+shift+u"], "command": "rtags_location", "args": {"switches": ["--absolute-path", "-r"]} },
{"keys": ["ctrl+shift+i"], "command": "rtags_cursor", "args": {"switches": ["-U"]} },
{"keys": ["ctrl+shift+x"], "command": "rtags_location", "args": {"switches": ["--absolute-path", "-k", "-r"]} },
{"keys": ["ctrl+shift+i"], "command": "rtags_symbol_info", "args": {"switches": ["--absolute-path", "--symbol-info"]} },
{"keys": ["f2"], "command": "rtags_location", "args": {"switches": ["--absolute-path", "-f"]} },
{"keys": ["ctrl+shift+b"], "command": "rtags_go_backward" },
]
7 changes: 4 additions & 3 deletions Default (Windows).sublime-keymap
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[
{"keys": ["ctrl+shift+u"], "command": "rtags_location", "args": {"switch": "-r"} },
{"keys": ["ctrl+shift+i"], "command": "rtags_cursor", "args": {"switch": "-U"} },
{"keys": ["f2"], "command": "rtags_location", "args": {"switch": "-f"} },
{"keys": ["ctrl+shift+u"], "command": "rtags_location", "args": {"switches": ["--absolute-path", "-r"]} },
{"keys": ["ctrl+shift+x"], "command": "rtags_location", "args": {"switches": ["--absolute-path", "-k", "-r"]} },
{"keys": ["ctrl+shift+i"], "command": "rtags_symbol_info", "args": {"switches": ["--absolute-path", "--symbol-info"]} },
{"keys": ["f2"], "command": "rtags_location", "args": {"switches": ["--absolute-path", "-f"]} },
{"keys": ["ctrl+shift+b"], "command": "rtags_go_backward" },
]
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# About

Sublime Text 3 C/C++ code completion, navigation plugin. It's based on [rtags](https://github.com/Andersbakken/rtags).
Sublime Text 3 C/C++ code completion, navigation plugin. It is based on [rtags](https://github.com/Andersbakken/rtags).

# Installation

Expand All @@ -11,33 +11,33 @@ Make sure you Install `rtags`:
cd rtags
mkdir build && cd build && cmake ..
make install


### Via Package Control

* Install [Package Control](https://sublime.wbond.net/installation)
* Run “Package Control: Install Package”
* Install "SublimeRtags"
* Run “Package Control: Install Package”
* Install "RtagsComplete"

### Manually

cd <sublime-text-Packages-dir>
git clone https://github.com/rampage644/sublime-rtags
git clone https://github.com/rampage644/sublime-rtags

# Features

* Symbol navigation (Goto definition/declaration)
* Find usages (Find symbol references)
* Find usages (Find symbol references, Find virtual function re-implementations)
* Symbol information
* Code completion

# Usage

It's very unstable plugin. There are number of limitations:
It is a very unstable plugin. There are a number of limitations:

* You have to run `rdm` daemon manually. Better run it before Sublime starts, because plugin creates persistent connection to daemon
* There is no `rdm`'s project management yet. So it's your responsibility to setup project, pass compilation commands (with `rc --compile gcc main.c` or `rc -J`). For more info see [LLVM codebase](http://clang.llvm.org/docs/JSONCompilationDatabase.html), [rtags README](https://github.com/Andersbakken/rtags/blob/master/README.org), [Bear project](https://github.com/rizsotto/Bear/blob/master/README.md).

So, typical workflow is:
So, the typical workflow is:

1. Start `rdm`
2. Supply it with _JSON compilation codebase_ via `rc -J` or several `rc -c` calls.
Expand All @@ -49,18 +49,22 @@ Keybindings inspired by `Qt Creator`.

+ Symbol navigation - `F2`
+ Find usages - `Ctrl+Shift+u`
+ Use `Alt+/` explicitly when you auto-completion
+ Find virtual function re-implementations - `Ctrl+Shift+x`
+ Symbol information - `Ctrl+Shift+i`
+ Use `Alt+/` explicitly for auto-completion
+ Mouse _button8_ to go backwards (mouse wheel left)

# Customization

### Keybindings
### Keybindings

Customize your own keybindings via "Preferences - Package Settings - SublimeRtags - Key Bindings - User"

```
[
{"keys": ["ctrl+shift+u"], "command": "rtags_location", "args": {"switches": ["--absolute-path", "-r"]} },
{"keys": ["ctrl+shift+x"], "command": "rtags_location", "args": {"switches": ["--absolute-path", "-k", "-r"]} },
{"keys": ["ctrl+shift+i"], "command": "rtags_symbol_info", "args": {"switches": ["--absolute-path", "--symbol-info"]} },
{"keys": ["f2"], "command": "rtags_location", "args": {"switches": ["--absolute-path", "-f"]} },
{"keys": ["ctrl+shift+b"], "command": "rtags_go_backward" },
]
Expand Down Expand Up @@ -96,4 +100,4 @@ If you need auto-completion to trigger upon `.`, `->` or `::` add following to "
"selector": "text, source, meta, string, punctuation, constant"
}
]
```
```
35 changes: 26 additions & 9 deletions rtags.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


def run_rc(switches, input=None, *args):
p = subprocess.Popen([RC_PATH, '--silent-query'] + switches + list(args),
p = subprocess.Popen([RC_PATH] + switches + list(args),
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE)
Expand Down Expand Up @@ -216,17 +216,34 @@ def _query(self, *args, **kwargs):
row + 1, col + 1)


class RtagsCursorCommand(RtagsLocationCommand):
class RtagsSymbolInfoCommand(RtagsLocationCommand):
panel_name = 'cursor'
inforeg = r'(\S+):\s*(.+)'

def filter_items(self, item):
return re.match(inforeg, item)

def _action(self, out, err):
text = out.decode()
if not text:
return
panel = self.view.window().create_output_panel(self.panel_name)
self.view.window().run_command(
"show_panel", {"panel": "output." + self.panel_name})
panel.run_command('output_panel_insert', {'characters': text})
items = list(map(lambda x: x.decode('utf-8'), out.splitlines()))
items = list(filter(self.filter_items, items))

def out_to_items(item):
(title, info) = re.findall(inforeg, item)[0]
return [info.strip(), title.strip()]

def out_file_to_items(item):
(file, line, _, usage) = re.findall(reg, item)[0]
return [usage.strip(), "{}:{}".format(file.split('/')[-1], line)]

items = list(map(out_to_items, items))
self.last_references = items

self.view.window().show_quick_panel(
items,
None,
sublime.MONOSPACE_FONT,
-1,
None)


class RtagsNavigationListener(sublime_plugin.EventListener):
Expand Down

0 comments on commit 8636cd3

Please sign in to comment.