mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-04-27 16:55:44 +08:00
Proposed API sample. Fix Microsoft/vscode#33358
This commit is contained in:
4
proposed-api-sample/.gitignore
vendored
Normal file
4
proposed-api-sample/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
out
|
||||
node_modules
|
||||
.vscode-test/
|
||||
*.vsix
|
||||
22
proposed-api-sample/.vscode/launch.json
vendored
Normal file
22
proposed-api-sample/.vscode/launch.json
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
// A launch configuration that compiles the extension and then opens it inside a new window
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [{
|
||||
"name": "Run Extension",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"runtimeExecutable": "${execPath}",
|
||||
"args": [
|
||||
// "--enable-proposed-api",
|
||||
"--extensionDevelopmentPath=${workspaceFolder}"
|
||||
],
|
||||
"outFiles": [
|
||||
"${workspaceFolder}/out/**/*.js"
|
||||
],
|
||||
"preLaunchTask": "npm: watch"
|
||||
}
|
||||
]
|
||||
}
|
||||
20
proposed-api-sample/.vscode/tasks.json
vendored
Normal file
20
proposed-api-sample/.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "watch",
|
||||
"problemMatcher": "$tsc-watch",
|
||||
"isBackground": true,
|
||||
"presentation": {
|
||||
"reveal": "never"
|
||||
},
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
21
proposed-api-sample/README.md
Normal file
21
proposed-api-sample/README.md
Normal file
@ -0,0 +1,21 @@
|
||||
# Proposed API Sample
|
||||
|
||||
This is a sample illustrating how to use [Proposed API](https://vscode-ext-docs.azurewebsites.net/api/advanced-topics/using-proposed-api) in VS Code. It is adapted from the [Hello Code Sample](/hellocode-sample).
|
||||
|
||||
The proposed API being used is `vscode.env.clipboard.readText()`. See details here: https://github.com/Microsoft/vscode/issues/217#issuecomment-433963587.
|
||||
|
||||
## VS Code API
|
||||
|
||||
### Proposed API
|
||||
|
||||
- [`env.clipboard`](https://github.com/Microsoft/vscode/blob/master/src/vs/vscode.proposed.d.ts#L49)
|
||||
- [`Clipboard.readText`](https://github.com/Microsoft/vscode/blob/master/src/vs/vscode.proposed.d.ts#L44)
|
||||
|
||||
## Running the Sample
|
||||
|
||||
This sample runs on VS Code Insider with commit [4626bc0e1b679d555dd6f034ece35ffc394b3bb7](https://github.com/Microsoft/vscode/commit/4626bc0e1b679d555dd6f034ece35ffc394b3bb7). If VS Code updated the Clipboard API in the future, you must re-download [`vscode.proposed.d.ts`](https://github.com/Microsoft/vscode/blob/master/src/vs/vscode.proposed.d.ts) to `src/vscode.proposed.d.ts` and update your API usage accordingly.
|
||||
|
||||
- Run `npm install` in terminal to install dependencies
|
||||
- Run the `Run Extension` target in the Debug View. This will:
|
||||
- Start a task `npm: watch` to compile the code
|
||||
- Run the extension in a new VS Code window
|
||||
BIN
proposed-api-sample/demo.gif
Normal file
BIN
proposed-api-sample/demo.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 846 KiB |
2237
proposed-api-sample/package-lock.json
generated
Normal file
2237
proposed-api-sample/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
37
proposed-api-sample/package.json
Normal file
37
proposed-api-sample/package.json
Normal file
@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "hellocode-sample",
|
||||
"displayName": "hellocode-sample",
|
||||
"description": "HelloWorld example for VS Code",
|
||||
"version": "0.0.1",
|
||||
"publisher": "vscode-samples",
|
||||
"enableProposedApi": true,
|
||||
"engines": {
|
||||
"vscode": "^1.27.0"
|
||||
},
|
||||
"categories": [
|
||||
"Other"
|
||||
],
|
||||
"activationEvents": [
|
||||
"onCommand:extension.helloCode"
|
||||
],
|
||||
"main": "./out/extension.js",
|
||||
"contributes": {
|
||||
"commands": [
|
||||
{
|
||||
"command": "extension.helloCode",
|
||||
"title": "Hello Code"
|
||||
}
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "npm run compile",
|
||||
"compile": "tsc -p ./",
|
||||
"watch": "tsc -watch -p ./",
|
||||
"postinstall": "node ./node_modules/vscode/bin/install"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^8.10.25",
|
||||
"typescript": "^2.6.1",
|
||||
"vscode": "^1.1.21"
|
||||
}
|
||||
}
|
||||
30
proposed-api-sample/src/extension.ts
Normal file
30
proposed-api-sample/src/extension.ts
Normal file
@ -0,0 +1,30 @@
|
||||
// The module 'vscode' contains the VS Code extensibility API
|
||||
// Import the module and reference it with the alias vscode in your code below
|
||||
import * as vscode 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: vscode.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 "hellocode-sample" is now active!');
|
||||
|
||||
// The command has been defined in the package.json file
|
||||
// Now provide the implementation of the command with registerCommand
|
||||
// The commandId parameter must match the command field in package.json
|
||||
let disposable = vscode.commands.registerCommand('extension.helloCode', () => {
|
||||
// The code you place here will be executed every time your command is executed
|
||||
|
||||
// Display a message box to the user
|
||||
// You are using Proposed API here!
|
||||
vscode.env.clipboard.readText().then(clipboardText => {
|
||||
vscode.window.showInformationMessage(`I'm using Proposed API here! Clipboard text is: ${clipboardText}`);
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
context.subscriptions.push(disposable);
|
||||
}
|
||||
|
||||
// this method is called when your extension is deactivated
|
||||
export function deactivate() {}
|
||||
1266
proposed-api-sample/src/vscode.proposed.d.ts
vendored
Normal file
1266
proposed-api-sample/src/vscode.proposed.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
11
proposed-api-sample/tsconfig.json
Normal file
11
proposed-api-sample/tsconfig.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"outDir": "out",
|
||||
"lib": ["es6"],
|
||||
"sourceMap": true,
|
||||
"rootDir": "src"
|
||||
},
|
||||
"exclude": ["node_modules", ".vscode-test"]
|
||||
}
|
||||
Reference in New Issue
Block a user