├── .no-sublime-package ├── .gitignore ├── Default.sublime-keymap ├── sublime-sourcetrail.png ├── Default.sublime-commands ├── Sourcetrail.sublime-settings ├── Context.sublime-menu ├── Main.sublime-menu ├── README.rst ├── LICENSE.txt └── SourcetrailPlugin.py /.no-sublime-package: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | .DS_STORE 3 | 4 | -------------------------------------------------------------------------------- /Default.sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | // { "keys": [""], "command": "set_active_token" }, 3 | ] -------------------------------------------------------------------------------- /sublime-sourcetrail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CoatiSoftware/sublime-sourcetrail/HEAD/sublime-sourcetrail.png -------------------------------------------------------------------------------- /Default.sublime-commands: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "caption": "Sourcetrail: Set active Token", 4 | "command": "set_active_token" 5 | } 6 | ] -------------------------------------------------------------------------------- /Sourcetrail.sublime-settings: -------------------------------------------------------------------------------- 1 | { 2 | "host_ip": "localhost", 3 | "sourcetrail_to_sublime_port": 6666, 4 | "sublime_to_sourcetrail_port": 6667 5 | } 6 | -------------------------------------------------------------------------------- /Context.sublime-menu: -------------------------------------------------------------------------------- 1 | [ 2 | { "caption": "-", "id": "sourcetrail" }, 3 | { "command": "set_active_token", "caption": "Sourcetrail - Set active Token" } 4 | ] 5 | -------------------------------------------------------------------------------- /Main.sublime-menu: -------------------------------------------------------------------------------- 1 | 2 | [ 3 | { 4 | "id": "preferences", 5 | "children": 6 | [ 7 | { 8 | "id": "package-settings", 9 | "children": 10 | [ 11 | { 12 | "caption": "Sourcetrail", 13 | "children": 14 | [ 15 | { 16 | "command": "open_file", "args": 17 | { 18 | "file": "${packages}/Sourcetrail/Sourcetrail.sublime-settings" 19 | }, 20 | "caption": "Settings - Default" 21 | }, 22 | { 23 | "command": "open_file", "args": 24 | { 25 | "file": "${packages}/User/Sourcetrail.sublime-settings" 26 | }, 27 | "caption": "Settings - User" 28 | } 29 | ] 30 | } 31 | ] 32 | } 33 | ] 34 | } 35 | ] -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ############# 2 | sublime-sourcetrail 3 | ############# 4 | 5 | sublime-sourcetrail is a plugin for Sublime to communicate with Sourcetrail_. 6 | 7 | 8 | .. _Sourcetrail : https://sourcetrail.com 9 | 10 | 11 | How to Install: 12 | =============== 13 | 14 | Manually 15 | 16 | Just copy and past this folder into your Packages folder of Sublime Text. (You can find 17 | that folder from within Sublime via the menu: Preferences -> Browse Packages...). Restart Sublime before 18 | starting to use the plugin. 19 | 20 | via Package Controll 21 | 22 | 23 | Use 24 | === 25 | 26 | .. image:: sublime-sourcetrail.png 27 | 28 | If you want Sublime to activate a certain element in Sourcetrail, click a location to place the cursor, 29 | right-click to bring up the context menu and choose the “Sourcetrail - Set active Token” option. 30 | Please note that the position of the cursor will be sent to Sourcetrail and not the position you opened the context menu at. 31 | 32 | License 33 | ======= 34 | 35 | MIT 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2016 Coati Software OG 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 9 | 10 | -------------------------------------------------------------------------------- /SourcetrailPlugin.py: -------------------------------------------------------------------------------- 1 | import sublime 2 | import sublime_plugin 3 | import threading 4 | import socket 5 | import os.path 6 | import encodings.idna 7 | 8 | try: # use this for Sublime Text 2 9 | import SocketServer 10 | except ImportError: # use this for Sublime Text 3 11 | import socketserver as SocketServer 12 | 13 | MESSAGE_SPLIT_STRING = ">>" 14 | 15 | 16 | # Handling Sourcetrail to Sublime communication 17 | 18 | def setCursorPosition(filePath, row, col): 19 | if (os.path.exists(filePath)): 20 | sublime.active_window().open_file(filePath + ":" + str(row) + 21 | ":" + str(col), sublime.ENCODED_POSITION) 22 | else: 23 | sublime.error_message( 24 | "Sourcetrail is trying to jump to a file that does not exist: " + filePath) 25 | 26 | 27 | def sendPing(): 28 | settings = sublime.load_settings('Sourcetrail.sublime-settings') 29 | host_ip = settings.get('host_ip') 30 | plugin_to_sourcetrail_port = settings.get('sublime_to_sourcetrail_port') 31 | 32 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 33 | s.connect((host_ip, plugin_to_sourcetrail_port)) 34 | message = "ping>>SublimeText" 35 | s.send(message.encode()) 36 | s.close() 37 | 38 | 39 | # This class is instantiated once per connection to the server 40 | class ConnectionHandler(SocketServer.BaseRequestHandler): 41 | 42 | def handle(self): 43 | data = self.request.recv(1024).strip() 44 | text = data.decode('utf-8') 45 | eom_index = text.find("") 46 | if (not eom_index == 0): 47 | message_string = text[0:eom_index] 48 | message_fields = message_string.split(MESSAGE_SPLIT_STRING) 49 | if (message_fields[0] == "moveCursor"): 50 | sublime.set_timeout(lambda: setCursorPosition( 51 | message_fields[1], int(message_fields[2]), int(message_fields[3]) + 1), 0) 52 | if (message_fields[0] == "ping"): 53 | sendPing() 54 | 55 | 56 | class ServerThreadHandler(threading.Thread): 57 | 58 | def __init__(self, ip, port): 59 | self.ip = ip 60 | self.port = port 61 | threading.Thread.__init__(self) 62 | 63 | def run(self): 64 | server = SocketServer.TCPServer( 65 | (self.ip, self.port), ConnectionHandler) 66 | server.serve_forever() 67 | 68 | 69 | class ServerStartupListener(sublime_plugin.EventListener): 70 | 71 | def __init__(self): 72 | self.running = False 73 | 74 | def on_activated(self, view): 75 | if (not self.running): 76 | self.running = True 77 | 78 | settings = sublime.load_settings('Sourcetrail.sublime-settings') 79 | host_ip = settings.get('host_ip') 80 | sourcetrail_to_plugin_port = settings.get('sourcetrail_to_sublime_port') 81 | 82 | networkListener = ServerThreadHandler( 83 | host_ip, sourcetrail_to_plugin_port) 84 | networkListener.start() 85 | sendPing() 86 | 87 | 88 | # Handling Sublime to Sourcetrail communication 89 | 90 | class SetActiveTokenCommand(sublime_plugin.TextCommand): 91 | 92 | def run(self, edit): 93 | filePath = self.view.file_name() 94 | 95 | selectionPos = self.view.sel()[0].begin() 96 | (row, col) = self.view.rowcol(selectionPos) 97 | col += 1 # cols returned by rowcol() are 0-based. 98 | row += 1 # rows returned by rowcol() are 0-based. 99 | 100 | text = "setActiveToken" + MESSAGE_SPLIT_STRING + filePath + \ 101 | MESSAGE_SPLIT_STRING + \ 102 | str(row) + MESSAGE_SPLIT_STRING + str(col) + "" 103 | data = text.encode() 104 | 105 | settings = sublime.load_settings('Sourcetrail.sublime-settings') 106 | host_ip = settings.get('host_ip') 107 | plugin_to_sourcetrail_port = settings.get('sublime_to_sourcetrail_port') 108 | 109 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 110 | s.connect((host_ip, plugin_to_sourcetrail_port)) 111 | s.send(data) 112 | s.close() 113 | --------------------------------------------------------------------------------