Is it possible using a vscode extension to get info on or even interact with other instances? - visual-studio-code

I would like to find a way to get the open projects in all open vscode instances using a custom extension. I have done some research but I'm not finding any information on this is the API docs. I am guessing this isn't something built into vscode's API.
I think I can fix it by using 1 file to write some JSON to when an editor opens, but I would like to know if there is a better solution?

VSCode indeed starts a separate extension host process for each instance, so it's almost completely isolated. The only workaround within the API I can think of is using the global / workspace state API, see here for more information:
How to persist information for a vscode extension?
Data persisted to a memento should be available to all instances. The tricky part would be figuring out when a particular memento value has changed, I don't think there's any event for this, so you might have to resort to polling.
Other than that, persisting something to the file system or perhaps using sockets might be an option. Note that the ExtensionContext exposes a storagePath that might be helpful for the former.

Related

Block auto save on syntax errors with VS Code

I use auto save on pretty short after change delay and on focus change. Instead of using longer delay and disabling save on blur, I'd like to block saving when code syntax is incorrect. This way watch scripts wouldn't fire, and auto reloading servers, compilers etc not fail unnecessarily. Manual save should work. I was wondering if there's configuration option, existing extension or perhaps something in the extension API that could do this check?
Settings don't seem to contain an option related to this. I searched extension marketplace in vain.I don't have experience with writing extensions yet, but will try to check that route too.

How to launch vscode debug configuration from the browser?

I have a test case reporting scheme delivered in HTML that is complex in its own right and not easily ported to a VSCode extension. I would like to launch a Debug Configuration for each failing test case from the browser displaying the report. I have already been able to modify the report and have added a copy/paste widget for each test case's associated command. However I would like to do something to the effect of:
Launch a service as a VSCode extension that can handle requests
Formulate those requests in a way that can dynamically create launch configurations
It may be that I am stuck writing a Debug Adapter without the bells and whistles of interacting with the report.
That being said, if this is a solved problem or has a framework for solving with VSCode (and I realize remote execution could be a Very Bad Thing for VSCode to allow), I have not been able to find it through an existing extension.
I welcome your ideas.
This is perhaps not as open ended as it sounds...my question ultimately is: can VSCode operate as a service to be requested by web interfaces? Even if it could be done via Localhost this would be a boon. If it can be done over ssh with authentication, that would also be a bonus.
One way of getting VSCode to handle requests would be by invoking a vscode:// URI. This requires your extension to implement a URI handler. After the mandatory parts of the URI, you could have arbitrary data with whatever information you need.
Something that might or might not be an issue for your use case is that invoking such a URI triggers a popup in VSCode / doesn't work silently:
For dynamically creating launch configurations, you can use the vscode.debug.startDebugging() API.

Checking if control/command key is currently pressed in VS Extensions

In my extension, I would like to check in a certain function, if the control (or command) key is currently pressed. How is that possible? I couldn't find any field that exposes this information.
If you read the below article
https://code.visualstudio.com/docs/extensionAPI/patterns-and-principles
It says
Visual Studio Code has a very rich extensibility model and there are many ways to extend the tool. However, we do not provide direct access to the underlying UI DOM to extension writers. With VS Code, we’re continually trying to optimize use of the underlying web technologies to deliver an always available, highly responsive editor and we will continue to tune our use of the DOM as these technologies and our product evolve. To maintain performance and compatibility, we run extensions in their own host process and prevent direct access to the DOM. VS Code also includes a built-in set of UI components for common scenarios such as IntelliSense, so that these experiences are consistent across programming languages and extensions and extension developers do not need to build their own.
We realize that this approach may initially feel restrictive to extension developers. We’re always looking for ways to improve our extensibility model and expand the capabilities available to extensions. We look forward to hearing your feedback and ideas.
This means your extension code doesn't run the in editor window context at all. And you can't hack into the webview as the extension api doesn't provide it. So you need to open a Feature request with VScode team and ask them to expose either the last keyboard event or atleast the status of Shift, Ctrl and alt keys. Currently they just discard it and throw it away (if no editor is open) else they send it to the monaco editor before checking for any shortcut combination
This does not directly answer your question but maybe helps solving your problem:
Your extension could contribute two different commands: For example first command myextension.runTarget (noDebug=true) and myextension.debugTarget (noDebug=false). In addition your extension can contribute keybindings that bind those two commands to different hotkeys, for instance CTRL + F5 and only F5.
Looks like vscode itself does it the same way (screenshot of keybindings view):
This question might be of use. With this approach you could track a key down event and then if the key code is equal to command (91 or 93 on Safari/Chrome, 224 on Firefox) or control. From there, you could put in your functionality if this returns as true, or however you want to structure it

VSCode all autocomplete

Can VSCode's Intellisense/autocomplete be configured to work across all open files similar to Sublime's All Autocomplete plugin? Is there an extension that supports this?
Specifically, I am looking to get basic function and variable name autocompletion to work across C, C++, Matlab, and Python source files.
No, this is not possible. All actions in VS code are strictly limited to the document, which is passed in to the various APIs an extension has to implement.
I can imagine a hack, however, where you store code completion info persistently (in vscode settings, external file etc.), once you have collected them for a document and use that persistance layer to load all the info from there. This is however not very dynamic and requires that a file has been scanned for code completion info at least once (i.e. it was open in vscode and active at least once).

Where does Internet Explorer stores its form data history that is uses for auto completion?

Where does Internet Explorer stores its form data history that is uses for auto completion?
I need to make a tool the cleans IE form data.
Is there an API for this?
Or what are the registry keys?
Autocomplete data is stored in the registry in two places:
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\IntelliForms\Storage1
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\IntelliForms\Storage2
Direct manipulation is not supported.
Technically, the IE7+ API to do this is:
rundll32.exe inetcpl.cpl,ClearMyTracksByProcess 48
But I'm not sure this is formally supported for public callers.
I'm not sure what the registry keys are, but you could work it out by taking a snapshot of your registry, then deleting your form data history, and comparing it and seeing what's different.
I doubt there's an API for it, but that's just a guess.
Have a look at "Clear All History" Its a tool to do what you exactly need.
You will find similar open source tools. Try googling for them.
In Hindsight you would also want to check out CCleaner. Its freeware and equally a fantastic tool to keep, amongst others, your internet history clean.