Box-Of-Hats / vscode-extension-author-snippets

A collection of snippets for writing VSCode extensions.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

vscode-extension-author-snippets README

A collection of snippets for writing extensions for VSCode.

Snippets

Get selected text

Get the currently selected text in the active document.

let textEditor = vscode.window.activeTextEditor;

if (!textEditor) {
    vscode.window.showErrorMessage("No active text editor found.");
    return;
}
let selectedText = textEditor.document.getText(textEditor.selection);

Create new file/document

Create a new file in a given language, with content.

vscode.workspace
    .openTextDocument({
        language: "plaintext",
        content: "file contents here"
    })
    .then(doc => {
        vscode.window.showTextDocument(doc).then(e => {
            vscode.commands.executeCommand("editor.action.formatDocument");
        });
    });

About

A collection of snippets for writing VSCode extensions.