Add an extension to an existing extension.js in visual studio code - visual-studio-code

I want to add an extension(for e.g. Docker extension) to my existing extension and repackage it as one single extension.

Assuming you want to create a user experience, where the end user gets the benefit of multiple VS Code extensions that complement each other well, or one depends on another, you should check out the mechanism called extension pack:
Create an extension that will have no code, but will list other extensions via this package.json. Here is an example:
{
"extensionPack": [
"felixfbecker.php-debug",
"felixfbecker.php-intellisense",
"Kasik96.format-php"
]
}
https://code.visualstudio.com/api/references/extension-manifest#extension-packs
And here is some further reading...
https://code.visualstudio.com/blogs/2017/03/07/extension-pack-roundup

Related

Generate starter code based on new file VSCode

Is there a way to configure some code based on a file extension when created in VS Code? I'm currently working with psioniq file header which has been pretty helpful in generating good header files, but I'm looking to take this a step farther.
When I create a new file, based on a specific file extension, I would like it to generate some starting code that I can configure. For example, I work with Verilog a lot. It would be really cool if Code could generate based on the file name.
Create new file
Code generates some code (like below) or something else that could be configured based on the filetype:
module <filename> (
input ,
output ,
);
endmodule
Anyone have any extensions they know about or resources they can point me to to implement this?
This would be a pretty easy extension to write but an alternative is snippets.
You can create keywords, based on the extensions, that when you type it it'll create all that code for you.
https://code.visualstudio.com/docs/editor/userdefinedsnippets

How to stop a single VS Code extension from auto update?

Some of my vs code extension update every day, and I have a limited amount of internet bandwidth, is it possible to stop a specific extension from the auto update?
Thanks in advance.
Yes, it is possible (and simple):
In the package.json of the extension,
you will find a metadata section that look like so:
"__metadata": {
"id": "0fcefdee-e09c-4b96-9998-f5dc891893dd",
"publisherId": "1e02cadf-73ee-47be-8772-75da47b7921f",
"publisherDisplayName": "Robert Plant"
}
Rename the id field, as "OLD id".
Below the OLD id line, add the following line
"id": "00000000-0000-0000-0000-000000000000",
You will end up with:
"__metadata": {
"OLD id": "0fcefdee-e09c-4b96-9998-f5dc891893dd",
"id": "00000000-0000-0000-0000-000000000000",
"publisherId": "1e02cadf-73ee-47be-8772-75da47b7921f",
"publisherDisplayName": "Robert Plant"
}
You might have to reload the window and/or to disable/reenable the extension.
NB: If you need to do it for more than one extension, you will need to give each one a different id, otherwise, it won't work:
00000000-0000-0000-0000-000000000000
00000000-0000-0000-0000-000000000001
00000000-0000-0000-0000-000000000002
Etc.
That's it!
So far, there are only settings for controlling all of your extensions. You can use the settings below:
{
"extensions.autoCheckUpdates": false,
"extensions.autoUpdate": false
}
Of course, you can always submit a feature request for controlling specific extensions individually.
From GH Issue: Please make it possible to disable auto-update for a specific extension
Please try the feature Install Another Version... - right click on
extension to see this action. Installing another version will lock the
extension to that version.
So specifically choosing a certain version should stop future updates.
Also see https://stackoverflow.com/a/53755378/836330 about pinning/reverting to a specific extension version which should not allow auto-updating.
Add line bellow to settings.json
Use this format -
"settingsSync.ignoredExtensions": ["extension-name"]
You can find the name of your extensions in VS Code settings or on the marketplace.
Example for quokka - VS Code extension marketplace
Example for quokka - "settingsSync.ignoredExtensions": ["wallabyjs.quokka-vscode"]
These settings will exclude extensions from auto-update.

Multiple formatters in Visual Studio Code

In my team, some people are using VS Code and others WebStorm. To align code format, I've written an extension for VS Code that adds some missing rules.
My plan was to run my extension along with the native formatters that ship with VS Code. I provide my edits using the API:
vscode.languages.registerDocumentFormattingEditProvider('typescript', {
provideDocumentFormattingEdits(document: vscode.TextDocument) {
const textEdit: vscode.TextEdit[];
return textEdit;
}
}
But it seems I can't run this along the native formatter, I have to chose either. Is it possible to run both using the above API?
I found a way of running multiple formatters in VSCode. Just run the formatting command of one extension inside the your other extension.
Inside my own extention.ts:
const firstFormatter = commands.executeCommand('editor.action.formatDocument');
firstFormatter.then(() => myFormat());
Like this, any custom extension can sequentially format the document with multiple formatters.

Eclipse Plugin Development: Adding items to a working set with the path of the item?

Hello,
I'm an eclipse plugin development newbie looking for pointers to get me started on a particular project.
I am trying to build an eclipse plugin that will automatically construct a working set from a text file that simply consists of a list of file path names. The files/items need not share any parent directories. The rough idea is represented in the following diagram:
I am not asking for the solution to this task. That's the over-arching goal. To achieve that goal, I want to conquer some smaller goals first.
With that in mind, here's the smaller goal I'm currently trying to tackle:
In Eclipse, how can I prompt the user for a single file's path, and then add that file to an existing working set?
I'm not sure where to start. Should I work directly off of the existing org.eclipse.ui.workingSets extension point? Or should I use a collection of other extension points? How do I convert strings into something that can be added to a working set? Do I write code that directly modifies the workingsets.xml file?
Even with a much simpler goal, I still feel quite overwhelmed with the vastness of eclipse extension options. There are probably many ways to go about implementing something like this, but I just need one to get started.
Thanks a bunch!
To manipulate working sets you use the working set manager interface IWorkingSetManager. Get this with:
IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager();
From this you can get a particular working by name with:
IWorkingSet workingSet = manager.getWorkingSet("name");
The contents of a working set is an array of IAdaptable objects:
IAdaptable [] contents = workingSet.getElements();
You add to the contents by adding to this array and setting the contents:
IAdaptable [] newContents
.... get new array with old contents + new contents
workingSet.setElements(newContents);
A lot of Eclipse objects implement IAdaptable, for a file in the workspace you would use IFile. You can use dialogs such as ResourceSelectionDialog to select resources from the workspace.

Is there auto-import functionality for typescript in Visual Studio Code?

Is there any shortcut that will allow me to auto generate my typescript imports? Like hitting ctrl+space next to the type name and having the import declaration placed at the top of the file. If not, what about intellisense for filling out the module reference path so that I wont have to do it manually? I would really love to use vscode but having to do manual imports for typescript is killing me.
There are rumors of making it support tsconfig.json (well, better than rumors). This will allow us to be able to use all files for our references.
Your feature would be to create an auto import of all commonly used 3rd party libs into the typings. Perhaps auto scan the files and create a list of ones to go gather. Wouldn't it be fine to just have a quick way to add several of these using tsd directly from Code (interactively)?
I believe the plugin called "TypeScript Importer" does exactly what You mean: https://marketplace.visualstudio.com/items?itemName=pmneo.tsimporter .
Automatically searches for TypeScript definitions in workspace files and provides all known symbols as completion item to allow code completion.
With it You can truly use Ctrl+Space to choose what exactly You would like to be imported.
You can find and install it from Ctrl+Shift+X menu or just by pasting ext install tsimporter in Quick Open menu opened with Ctrl+P.
I know a solution for Visual Studio (not Visual Studio Code, I'm using the 2015 Community edition, which is free), but it needs some setup and coding -- however, I find the results to be adequate.
Basically, in Visual Studio, when using the Web-Essentials extension, .ts files can be dragged into the active document to automatically generate a relative reference path comment:
/// <reference path="lib/foo.ts" />
With which of course we might as well wipe it, because it's an import statement we need, not a reference comment.
For this reason, I recently wrote the following command snippet for Visual Commander, but it should be easily adaptable to other use casese as well. With Visual Commander, your drag the needed imports into the open document, then run the following macro:
using EnvDTE;
using EnvDTE80;
using System.Text.RegularExpressions;
public class C : VisualCommanderExt.ICommand
{
// Called by Visual Commander extension.
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
TextDocument doc = (TextDocument)(DTE.ActiveDocument.Object("TextDocument"));
var p = doc.StartPoint.CreateEditPoint();
string s = p.GetText(doc.EndPoint);
p.ReplaceText(doc.EndPoint, this.ReplaceReferences(s), (int)vsEPReplaceTextOptions.vsEPReplaceTextKeepMarkers);
}
// Converts "reference" syntax to "ES6 import" syntax.
private string ReplaceReferences(string text)
{
string pattern = "\\/\\/\\/ *<reference *path *= *\"([^\"]*)(?:\\.ts)\" *\\/>";
var regex = new Regex(pattern);
var matches = Regex.Matches(text, pattern);
return Regex.Replace(text, pattern, "import {} from \"./$1\";");
}
}
When running this snippet, all reference comments in the active document will be replaced with import statements. The above example is converted to:
import {} from "./lib/foo";
This has just been released in version 1.18.
From the release notes:
Auto Import for JavaScript and TypeScript
Speed up your coding with auto imports for JavaScript and TypeScript. The suggestion list now includes all exported symbols in the current project. Just start typing:
If you choose one of the suggestion from another file or module, VS Code will automatically add an import for it. In this example, VS Code adds an import for Hercules to the top of the file:
Auto imports requires TypeScript 2.6+. You can disable auto imports by setting "typescript.autoImportSuggestions.enabled": false.
The files attributes in the tsconfig.json file allows you to set your reference imports in your whole project. It is supported with Visual Studio Code, but please note that if you're using a specific build chain (such as tsify/browserify) it might not work when compiling your project.