问题
I'm searching for a method to expose VSCode active 'when Clause Contexts' e.g 'explorerResourceIsFolder'. To give you a better understanding of my use case, here's some background on the project to which a VSCode extension is being developed. My extension will facilitate programming in and controlling VSCode by voice.
Caster is a Dragonfly-Based Voice Programming Toolkit. Dragonfly is a speech recognition framework. It is a Python package which offers a high-level object model and allows its users to easily write scripts, macros, and programs which use speech recognition. The goal behind these projects is to enable those who limited interaction with keyboard or mouse to program or for Devs to boost productivity.
Some current outstanding limitations with Castor and Dragonfly both interact by emulating keystrokes. This is just to name a few issues.
- Reliability of IDE of performance different system configurations and IDE versions. This introduces variables such as command execution latency.
- Castor is completely unaware of the IDE environment.
- Dragon NaturallySpeaking has an upper complexity limit on Grammars. After the limit is reached, a BadGrammar error will occur.
- Limited keyboard combinations and not all functions can be called by shortcuts.
Some examples via Adom editor
- find in buffer": R(Key("c-f"), rdescript="Atom: Find in Buffer") Only a few relevant commands are useful within 'Find in Buffer' context, but Castor commands are global which decreases command speech recognition accuracy and increases grammar complexity. With Caster IDE integration would allow for llimited command sets specified to IDE contexts or focuses.
- "split into lines": R(Key("cs-p") + Text("Split Into Lines") + Pause(atom_palette_wait) + Key("enter"), rdescript="Atom: Split Into lines"), Not all IDE functions can be called via shortcuts or be easily re-created within castor. My attempt to work around this within Adom was to utilize command palette. While this extended my ability to trigger commands it introduced latency. To fast the wrong command would be triggered. Too slow it a decrease productivity. Indexing latency which based on system load, system specs, number of active plug-ins, and number of characters per command. We tried to mitigate this by using Pause(atom_palette_wait) but the variables in the latency were too complex. The same would be true of Studio Code.
Castor framework IDE integration
Castor would contain IDE functions to pass to IDEs plug-ins/extensions for execution. For example "Find ": find R(SendFunction("actions.find"), rdescript="VisualStudioCode: Find")
Castor would listen for contexts or focus announced from IDEs .
Castor would store commands and functions based on IDE context or focus. Then activate the only relevant commands containing shortcuts or IDEs functions based the focus announced from the IDE.
IDEs plug-ins/extensions framework
Listen for and execute IDEs specific functions from Caster
Announce current contexts or focus to Caster
As a long-term goal extend functionality of IDE ( e.g. in Visual Studio Code adding numbers to IntelliSense list) The user would speak the number and the appropriate line would be selected and executed.
There will be three parts to the Studio Code Extension.
- A websocket running a server and client that allows for bidirectional communication to Castor.
- A function that executes 'Command_id' e.g 'editor.debug.action.toggleBreakpoint' In progress - Near completion
- A method to expose the editors 'when Clause Contexts' e.g 'explorerResourceIsFolder' - Searching for method - No luck via the APIs thus far - Searching source code to understand implementation.
Any suggestions would be welcome. If you think this is worth opening a github ticket on the VSCode repository let me know.
回答1:
There is a non public api for getting the when context in effect. You can use getValue(key: string). It is available from the work on this issue ticket:
Lift setContext from a command to proper API Microsoft/vscode#10471
and the source can be viewed here:
contextKeyService.ts
by using getValue(key: string)
It is still work in progress as of May 2017. Thank you. Good day.
来源:https://stackoverflow.com/questions/43372232/a-method-to-expose-the-vscode-active-when-clause-contexts