A collection of utilities for developing vscode extensions.
npm install --save vscode-extras
A convenience wrapper around showInformationMessage
, showWarningMessage
and showErrorMessage
.
import {alert} from 'vscode-extras';
alert.error ( 'Some error' );
alert.info ( 'Some information' );
alert.warn ( 'Some warning' );
The re-exported function from nanoexec
, for conveniently executing a native binary.
import {exec} from 'vscode-extras';
const {ok, code, stdout, stderr} = await exec ( 'echo', ['example'] );
Get the language of the currently active file, if it's a textual one.
import {getActiveFileLanguage} from 'vscode-extras';
const language = getActiveFileLanguage ();
Get the path of the currently active file, which could be either a textual or binary file.
import {getActiveFilePath} from 'vscode-extras';
const filePath = getActiveFilePath ();
Get the path of the currently active binary file, where binary means the file is not being edited with a textual editor.
import {getActiveBinaryFilePath} from 'vscode-extras';
const filePath = getActiveBinaryFilePath ();
Get the path of the currently active textual file, where textual means the file is being edited with a textual editor.
import {getActiveTextualFilePath} from 'vscode-extras';
const filePath = getActiveTextualFilePath ();
Get the current active file, if it's an untitled one.
import {getActiveUntitledFile} from 'vscode-extras';
const file = getActiveUntitledFile ();
file.path; // 'Untitled-1'
file.content; // 'Some content'
Get the path of the currently active folder, meaning the folder containing the currently active file, or the project root.
import {getActiveFolderPath} from 'vscode-extras';
const folderPath = getActiveFolderPath ();
Get the configuration object for a given extension.
import {getConfig} from 'vscode-extras';
const config = getConfig ( 'myExtension' );
Infer the path of the nearest git repository, considering the currently open file also.
import {getGitRootPath} from 'vscode-extras';
const rootPath = getGitRootPath ();
Get the paths of all the currently open files, across all visible tab groups.
import {getOpenFilesPaths} from 'vscode-extras';
const filesPaths = getOpenFilesPaths ();
Get the paths of all the currently open binary files, across all visible tab groups.
import {getOpenBinaryFilesPaths} from 'vscode-extras';
const filesPaths = getOpenBinaryFilesPaths ();
Get the paths of all the currently open textual files, across all visible tab groups.
import {getOpenTextualFilesPaths} from 'vscode-extras';
const filesPaths = getOpenTextualFilesPaths ();
Get the currently open untitled files, across all visible tab groups.
import {getOpenUntitledFiles} from 'vscode-extras';
const files = getOpenUntitledFiles ();
files[0].path; // 'Untitled-1'
files[0].content; // 'Some content'
Get the content of the package.json
file, as provided by find-up-json
, considering the currently open file also.
import {getPackage} from 'vscode-extras';
const pkg = getPackage ();
Infer the path of the nearest folder containing a package.json
file, considering the currently open file also.
import {getPackageRootPath} from 'vscode-extras';
const rootPath = getPackageRootPath ();
Infer the root path of the current project, considering the currently open file also.
import {getProjectRootPath} from 'vscode-extras';
const rootPath = getProjectRootPath ();
Get all the root paths that make up the current workspace.
import {getProjectRootPaths} from 'vscode-extras';
const rootPaths = getProjectRootPaths ();
Check if the current instance of vscode is the insiders one.
import {isInsiders} from 'vscode-extras';
const insiders = isInsiders ();
A little wrapper around tiny-browser-open
and tiny-open
, for opening a file with a custom app.
import {openInApp} from 'vscode-extras';
openInApp ( 'https://example.com', 'firefox' );
openInApp ( '/path/to/project', 'Visual Studio Code' );
A little wrapper around the built-in vscode.diff
command.
import {openInDiffEditor} from 'vscode-extras';
const leftFilePath = '/path/to/left/file';
const rightFilePath = '/path/to/right/file';
openInDiffEditor ( leftFilePath, rightFilePath, 'Custom Title' );
A little wrapper around the built-in vscode.open
command, with support for TextDocumentShowOptions
options.
import vscode from 'vscode';
import {openInEditor} from 'vscode-extras';
openInEditor ( '/path/to/file', {
preview: false
viewVolumn: vscode.ViewColumn.Beside
});
A little wrapper around vscode.env.openInExternal
, useful for opening a URL in the default browser.
import {openInExternal} from 'vscode-extras';
openInExternal ( 'https://example.com' );
Open a folder in a vscode window, either the current one or a new one.
import {openInWindow} from 'vscode-extras';
openInWindow ( '/path/to/folder' ); // Open in current window
openInWindow ( '/path/to/folder', true ); // Open in new window
A convenience wrapper around showInformationMessage
, showInputBox
and showQuickPick
.
import {prompt} from 'vscode-extras';
const boolean = await prompt.boolean ( 'Do you want to continue?' );
const string = await prompt.string ( 'Wha is your name?' );
const password = await prompt.password ( 'What is your password?' );
const pick = await prompt.pick ( 'What is your favorite color?', ['red', 'green', 'blue'] );
MIT © Fabio Spampinato