Skip to content

Commit 7fd0579

Browse files
committed
fix(windows): fix plugin not working with remote extn pack
issue - RelativePattern not working on `local os: windows`
1 parent 22d8315 commit 7fd0579

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed

src/ClientStatusBarItem.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ export default class ClientStatusBarItem {
4848
private _item: StatusBarItem;
4949
private _client: LanguageClient;
5050
private _disposables: Array<{ dispose: () => any }> = [];
51+
private _canUseRelativePattern: boolean;
5152

52-
constructor(client: LanguageClient) {
53+
constructor(client: LanguageClient, canUseRelativePattern: boolean) {
5354
this._item = window.createStatusBarItem(StatusBarAlignment.Right, 0);
5455
this._client = client;
56+
this._canUseRelativePattern = canUseRelativePattern;
5557

5658
this._disposables.push(this._item);
5759
this._disposables.push(this._addOnClickToShowOutputChannel());
@@ -113,16 +115,17 @@ export default class ClientStatusBarItem {
113115
// @TODO: if possible, match against patterns defined in .gqlconfig
114116
// instead of extensions.
115117
const extensions = this._client.initializeResult.fileExtensions;
118+
const pattern = `**/*.{${extensions.join(',')}}`;
116119
const score = languages.match(
117120
{
118121
scheme: 'file',
119-
pattern: new RelativePattern(
120-
workspaceFolder,
121-
`**/*.{${extensions.join(',')}}`,
122-
),
122+
pattern: this._canUseRelativePattern
123+
? new RelativePattern(workspaceFolder, pattern)
124+
: pattern,
123125
},
124126
textEditor.document,
125127
);
128+
126129
hide = score === 0;
127130
} else {
128131
// while server is initializing show status bar item

src/extension.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616

1717
import { findConfigFile as findGQLConfigFile } from '@playlyfe/gql-language-server';
1818
import ClientStatusBarItem from './ClientStatusBarItem';
19+
import { isExtensionRunningLocally } from './utils';
1920

2021
const EXT_NAME = 'graphqlForVSCode';
2122
const GQL_LANGUAGE_SERVER_CLI_PATH = require.resolve(
@@ -31,9 +32,11 @@ interface IClient {
3132
const clients: Map<string, IClient | null> = new Map();
3233

3334
export function activate(context: ExtensionContext) {
34-
createClientForWorkspaces();
35+
createClientForWorkspaces(context);
3536
// update clients when workspaceFolderChanges
36-
Workspace.onDidChangeWorkspaceFolders(createClientForWorkspaces);
37+
Workspace.onDidChangeWorkspaceFolders(() => {
38+
createClientForWorkspaces(context);
39+
});
3740
}
3841

3942
export function deactivate(): Thenable<void> {
@@ -46,14 +49,14 @@ export function deactivate(): Thenable<void> {
4649
return Promise.all(promises).then(() => undefined);
4750
}
4851

49-
function createClientForWorkspaces() {
52+
function createClientForWorkspaces(context: ExtensionContext) {
5053
const workspaceFolders = Workspace.workspaceFolders || [];
5154
const workspaceFoldersIndex: { [key: string]: boolean } = {};
5255

5356
workspaceFolders.forEach(folder => {
5457
const key = folder.uri.toString();
5558
if (!clients.has(key)) {
56-
const client = createClientForWorkspace(folder);
59+
const client = createClientForWorkspace(folder, context);
5760
// console.log('adding client', key, client);
5861
clients.set(key, client);
5962
}
@@ -73,7 +76,10 @@ function createClientForWorkspaces() {
7376
});
7477
}
7578

76-
function createClientForWorkspace(folder: WorkspaceFolder): null | IClient {
79+
function createClientForWorkspace(
80+
folder: WorkspaceFolder,
81+
context: ExtensionContext,
82+
): null | IClient {
7783
// per workspacefolder settings
7884
const config = Workspace.getConfiguration(EXT_NAME, folder.uri);
7985
const outputChannel = window.createOutputChannel(`GraphQL - ${folder.name}`);
@@ -121,6 +127,12 @@ function createClientForWorkspace(folder: WorkspaceFolder): null | IClient {
121127
},
122128
};
123129

130+
// TEMP_FIX: relativePattern is not working when extension is
131+
// running using vscode-remote with `local os = windows`
132+
// NOTE: relativePattern is used only for optimization so it will
133+
// not change the extension behaviour
134+
const canUseRelativePattern = isExtensionRunningLocally(context);
135+
124136
// Options to control the language client
125137
const clientOptions: LanguageClientOptions = {
126138
diagnosticCollectionName: 'graphql',
@@ -136,7 +148,7 @@ function createClientForWorkspace(folder: WorkspaceFolder): null | IClient {
136148
outputChannel,
137149
workspaceFolder: folder,
138150
initializationOptions: {
139-
relativePattern: true,
151+
relativePattern: canUseRelativePattern,
140152
},
141153
};
142154

@@ -148,7 +160,7 @@ function createClientForWorkspace(folder: WorkspaceFolder): null | IClient {
148160
clientOptions,
149161
);
150162

151-
const statusBarItem = new ClientStatusBarItem(client);
163+
const statusBarItem = new ClientStatusBarItem(client, canUseRelativePattern);
152164

153165
const subscriptions = [
154166
client.start(),

src/utils.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ExtensionContext } from 'vscode';
2+
3+
// NOTE same as vscode.ExtensionExecutionContext
4+
// this const can be replaced when we drop support of vscode <=1.35
5+
const EXTENSION_EXECUTION_CONTEXT = {
6+
Local: 1,
7+
Remote: 2,
8+
};
9+
10+
export function isExtensionRunningLocally(context: ExtensionContext): boolean {
11+
// NOTE: executionContext is present in >=1.35 (when remote support added)
12+
// so using local as default value
13+
const executionContext =
14+
(context as any).executionContext || EXTENSION_EXECUTION_CONTEXT.Local;
15+
return executionContext === EXTENSION_EXECUTION_CONTEXT.Local;
16+
}

0 commit comments

Comments
 (0)