-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsublime_ros_assist.py
135 lines (111 loc) · 4.87 KB
/
sublime_ros_assist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import sublime
import sublime_plugin
import os
import errno
def oprint(s):
print("[ros_assist] {}".format(s))
def generate_package_paths(ros_ws_path):
pkg_paths = list()
for root, dirs, files in os.walk(ros_ws_path):
if 'package.xml' in files \
and root.find('src') >= 0 \
and 'CATKIN_IGNORE' not in files:
pkg_paths.append(root)
return pkg_paths
def generate_include_flags(ros_ws_path):
inc_paths = [os.path.join(os.path.join(ros_ws_path, 'devel'), 'include')] \
+ [os.path.join(path, 'include')
for path in generate_package_paths(ros_ws_path)]
oprint(inc_paths)
return ["-I"+p for p in inc_paths]
class SublimeRosAssistRevealPackageCommand(sublime_plugin.WindowCommand):
def finish_package(self, i):
if i >= 0:
active_window = sublime.active_window()
active_window.open_file(
os.path.join(self.pkg_paths[i], 'package.xml'))
active_window.run_command("reveal_in_side_bar")
active_window.active_view().close()
def finish_ros_ws(self, i):
if i >= 0:
oprint("select \"{}\"".format(self.ros_ws_paths[i]))
pkg_paths = generate_package_paths(self.ros_ws_paths[i])
self.pkg_paths = pkg_paths
active_window = sublime.active_window()
active_window.show_quick_panel(
pkg_paths, self.finish_package, 0, 0)
else:
oprint("Withdraw select")
def run(self):
active_window = sublime.active_window()
proj_paths = [d['path']
for d in active_window.project_data()['folders']]
oprint("project_paths:{}".format(proj_paths))
ros_ws_paths = list()
for proj_path in proj_paths:
for root, dirs, files in os.walk(proj_path):
if 'setup.bash' in files and root[-5:] == 'devel':
ros_ws_paths.append(os.path.dirname(root))
oprint("ros_ws_paths:{}".format(ros_ws_paths))
self.ros_ws_paths = ros_ws_paths
if len(self.ros_ws_paths) > 1:
active_window.show_quick_panel(
proj_paths, self.finish_ros_ws, 0, 0)
else:
self.finish_ros_ws(0)
class SublimeRosAssistGenerateClangFlagsCommand(sublime_plugin.WindowCommand):
def finish(self, i):
if i >= 0:
oprint("select \"{}\"".format(self.ros_ws_paths[i]))
inc_flags = generate_include_flags(self.ros_ws_paths[i])
active_window = sublime.active_window()
data = active_window.project_data()
if 'settings' not in data:
data['settings'] = dict()
plugin_settings = sublime.load_settings(
"sublime_ros_assist.sublime-settings")
extra_flags = plugin_settings.get('extra_flags_for_clang', list())
data['settings']['sublimeclang_options'] = extra_flags + inc_flags
active_window.set_project_data(data)
else:
oprint("Withdraw select")
def run(self):
active_window = sublime.active_window()
proj_paths = [d['path']
for d in active_window.project_data()['folders']]
oprint("project_paths:{}".format(proj_paths))
ros_ws_paths = list()
for proj_path in proj_paths:
for root, dirs, files in os.walk(proj_path):
if 'setup.bash' in files and root[-5:] == 'devel':
ros_ws_paths.append(os.path.dirname(root))
oprint("ros_ws_paths:{}".format(ros_ws_paths))
self.ros_ws_paths = ros_ws_paths
if len(self.ros_ws_paths) > 1:
active_window.show_quick_panel(proj_paths, self.finish, 0, 0)
else:
self.finish(0)
class SublimeRosAssistInsertContentCommand(sublime_plugin.TextCommand):
def run(self, edit, value=None):
self.view.insert(edit, 0, value)
class SublimeRosAssistShowYcmExtraConfCommand(sublime_plugin.WindowCommand):
def run(self):
package_path = os.path.join(sublime.packages_path(), "SublimeRosAssist")
content = None
try:
with open(os.path.join(package_path, 'ycm_extra_conf.py.txt')) as f:
content = f.read()
if content:
newview = sublime.active_window().new_file();
newview.run_command('sublime_ros_assist_insert_content', dict(value = content))
newview.set_name(".ycm_extra_conf.py")
newview.set_syntax_file('Packages/Python/Python.sublime-syntax')
except OSError as e:
if e.errno == errno.ENOENT:
sublime.error_message("No ycm_extra_conf.py in the package path!")
else:
sublime.error_message("Some error occured!")
raise
except Exception as e:
sublime.error_message("Some error occured!")
raise