Skip to content

Commit

Permalink
fix(remote): fix plugin not working with remote extension pack on win…
Browse files Browse the repository at this point in the history
…dows

closes #336
  • Loading branch information
Mayank1791989 committed Aug 4, 2019
1 parent 5c15751 commit 3dd4ecc
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
3 changes: 3 additions & 0 deletions flow-libs/vscode.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -4041,6 +4041,9 @@ declare module 'vscode' {
* Extensions must create this directory before writing to it. The parent directory will always exist.
*/
+logDirectory: string;

// NOTE: only present in vscode >= 1.35
+executionContext?: 1 | 2;
/* END PROPOSED *********************************************************************************/
}

Expand Down
11 changes: 6 additions & 5 deletions lib/flowLSP/FlowLanguageClient/FlowLanguageClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Options = {|
flowconfigPath: string,
workspaceRoot: string,
outputChannel: vscode.OutputChannel,
canUseRelativePattern: boolean,
getConfig: () => Config,
|};

Expand Down Expand Up @@ -167,11 +168,11 @@ export default class FlowLanguageClient {
// options: { cwd: flowconfigDir },
};

// all files inside flowconfigDir
const pattern: vscode.RelativePattern = new vscode.RelativePattern(
flowconfigDir,
'**/*',
);
const patternGlob = '**/*';
const pattern: vscode.GlobPattern = this._options.canUseRelativePattern
? // all files inside flowconfigDir
new vscode.RelativePattern(flowconfigDir, patternGlob)
: patternGlob;

const clientOptions: lsp.LanguageClientOptions = {
// NOTE: nested .flowconfig filtering not possible using only documentSelector
Expand Down
2 changes: 2 additions & 0 deletions lib/flowLSP/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export function onDidOpenTextDocument(
clients: FlowClients,
document: vscode.TextDocument,
outputChannel: vscode.OutputChannel,
canUseRelativePattern: boolean,
logger: Logger,
) {
if (!vscode.languages.match(activationDocumentSelector, document)) {
Expand Down Expand Up @@ -98,6 +99,7 @@ export function onDidOpenTextDocument(
flowconfigPath,
workspaceRoot: workspaceFolder.uri.fsPath,
outputChannel,
canUseRelativePattern,
// NOTE: passing config as getFunction instead of plain object
// to add support of handling config change without the requirement of vscode restart
getConfig: () => {
Expand Down
18 changes: 16 additions & 2 deletions lib/flowLSP/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,29 @@ import FlowClients from './FlowClients';
import PluginCommands from './PluginCommands';
import * as handlers from './handlers';

import checkRelativePatternSupported from './utils/checkRelativePatternSupported';
import Logger from './utils/Logger';

export function activate(context: vscode.ExtensionContext) {
const outputChannel = vscode.window.createOutputChannel('Flow');
const logger = new Logger('', outputChannel, 'error');
const clients = new FlowClients(logger);
const commands = new PluginCommands(clients, outputChannel);
const canUseRelativePattern = checkRelativePatternSupported(context);

logger.info('Open javascript or flowconfig to start flow.');

context.subscriptions.push(
clients,
// handlers
vscode.workspace.onDidOpenTextDocument((document) => {
handlers.onDidOpenTextDocument(clients, document, outputChannel, logger);
handlers.onDidOpenTextDocument(
clients,
document,
outputChannel,
canUseRelativePattern,
logger,
);
}),
vscode.window.onDidChangeActiveTextEditor((editor) => {
handlers.onDidChangeActiveTextEditor(clients, editor);
Expand All @@ -43,6 +51,12 @@ export function activate(context: vscode.ExtensionContext) {

// create flow clients for currently opened documents
vscode.workspace.textDocuments.forEach((document) => {
handlers.onDidOpenTextDocument(clients, document, outputChannel, logger);
handlers.onDidOpenTextDocument(
clients,
document,
outputChannel,
canUseRelativePattern,
logger,
);
});
}
14 changes: 14 additions & 0 deletions lib/flowLSP/utils/checkRelativePatternSupported.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* @flow */
import { ExtensionContext } from 'vscode';

const EXECUTION_CONTEXT_REMOTE = 2;

export default function checkRelativePatternSupported(
context: ExtensionContext,
): boolean {
// NOTE: vscode.RelativePattern is not working when extension run using
// remote extension pack on windows (on linux it's working fine)
// it's not possible to detect local maching is linux or windows
// so disabling in all cases if extension is running remotely
return context.executionContext !== EXECUTION_CONTEXT_REMOTE;
}

0 comments on commit 3dd4ecc

Please sign in to comment.