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).
Related
I want to add a language server to handle completion / highlighting / etc. for a file.
As a basis for testing stuff I am using an example from Microsoft (https://github.com/microsoft/vscode-extension-samples/tree/main/lsp-sample) and changed it to be active for any File. This language server highlights any word in all capital letters.
When opening a C++ File, I get the highlighting / completion of my language server and the default one for C++ (See image).
I would like to detect if some other extension / build in highlighter is active for a file and deactivate it for this workspace or the current file if it is impossible for the current workspace)
Is there a way to do this in a generic way where I do not have to know which extensions are highlighting code?
If no, is there a way to do this, if I know a set of extensions I want to deactivate?
I finally had enough time to try around a bit more and found that providing your own language for the same extension is enough.
In package.json I added an element in contributes.languages with extensions containing .cpp (since I am using cpp files for testing).
I also copied over some implementation code from an example.
This suppressed the default highlighter and code completion for cpp files. Since i am only implementing a semantic token provider, I can see the default highlighting before my provider takes over. (I think this could be solved by adding a syntax highlighter, but this is already sufficient fo my preliminary testing)
I am not sure, how stable all of this would be as a plugin (I only tested in Extension Development Host mode)
Here an image of the results:
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.
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
I am exploring vscode after using atom for a long while. One of the things I'm missing is an equivalent of the lovely package advanced-open-file. Is there something similar to this in vscode?
I found the advanced-new-file extension, but it is only helpful when it comes to new files. I would like to be able to quickly open files from all over my local files (not only the workspace).
Edit: I found the option of workbench.action.quickOpen; but it doesn't allow opening files from the whole file system.
Sorry, but currently the answer is no. The problem is that input box doesn't provide a way to listen to key events:
GitHub issue,
so even the extensions can't do that currently. Here's the comment from advanced-new-file extension creator:
Because VSCode extensions don't yet have the ability to do type-ahead autocomplete within the text input box (See https://github.com/Microsoft/vscode/issues/426), we work around this limitation and provide autocomplete using a two-step workflow of selecting existing path, then providing new filename/path relative to the selection.
The good news is that there is a new API addressing this issue, but it's currently in 'proposed' state and can't be used for published extensions.
One workaround could be typing code -r some/path in integrated terminal and using 'tab' for autocomplete.
The Fuzzy search extension seems to work for me.
It adds a new action to the command palette which allows you to search for files in the current project and open them.
I'm searching for a way to parse the whole directory with source code with semantic. Is this possible to do without explicitly opening each file in emacs?
Yes,
There's a thing called an EDE project in CEDET - where you can specify the list of files in a project file. Semantic then does analysis of all of the files listed in the .ede project, and stored that in the database.
At that point, completion and intellisense works on all of those files.
I use projman mode on top of EDE. It aids in the creation of projects and provides convenient functions to find all source files and generate a global TAGS file. I had tried CEDET on and off for the past couple years and had always come away disappointed until I discovered projman.