64 lines
2.1 KiB
TypeScript
64 lines
2.1 KiB
TypeScript
// The module 'vscode' contains the VS Code extensibility API
|
|
// Import the module and reference it with the alias vscode in your code below
|
|
import {
|
|
commands, languages, window, workspace,WorkspaceFolder, ExtensionContext, Memento,
|
|
TextEditor, TextEditorSelectionChangeEvent, TextEditorSelectionChangeKind, DiagnosticCollection, Uri
|
|
} from "vscode";
|
|
|
|
// this method is called when your extension is activated
|
|
// your extension is activated the very first time the command is executed
|
|
export function activate(context: ExtensionContext) {
|
|
|
|
// Use the console to output diagnostic information (console.log) and errors (console.error)
|
|
// This line of code will only be executed once when your extension is activated
|
|
console.log('Congratulations, your extension "ext1" is now active!');
|
|
|
|
function helloHandler() {
|
|
let path: string;
|
|
if (!workspace.workspaceFolders) {
|
|
path = "none";
|
|
} else {
|
|
let root: WorkspaceFolder;
|
|
if (workspace.workspaceFolders.length === 1) {
|
|
root = workspace.workspaceFolders[0];
|
|
path = root.uri.fsPath;
|
|
} else {
|
|
path="count?";
|
|
}
|
|
|
|
|
|
}
|
|
window.showInformationMessage('Hello World!' + path);
|
|
}
|
|
|
|
function pickHandler(name: string = 'world') {
|
|
window.showInformationMessage('hello', ...['test', 'taco', 'cheeseburger'])
|
|
.then(selection => {
|
|
console.log(selection);
|
|
});
|
|
}
|
|
|
|
function commandHandler(name: string = 'world') {
|
|
console.log(`Hello ${name}!!!`);
|
|
}
|
|
|
|
async function newDocHandler(name: string = 'world') {
|
|
let what = await window.showInputBox({ placeHolder: 'file say?' });
|
|
if (what) {
|
|
let uri = Uri.parse('file:' + what);
|
|
let doc = await workspace.openTextDocument(uri); // calls back into the provider
|
|
await window.showTextDocument(doc, { preview: false });
|
|
}
|
|
}
|
|
commands.registerCommand('ext1.helloWorld', helloHandler);
|
|
commands.registerCommand('ext1.pick', pickHandler);
|
|
|
|
commands.registerCommand('ext1.newDoc', newDocHandler);
|
|
|
|
}
|
|
|
|
// this method is called when your extension is deactivated
|
|
export function deactivate(): void { }
|
|
|
|
// add
|
|
|