Ejemplo n.º 1
0
export function activate(context: vscode.ExtensionContext) {
    class BrowserContentProvider implements vscode.TextDocumentContentProvider {
        provideTextDocumentContent(uri: vscode.Uri, token: vscode.CancellationToken): string {
            // TODO: detect failure to load page (e.g. google.com) and display error to user.
            return `<iframe src="${uri}" frameBorder="0" style="width: 100%; height: 100%" />`;
        }
    }
    let provider = new BrowserContentProvider();

    // Handle http:// and https://.
    let registrationHTTPS = vscode.workspace.registerTextDocumentContentProvider('https', provider);
    let registrationHTTP = vscode.workspace.registerTextDocumentContentProvider('http', provider);

    // urlIsValid returns true if url is valid; false otherwise.
    // TODO: test more robustly.
    function urlIsValid(url: string): boolean {
        if (url.startsWith("http://") || url.startsWith("https://")) {
            return true;
        }
        return false;
    }

    let disposable = vscode.commands.registerCommand('extension.openURL', () => {
        let opts: vscode.InputBoxOptions = {
            prompt: "URL",
            value: "https://",
            validateInput: (url) => {
                if (urlIsValid(url)) {
                    return null;
                }
                return "Invalid URL.";
            },
        };
        vscode.window.showInputBox(opts).then(
            (url) => {
                if (!urlIsValid(url)) {
                    return;
                }

                let uri = vscode.Uri.parse(url);

                // Determine column to place browser in.
                let col: vscode.ViewColumn;
                let ae = vscode.window.activeTextEditor;
                if (ae != undefined) {
                    col = ae.viewColumn || vscode.ViewColumn.One;
                } else {
                    col = vscode.ViewColumn.One;
                }

                return vscode.commands.executeCommand('vscode.previewHtml', uri, col).then((success) => {
                }, (reason) => {
                    vscode.window.showErrorMessage(reason);
                }
                );
            });
    });

    context.subscriptions.push(disposable);
}
Ejemplo n.º 2
0
	test('registerTextDocumentContentProvider, constrains', function() {

		// built-in
		assert.throws(function() {
			workspace.registerTextDocumentContentProvider('untitled', { provideTextDocumentContent() { return null; } });
		});
		// built-in
		assert.throws(function() {
			workspace.registerTextDocumentContentProvider('file', { provideTextDocumentContent() { return null; } });
		});

		// duplicate registration
		let registration = workspace.registerTextDocumentContentProvider('foo', {
			provideTextDocumentContent(uri) {
				return uri.toString();
			}
		});
		assert.throws(function() {
			workspace.registerTextDocumentContentProvider('foo', { provideTextDocumentContent() { return null; } });
		});

		// unregister & register
		registration.dispose();
		registration = workspace.registerTextDocumentContentProvider('foo', { provideTextDocumentContent() { return null; } });
		registration.dispose();

		// missing scheme
		return workspace.openTextDocument(Uri.parse('notThere://foo/far/boo/bar')).then(() => {
			assert.ok(false, 'expected failure')
		}, err => {
			// expected
		})
	});
Ejemplo n.º 3
0
export function activate(context: ExtensionContext) {
    
    let version = "5.20161.151";
    let previewUri: Uri;
    let csvProvider = new csv.CsvDocumentContentProvider(version);
    let csvSubscription = workspace.registerTextDocumentContentProvider('csv-preview', csvProvider);
    let excelProvider = new excel.ExcelDocumentContentProvider(version);
    let excelSubscription = workspace.registerTextDocumentContentProvider('excel-preview', excelProvider);
    
    workspace.onDidChangeTextDocument((e: TextDocumentChangeEvent) => {
        if (e.document === window.activeTextEditor.document) {
            csvProvider.update(previewUri);
        }
    });
    
    let csvCommand = commands.registerCommand('csv.preview', () => {
        let file = window.activeTextEditor.document.fileName;
        if (file.startsWith("/")) {
            file = file.substring(1);
        }
        previewUri = Uri.parse(`csv-preview://preview/${file}`);
        return commands.executeCommand('vscode.previewHtml', previewUri, ViewColumn.One).then((success) => {
        }, (reason) => {
            window.showErrorMessage(reason);
        });
    });
    
    let excelCommand = commands.registerCommand('excel.preview', () => {
        var files = workspace.findFiles('**/*.xls*', '**/node_modules/**').then((value: Uri[]) => {
            var path = workspace.rootPath;
            var uris = value.map(function (u) {
                return u.path.slice(path.length + 1);
            });
            if (!path.startsWith("/")) {
                path = "/" + path;
            }
            window.showQuickPick(uris).then(sel => {
                excelProvider.setPath(sel);
                previewUri = Uri.parse(`excel-preview://preview${path}/${sel}`);
                return commands.executeCommand('vscode.previewHtml', previewUri, ViewColumn.One).then((success) => {
                }, (reason) => {
                    window.showErrorMessage(reason);
                });                
            });
        });
    });
    
    context.subscriptions.push(csvCommand, csvSubscription);
    context.subscriptions.push(excelCommand, excelSubscription);
}
Ejemplo n.º 4
0
function registerPreviewing(context: vscode.ExtensionContext) {
    let previewUri = vscode.Uri.parse('songtools-preview://authority/songtools-preview')
    let songToolsPreviewProvider = new SongToolsPreviewContentProvider();
    context.subscriptions.push(vscode.workspace.registerTextDocumentContentProvider(previewUri.scheme, songToolsPreviewProvider));

    let previewDocument = function(document: vscode.TextDocument) {
        if (document === vscode.window.activeTextEditor.document) {
            songToolsPreviewProvider.update(previewUri);
        }
    }
    
    vscode.workspace.onDidChangeTextDocument((e: vscode.TextDocumentChangeEvent) => {
        previewDocument(e.document);
    });
    vscode.window.onDidChangeActiveTextEditor((e: vscode.TextEditor) => {
        previewDocument(e.document);
    });
    
    vscode.commands.registerCommand('songtools.showPreview', () => {
        return vscode.commands.executeCommand('vscode.previewHtml', previewUri, vscode.ViewColumn.Two).then((success) => {
        }, (error) => {
            vscode.window.showErrorMessage(error);
        });
    });
}
Ejemplo n.º 5
0
export async function activateLanguageServer(context: vscode.ExtensionContext) {
    const r = RLanguage.language;
    // The server is implemented in C#
    const commandOptions = { stdio: "pipe" };
    const serverModule = context.extensionPath + "/server/Microsoft.R.LanguageServer.dll";

    // If the extension is launched in debug mode then the debug server options are used
    // Otherwise the run options are used
    const serverOptions: languageClient.ServerOptions = {
        debug: { command: "dotnet", args: [serverModule, "--debug"], options: commandOptions },
        run: { command: "dotnet", args: [serverModule], options: commandOptions },
    };

    // Options to control the language client
    const clientOptions: languageClient.LanguageClientOptions = {
        // Register the server for R documents
        documentSelector: [r],
        synchronize: {
            configurationSection: r,
        },
    };

    // Create the language client and start the client.
    client = new languageClient.LanguageClient(r, "R Tools", serverOptions, clientOptions);
    context.subscriptions.push(client.start());

    await client.onReady();

    rEngine = new REngine(client);
    const resultsView = new ResultsView();
    context.subscriptions.push(vscode.workspace.registerTextDocumentContentProvider("r", resultsView));

    commands = new Commands(rEngine, resultsView);
    context.subscriptions.push(...commands.activateCommandsProvider());
}
Ejemplo n.º 6
0
	test('api-command: vscode.diff', function () {

		let registration = workspace.registerTextDocumentContentProvider('sc', {
			provideTextDocumentContent(uri) {
				return `content of URI <b>${uri.toString()}</b>#${Math.random()}`;
			}
		});


		let a = commands.executeCommand('vscode.diff', Uri.parse('sc:a'), Uri.parse('sc:b'), 'DIFF').then(value => {
			assert.ok(value === void 0);
			registration.dispose();
		});

		let b = commands.executeCommand('vscode.diff', Uri.parse('sc:a'), Uri.parse('sc:b')).then(value => {
			assert.ok(value === void 0);
			registration.dispose();
		});

		let c = commands.executeCommand('vscode.diff', Uri.parse('sc:a'), Uri.parse('sc:b'), 'Title', { selection: new Range(new Position(1, 1), new Position(1, 2)) }).then(value => {
			assert.ok(value === void 0);
			registration.dispose();
		});

		let d = commands.executeCommand('vscode.diff').then(() => assert.ok(false), () => assert.ok(true));
		let e = commands.executeCommand('vscode.diff', 1, 2, 3).then(() => assert.ok(false), () => assert.ok(true));

		return Promise.all([a, b, c, d, e]);
	});
Ejemplo n.º 7
0
export function activate(context: ExtensionContext) 
{
	const provider = new ContentProvider();

	const providerRegistrations = Disposable.from(
		workspace.registerTextDocumentContentProvider(ContentProvider.scheme, provider)
	);
    
	const commandRegistration = commands.registerTextEditorCommand('editor.printFunctions', editor => {
        return provider.newDocument(editor);
	});

    let contextMenuSwitchSort = commands.registerCommand('contextmenu.switchSort', () => {
        provider.updateDocument(true);
    });
    
    let contextMenuRefresh = commands.registerCommand('contextmenu.refresh', () => {
        provider.updateDocument(false);
    });
        
	context.subscriptions.push(
		provider,
        commandRegistration,
        contextMenuSwitchSort,
        contextMenuRefresh,
        providerRegistrations
    );
}
Ejemplo n.º 8
0
export function activate(ctx: vsc.ExtensionContext) {
    console.log('activate extension');
    // expose global and workspace state to the entire extension
    GlobalState = ctx.globalState;
    WorkspaceState = ctx.workspaceState;
    
	// register palette commands
    ctx.subscriptions.push(
        vsc.commands.registerTextEditorCommand('xmlTools.minifyXml', TextEditorCommands.minifyXml),
        vsc.commands.registerTextEditorCommand('xmlTools.evaluateXPath', TextEditorCommands.evaluateXPath),
        vsc.commands.registerTextEditorCommand('xmlTools.executeXQuery', TextEditorCommands.executeXQuery),
        vsc.commands.registerTextEditorCommand('xmlTools.viewXmlTree', TextEditorCommands.viewXmlTree)
    );
	
	// register language feature providers
    ctx.subscriptions.push(
        vsc.languages.registerDocumentFormattingEditProvider(LANG_XML, new XmlFormattingEditProvider()),
        vsc.languages.registerDocumentRangeFormattingEditProvider(LANG_XML, new XmlFormattingEditProvider()),
        
        vsc.languages.registerCompletionItemProvider(LANG_XQUERY, new XQueryCompletionItemProvider(), ':', '$')
    );
    
    // register workspace feature providers
    ctx.subscriptions.push(
        vsc.workspace.registerTextDocumentContentProvider(XmlTreeDocumentContentProvider.SCHEME, new XmlTreeDocumentContentProvider())
    );
    
    // listen to editor events (for linting)
    ctx.subscriptions.push(
        vsc.window.onDidChangeActiveTextEditor(_handleChangeActiveTextEditor),
        vsc.window.onDidChangeTextEditorSelection(_handleChangeTextEditorSelection)
    );
}
Ejemplo n.º 9
0
export function activate(context: vscode.ExtensionContext) {
    cljConnection.setCljContext(context);
    context.subscriptions.push(nreplController);
    cljConnection.disconnect(false);
    var config = vscode.workspace.getConfiguration('clojureVSCode');
    if (config.autoStartNRepl) {
        cljConnection.startNRepl();
    }

    maybeActivateFormatOnSave();

    const testResultDataProvidier = buildTestProvider();

    vscode.commands.registerCommand('clojureVSCode.manuallyConnectToNRepl', cljConnection.manuallyConnect);
    vscode.commands.registerCommand('clojureVSCode.stopDisconnectNRepl', cljConnection.disconnect);
    vscode.commands.registerCommand('clojureVSCode.startNRepl', cljConnection.startNRepl);

    const evaluationResultChannel = vscode.window.createOutputChannel('Evaluation results');
    vscode.commands.registerCommand('clojureVSCode.eval', () => clojureEval(evaluationResultChannel));
    vscode.commands.registerCommand('clojureVSCode.evalAndShowResult', () => clojureEvalAndShowResult(evaluationResultChannel));

    vscode.commands.registerCommand('clojureVSCode.testNamespace', () => testNamespace(evaluationResultChannel, testResultDataProvidier));
    vscode.commands.registerCommand('clojureVSCode.runAllTests', () => runAllTests(evaluationResultChannel, testResultDataProvidier));
    vscode.window.registerTreeDataProvider('clojure', testResultDataProvidier);

    vscode.commands.registerTextEditorCommand('clojureVSCode.formatFile', formatFile);

    context.subscriptions.push(vscode.languages.registerCompletionItemProvider(CLOJURE_MODE, new ClojureCompletionItemProvider(), '.', '/'));
    context.subscriptions.push(vscode.languages.registerDefinitionProvider(CLOJURE_MODE, new ClojureDefinitionProvider()));
    context.subscriptions.push(vscode.languages.registerHoverProvider(CLOJURE_MODE, new ClojureHoverProvider()));
    context.subscriptions.push(vscode.languages.registerSignatureHelpProvider(CLOJURE_MODE, new ClojureSignatureProvider(), ' ', '\n'));

    vscode.workspace.registerTextDocumentContentProvider('jar', new JarContentProvider());
    vscode.languages.setLanguageConfiguration(CLOJURE_MODE.language, ClojureLanguageConfiguration);
}
Ejemplo n.º 10
0
export function activate(context: vscode.ExtensionContext) {
    let registration = vscode.workspace.registerTextDocumentContentProvider('markdown', {
        provideTextDocumentContent(uri) {
            return new Promise((approve, reject) => {
                fs.readFile(uri.fsPath, (error, buffer) => {
                    if (error) {
                        return reject(error);
                    }
                    
                    const res = md.render(buffer.toString());

                    const baseCss = `<link rel="stylesheet" type="text/css" href="${path.join(__dirname, '..', '..', 'media', 'markdown.css')}" >`;
                    const codeCss = `<link rel="stylesheet" type="text/css" href="${path.join(__dirname, '..', '..', 'media', 'tomorrow.css')}" >`;

                    approve(baseCss + codeCss + res);
                });
            });
        }
    });

    let d1 = vscode.commands.registerCommand('extension.previewMarkdown', () => openPreview());
    let d2 = vscode.commands.registerCommand('extension.previewMarkdownSide', () => openPreview(true));

    context.subscriptions.push(d1, d2, registration);
}