mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-06-13 07:10:26 +08:00
add better sample for virtual documents
This commit is contained in:
2
virtual-document-sample/.gitignore
vendored
Normal file
2
virtual-document-sample/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
out
|
||||
node_modules
|
||||
21
virtual-document-sample/.vscode/launch.json
vendored
Normal file
21
virtual-document-sample/.vscode/launch.json
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
// A launch configuration that compiles the extension and then opens it inside a new window
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Launch Extension",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"runtimeExecutable": "${execPath}",
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceRoot}"
|
||||
],
|
||||
"stopOnEntry": false,
|
||||
"sourceMaps": true,
|
||||
"outFiles": [
|
||||
"${workspaceRoot}/out/src/**/*.js"
|
||||
],
|
||||
"preLaunchTask": "npm: watch"
|
||||
}
|
||||
]
|
||||
}
|
||||
11
virtual-document-sample/.vscode/settings.json
vendored
Normal file
11
virtual-document-sample/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
// Place your settings in this file to overwrite default and user settings.
|
||||
{
|
||||
"files.exclude": {
|
||||
"out": false // set this to true to hide the "out" folder with the compiled JS files
|
||||
},
|
||||
"search.exclude": {
|
||||
"out": true // set this to false to include "out" folder in search results
|
||||
},
|
||||
"typescript.tsdk": "./node_modules/typescript/lib", // we want to use the TS server from our node_modules folder to control its version
|
||||
"typescript.tsc.autoDetect": "off" // Turn off tsc task auto detection since we have the necessary task as npm scripts
|
||||
}
|
||||
20
virtual-document-sample/.vscode/tasks.json
vendored
Normal file
20
virtual-document-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
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
9
virtual-document-sample/.vscodeignore
Normal file
9
virtual-document-sample/.vscodeignore
Normal file
@ -0,0 +1,9 @@
|
||||
.vscode/**
|
||||
typings/**
|
||||
out/test/**
|
||||
test/**
|
||||
src/**
|
||||
**/*.map
|
||||
.gitignore
|
||||
tsconfig.json
|
||||
vsc-extension-quickstart.md
|
||||
14
virtual-document-sample/README.md
Normal file
14
virtual-document-sample/README.md
Normal file
@ -0,0 +1,14 @@
|
||||
# Virtual Document Sample
|
||||
|
||||
This is a sample extension that shows how to add virtual documents to the editor.
|
||||
|
||||

|
||||
|
||||
|
||||
## VS Code API
|
||||
|
||||
### `vscode` module
|
||||
|
||||
- [`workspace.registerTextDocumentContentProvider`](https://code.visualstudio.com/docs/extensionAPI/vscode-api#workspace.registerTextDocumentContentProvider)
|
||||
- [`commands.registerCommand`](https://code.visualstudio.com/docs/extensionAPI/vscode-api#commands.registerCommand)
|
||||
- [`window.showInputBox`](https://code.visualstudio.com/docs/extensionAPI/vscode-api#window.showInputBox)
|
||||
2447
virtual-document-sample/package-lock.json
generated
Normal file
2447
virtual-document-sample/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
42
virtual-document-sample/package.json
Normal file
42
virtual-document-sample/package.json
Normal file
@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "virtual-document-sample",
|
||||
"displayName": "Cowsay in virtual documents",
|
||||
"description": "A sample for virtual document",
|
||||
"version": "0.0.1",
|
||||
"publisher": "vscode-samples",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Microsoft/vscode-extension-samples"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/Microsoft/vscode-extension-samples/issues"
|
||||
},
|
||||
"engines": {
|
||||
"vscode": "^1.29.0"
|
||||
},
|
||||
"categories": [
|
||||
"Other"
|
||||
],
|
||||
"activationEvents": [
|
||||
"onCommand:cowsay.say"
|
||||
],
|
||||
"main": "./out/extension",
|
||||
"contributes": {
|
||||
"commands": {
|
||||
"command": "cowsay.say",
|
||||
"title": "cowsay"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "tsc -p ./",
|
||||
"watch": "tsc -watch -p ./",
|
||||
"postinstall": "node ./node_modules/vscode/bin/install"
|
||||
},
|
||||
"dependencies": {
|
||||
"cowsay": "1.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^3.1.6",
|
||||
"vscode": "^1.1.21"
|
||||
}
|
||||
}
|
||||
BIN
virtual-document-sample/preview.png
Normal file
BIN
virtual-document-sample/preview.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 35 KiB |
14
virtual-document-sample/src/cowsay.d.ts
vendored
Normal file
14
virtual-document-sample/src/cowsay.d.ts
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
declare module 'cowsay' {
|
||||
|
||||
export interface CowsayOptions {
|
||||
text: string;
|
||||
cow?: string;
|
||||
eyes?: string;
|
||||
tongue?: string;
|
||||
wrap?: boolean;
|
||||
wrapLength?: number;
|
||||
mode?: 'b' | 'd' | 'g' | 'p' | 's' | 't' | 'w' | 'y'
|
||||
}
|
||||
|
||||
export function say(options: CowsayOptions): string;
|
||||
}
|
||||
31
virtual-document-sample/src/extension.ts
Normal file
31
virtual-document-sample/src/extension.ts
Normal file
@ -0,0 +1,31 @@
|
||||
/*---------------------------------------------------------
|
||||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as cowsay from 'cowsay';
|
||||
|
||||
export function activate({ subscriptions }: vscode.ExtensionContext) {
|
||||
|
||||
// register a content provider for the cowsay-scheme
|
||||
const myScheme = 'cowsay';
|
||||
const myProvider = new class implements vscode.TextDocumentContentProvider {
|
||||
provideTextDocumentContent(uri: vscode.Uri): string {
|
||||
// simply invoke cowsay, use uri-path as text
|
||||
return cowsay.say({ text: uri.path });
|
||||
}
|
||||
}
|
||||
subscriptions.push(vscode.workspace.registerTextDocumentContentProvider(myScheme, myProvider));
|
||||
|
||||
// register a command that opens a cowsay-document
|
||||
subscriptions.push(vscode.commands.registerCommand('cowsay.say', async () => {
|
||||
let what = await vscode.window.showInputBox({ placeHolder: 'cowsay...' });
|
||||
if (what) {
|
||||
let uri = vscode.Uri.parse('cowsay:' + what);
|
||||
let doc = await vscode.workspace.openTextDocument(uri);
|
||||
await vscode.window.showTextDocument(doc, { preview: false });
|
||||
}
|
||||
}));
|
||||
}
|
||||
17
virtual-document-sample/tsconfig.json
Normal file
17
virtual-document-sample/tsconfig.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"outDir": "out",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"strict": true,
|
||||
"sourceMap": true,
|
||||
"rootDir": "src"
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
".vscode-test"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user