add better sample for virtual documents

This commit is contained in:
Johannes Rieken
2018-11-15 18:42:11 +01:00
parent 8e8001f9c5
commit 8724ad4806
12 changed files with 2628 additions and 0 deletions

2
virtual-document-sample/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
out
node_modules

View 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"
}
]
}

View 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
}

View 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
}
}
]
}

View File

@ -0,0 +1,9 @@
.vscode/**
typings/**
out/test/**
test/**
src/**
**/*.map
.gitignore
tsconfig.json
vsc-extension-quickstart.md

View File

@ -0,0 +1,14 @@
# Virtual Document Sample
This is a sample extension that shows how to add virtual documents to the editor.
![cowsay](https://raw.githubusercontent.com/Microsoft/vscode-extension-samples/master/virtual-document-sample/README.md)
## 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

File diff suppressed because it is too large Load Diff

View 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"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

14
virtual-document-sample/src/cowsay.d.ts vendored Normal file
View 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;
}

View 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 });
}
}));
}

View 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"
]
}