jetbrains
The community/apps/jetbrains directory contains files that enable Talon to interact with JetBrains IDEs.
The core functionality is implemented in jetbrains.py. This file defines a port_mapping dictionary that associates the bundle IDs and executable names of various JetBrains IDEs with specific ports on the local machine. It uses this mapping to send commands to the IDE via HTTP requests. The IDEs have a plugin, Voice Code Idea, installed that listens for these requests on its configured port and executes the desired actions. A nonce is used to authenticate the requests, and the script attempts to find the nonce file in the temp directory or the user's home directory, using the port number as a suffix. The send_idea_command function is used to send the commands over HTTP and return the result. The file also defines Talon actions for various IDE commands, including:
idea(commands: str): Sends a comma-separated list of commands to the active JetBrains application.idea_grab(times: int): Copies the specified number of words to the left of the cursor, which can be useful for refactoring and code manipulation.
The jetbrains.py file also sets up Talon contexts that match JetBrains applications, and defines Talon actions that are available within those contexts. These actions include:
tab_next,tab_previous,tab_close,tab_reopen: Actions for working with editor tabs.toggle_comment: Toggles line comments in the editor.copy,cut,delete,paste: Standard edit actions.find_next,find_previous,find: Actions for searching in the editor.line_clone,line_swap_down,line_swap_up: Actions for manipulating lines of code.indent_more,indent_less: Actions for indenting and unindenting lines of code.select_line,select_word,select_all: Actions for making selections in the editor.file_start,file_end,extend_file_start,extend_file_end: Actions for moving the cursor to the start or end of the file.extend_word_left,extend_word_right: Actions for extending the selection by words.jump_line(n: int): Jumps to a specific line number in the editor.filename() -> str: Returns the filename of the active file.tab_jump(number: int): Jumps to a specific tab number.extend_until_line(line: int): Extends the selection to the specified line.select_range(line_start: int, line_end: int): Selects a range of lines.extend_camel_left(),extend_camel_right(),camel_left(),camel_right(): Actions for moving and extending selections by camel case words.command_search(command: str = ""): Opens the command search popup.line_clone(line: int): Clones a specific line.multi_cursor_enable(),multi_cursor_disable(),multi_cursor_add_above(),multi_cursor_add_below(),multi_cursor_select_fewer_occurrences(),multi_cursor_select_more_occurrences(),multi_cursor_select_all_occurrences(),multi_cursor_add_to_line_ends(): Actions for working with multiple cursors.split_window_vertically(),split_window_horizontally(),split_flip(),split_maximize(),split_reset(),split_clear(),split_clear_all(),split_next(): Actions for splitting and managing the editor windows.
The jetbrains.talon file defines Talon commands for various JetBrains IDE actions. It imports several tags (user.line_commands, user.multiple_cursors, user.splits, user.tabs, user.command_search) to enable the functionality in these categories. These commands leverage the actions defined in jetbrains.py. Here are some notable commands:
- Code Completion:
complete,perfect,smartcommands use the IDE's code completion features. - Refactoring: Commands like
refactor,extract variable,extract method,refactor in line,refactor rename, andrename fileprovide quick access to refactoring actions. - Navigation:
go declaration,go implementation,go usage,go type,go test,go back, andgo forwardenable easy navigation within the code. - Search:
find (everywhere | all),(search | find) class,(search | find) file,(search | find) path,(search | find) symbol, andrecentprovide various ways to search for code. - Surround and Templates: The
surround withcommand wraps code with a template, and commands likeinsert generatedandinsert templateinsert generated code and templates, respectively. - Recording: Commands like
toggle recording,change recordings, andplay recordingallow recording and replaying macros. - Bookmarks: Commands like
go mark,toggle mark,go next mark,go last markand the numbered versions of these are used to manipulate bookmarks. - Folding:
expand deep,expand all,collapse deep, andcollapse allprovide code folding actions. - Miscellaneous:
go next (method | function)andgo last (method | function)allow navigation between methods/functions.clippings,copy path,copy reference, andcopy prettyprovide ways to copy information to the clipboard. - File Creation:
create sibling, andcreate fileprovide ways to create new files. - Task Management: Commands like
go task,go browser task,switch task,clear task, andconfigure serversmanage tasks within the IDE. - Git / Github: Commands such as
git pull,git commit,git push,git log,git browse,git (gets | gist),git (pull request | request),git (view | show | list) (requests | request),git (annotate | blame), andgit menuprovide Git and GitHub integration. - Tool Windows: Commands like
toggle project,toggle find,toggle run,toggle debug,toggle events,toggle terminal,toggle git,toggle structure,toggle database,toggle database changes,toggle make,toggle to do,toggle docker,toggle favorites, andtoggle lastmanage tool window visibility. - Pin/dock/float: Commands like
toggle pinned,toggle docked,toggle floating,toggle windowed, andtoggle splitmanage the layout of tool windows. - Settings, not windows: Commands like
toggle tool buttons,toggle toolbar,toggle status [bar], andtoggle navigation [bar]manage the IDE's UI. - Active editor settings: Commands such as
toggle power save,toggle whitespace,toggle indents,toggle line numbers,toggle (bread crumbs | breadcrumbs),toggle gutter icons,toggle wrap, andtoggle parametersmanage editor-specific settings. - Toggleable views: Commands such as
toggle fullscreen,toggle distraction [free mode], andtoggle presentation [mode]toggle different IDE views. - Additional toggles:
toggle commentcomments out code. - Quick popups:
change schemeopens the theme selection window. - Javadoc/Definitions/Parameters: Commands like
(toggle | pop) (doc | documentation),(pop deaf | toggle definition),pop type, andpop parametersopen quick popups with related information. - Debugging: Commands like
go breakpoints,toggle [line] breakpoint,toggle method breakpoint,run menu,run test,run test again,debug test,step over,step into,step smart,step to line, andcontinuecontrol the debugger. - Grow/Shrink:
(grow | shrink) window right,(grow | shrink) window left,(grow | shrink) window up, and(grow | shrink) window downresize tool windows. - Error/Warning Navigation:
go next (error | air),go last (error | air),fix next (error | air), andfix last (error | air)provide ways to navigate and fix errors/warnings. - Special Selects:
select less,select (more | this)provide ways to adjust selection size. - Line-Specific Commands: The
expand <number> until <number>,collapse <number> until <number>,paste <number> until <number>,refactor <number> until <number>, andclone <number>commands use line numbers to specify the scope of the command. - Find/Replace Commands: There are several find/replace commands that use line numbers or the currently selected text:
clear last <user.text>,clear next <user.text>,comment last <user.text>,comment next <user.text>,go last <user.text>,go next <user.text>,go <number> <user.text>,paste last <user.text>,paste next <user.text>,refactor <number> <user.text>,refactor last <user.text>,refactor next <user.text>,rename <number> <user.text>,rename next <user.text>,rename last <user.text>,complete <number> <user.text>,complete next <user.text>,complete last <user.text>,quick fix <number> <user.text>,quick fix next <user.text>,quick fix last <user.text>,replace last <user.text>,replace next <user.text>,follow <number> <user.text>,follow next <user.text>,follow last <user.text>,reference <number> <user.text>,reference next <user.text>,reference last <user.text>,select last <user.text>,select next <user.text>, andselect <number> <user.text>. - Camel Case Navigation:
select camel left,select camel right,go camel left, andgo camel rightallow navigation by camel case words. - Blacken: The
blackencommand formats code using theblackplugin.
In summary, jetbrains.py provides the core logic for communication with JetBrains IDEs, while jetbrains.talon defines the specific voice commands that users can use to interact with the IDEs. Together, they enable comprehensive voice control of JetBrains IDEs.