Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Add support for showing Flow messages to the User via an output channel #55

Merged
merged 1 commit into from
Dec 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/flowLogging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Adds a gloabl that is used inside consoleAppender.js to output console messages
* to the user, instead of to the developer console.
*/
export function setupLogging(): void {
const channel = vscode.window.createOutputChannel("Flow");
global.flowOutputChannel = channel
}
102 changes: 52 additions & 50 deletions lib/flowMain.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,52 @@
/* @flow */

/*
Copyright (c) 2015-present, Facebook, Inc.
All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
the root directory of this source tree.
*/

// Necessary to get the regenerator runtime, which transpiled async functions need
import * as _ from 'regenerator-runtime/runtime';

import * as vscode from 'vscode';

import {CompletionSupport} from './flowCompletion';
import {HoverSupport} from './flowHover'
import {DeclarationSupport} from './flowDeclaration';
import {setupDiagnostics} from './flowDiagnostics';

import {checkNode, checkFlow, isFlowEnabled} from './utils'

type Context = {
subscriptions: Array<vscode.Disposable>
}

const languages = [
{ language: 'javascript', scheme: 'file' },
'javascriptreact'
]

export function activate(context: Context): void {
//User can disable flow for some projects that previously used flow, but it's not have actual typing
if (!isFlowEnabled()) {
return
}
global.vscode = vscode
checkNode()
checkFlow()
// Language features
languages.forEach(lang => {
context.subscriptions.push(vscode.languages.registerHoverProvider(lang, new HoverSupport));
context.subscriptions.push(vscode.languages.registerDefinitionProvider(lang, new DeclarationSupport()));
context.subscriptions.push(vscode.languages.registerCompletionItemProvider(lang, new CompletionSupport(), '.'));
})
// https://github.com/Microsoft/vscode/issues/7031 Workaround for language scoring for language and in-memory. Check in nearest Insiders build
// context.subscriptions.push(vscode.languages.registerCompletionItemProvider({ language: 'javascript' }, new CompletionSupport(), '.'));
// Diagnostics
setupDiagnostics(context.subscriptions);
}
/* @flow */

/*
Copyright (c) 2015-present, Facebook, Inc.
All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
the root directory of this source tree.
*/

// Necessary to get the regenerator runtime, which transpiled async functions need
import * as _ from 'regenerator-runtime/runtime';

import * as vscode from 'vscode';

import {CompletionSupport} from './flowCompletion';
import {HoverSupport} from './flowHover'
import {DeclarationSupport} from './flowDeclaration';
import {setupDiagnostics} from './flowDiagnostics';

import {checkNode, checkFlow, isFlowEnabled} from './utils'
import {setupLogging} from "./flowLogging"

type Context = {
subscriptions: Array<vscode.Disposable>
}

const languages = [
{ language: 'javascript', scheme: 'file' },
'javascriptreact'
]

export function activate(context: Context): void {
//User can disable flow for some projects that previously used flow, but it's not have actual typing
if (!isFlowEnabled()) {
return
}
global.vscode = vscode
setupLogging()
checkNode()
checkFlow()
// Language features
languages.forEach(lang => {
context.subscriptions.push(vscode.languages.registerHoverProvider(lang, new HoverSupport));
context.subscriptions.push(vscode.languages.registerDefinitionProvider(lang, new DeclarationSupport()));
context.subscriptions.push(vscode.languages.registerCompletionItemProvider(lang, new CompletionSupport(), '.'));
})
// https://github.com/Microsoft/vscode/issues/7031 Workaround for language scoring for language and in-memory. Check in nearest Insiders build
// context.subscriptions.push(vscode.languages.registerCompletionItemProvider({ language: 'javascript' }, new CompletionSupport(), '.'));
// Diagnostics
setupDiagnostics(context.subscriptions);
}
7 changes: 7 additions & 0 deletions lib/pkg/nuclide-logging/lib/consoleAppender.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ function layout(loggingEvent: any): Array<any> {
function consoleAppender(): (loggingEvent: any) => void {
return loggingEvent => {
console.log.apply(console, layout(loggingEvent)); // eslint-disable-line no-console

// Also support outputing information into a VS Code console,
// it is only string based, so we only take the first string
if (global.flowOutputChannel) {
const message = layout(loggingEvent)[0]
global.flowOutputChannel.appendLine(message.replace("nuclide -", "flow -"))
}
};
}

Expand Down