-
Notifications
You must be signed in to change notification settings - Fork 112
Support automatically checking for the node_modules version of Flow #53
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,56 @@ | ||
/* @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 {clearWorkspaceCaches} from './pkg/flow-base/lib/FlowHelpers' | ||
|
||
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); | ||
} | ||
|
||
vscode.workspace.onDidChangeConfiguration(params => { | ||
clearWorkspaceCaches(); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,7 +139,8 @@ export class FlowProcess { | |
// don't want to log because it just means the server is busy and we don't want to wait. | ||
if (!couldRetry && !suppressErrors) { | ||
// not sure what happened, but we'll let the caller deal with it | ||
logger.error(`Flow failed: flow ${args.join(' ')}. Error: ${JSON.stringify(e)}`); | ||
const pathToFlow = await getPathToFlow(); | ||
logger.error(`Flow failed: ${pathToFlow} ${args.join(' ')}. Error: ${JSON.stringify(e)}`); | ||
} | ||
throw e; | ||
} | ||
|
@@ -153,7 +154,7 @@ export class FlowProcess { | |
|
||
/** Starts a Flow server in the current root */ | ||
async _startFlowServer(): Promise<void> { | ||
const pathToFlow = getPathToFlow(); | ||
const pathToFlow = await getPathToFlow(); | ||
// `flow server` will start a server in the foreground. asyncExecute | ||
// will not resolve the promise until the process exits, which in this | ||
// case is never. We need to use spawn directly to get access to the | ||
|
@@ -342,7 +343,7 @@ export class FlowProcess { | |
...args, | ||
'--from', 'nuclide', | ||
]; | ||
const pathToFlow = getPathToFlow(); | ||
const pathToFlow = await getPathToFlow(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How much slower do you think this call is? I mainly worry about things like autocomplete, where adding 100ms can really degrade performance. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
const ret = await asyncExecute(pathToFlow, args, options); | ||
if (ret.exitCode !== 0) { | ||
// TODO: bubble up the exit code via return value instead | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,11 @@ | |
|
||
import spawn from 'cross-spawn'; | ||
import {window, workspace} from 'vscode' | ||
import {getPathToFlow} from "../pkg/flow-base/lib/FlowHelpers" | ||
|
||
const NODE_NOT_FOUND = '[Flow] Cannot find node in PATH. The simpliest way to resolve it is install node globally' | ||
const FLOW_NOT_FOUND = '[Flow] Cannot find flow in PATH. Try to install it by npm install flow-bin -g' | ||
|
||
function getPathToFlow(): string { | ||
return workspace.getConfiguration('flow').get('pathToFlow') | ||
} | ||
|
||
export function isFlowEnabled() { | ||
return workspace.getConfiguration('flow').get('enabled') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As this would have different behaviour now, I made them share the code instead |
||
} | ||
|
@@ -36,9 +33,10 @@ export function checkNode() { | |
} | ||
} | ||
|
||
export function checkFlow() { | ||
export async function checkFlow() { | ||
const path = await getPathToFlow() | ||
try { | ||
const check = spawn(process.platform === 'win32' ? 'where' : 'which', [getPathToFlow()]) | ||
const check = spawn(process.platform === 'win32' ? 'where' : 'which', [path]) | ||
let | ||
flowOutput = "", | ||
flowOutputError = "" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, bah, git was complaining about line ends - didn't think it would do this