Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit 27c958e

Browse files
committed
Remove the RubyEnvironment type and use IEnvironment
The environment can vary between platforms. Instead, we'll just whitelist keys to import on the client and pass them transparently through to the server.
1 parent 8b704bd commit 27c958e

File tree

8 files changed

+24
-41
lines changed

8 files changed

+24
-41
lines changed

client/src/WorkspaceRubyEnvironment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import {
55
StaticFeature,
66
} from 'vscode-languageclient';
77
import { Uri, workspace, WorkspaceFolder } from 'vscode';
8-
import { loadEnv, RubyEnvironment } from './util/env';
8+
import { loadEnv, IEnvironment } from './util/env';
99

1010
interface WorkspaceRubyEnvironmentParams {
1111
readonly folders: string[];
1212
}
1313

1414
interface WorkspaceRubyEnvironmentResult {
15-
[key: string]: RubyEnvironment;
15+
[key: string]: IEnvironment;
1616
}
1717

1818
namespace WorkspaceRubyEnvironmentRequest {

client/src/util/env.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,11 @@ const RUBY_ENVIRONMENT_VARIABLES = [
9292
'RUBOCOP_OPTS',
9393
];
9494

95-
export type RubyEnvironment = {
96-
PATH: string;
97-
RUBY_VERSION: string;
98-
RUBY_ROOT: string;
99-
GEM_HOME: string;
100-
GEM_PATH: string;
101-
GEM_ROOT: string;
102-
HOME: string;
103-
RUBOCOP_OPTS?: string;
104-
};
105-
10695
export interface IEnvironment {
10796
[key: string]: string;
10897
}
10998

110-
export function loadEnv(cwd: string): RubyEnvironment {
99+
export function loadEnv(cwd: string): IEnvironment {
111100
const shim: string = getShim();
112101
const env: IEnvironment = {};
113102
const { stdout, stderr } = execa.sync(shim, [], {
@@ -118,10 +107,11 @@ export function loadEnv(cwd: string): RubyEnvironment {
118107

119108
for (const line of stdout.split('\n')) {
120109
const result: string[] = processExportLine(line);
121-
if (RUBY_ENVIRONMENT_VARIABLES.indexOf(result[0]) >= 0) {
122-
env[result[0]] = result[1];
110+
const name = result[0];
111+
if (RUBY_ENVIRONMENT_VARIABLES.indexOf(name) >= 0) {
112+
env[name] = result[1];
123113
}
124114
}
125115

126-
return env as RubyEnvironment;
116+
return env;
127117
}

server/src/Formatter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Range, TextDocument, TextDocumentIdentifier, TextEdit } from 'vscode-languageserver';
22
import {
33
documentConfigurationCache,
4-
RubyEnvironment,
4+
IEnvironment,
55
workspaceRubyEnvironmentCache,
66
RubyConfiguration,
77
} from './SettingsCache';
@@ -19,7 +19,7 @@ const FORMATTER_MAP = {
1919

2020
function getFormatter(
2121
document: TextDocument,
22-
env: RubyEnvironment,
22+
env: IEnvironment,
2323
config: RubyConfiguration,
2424
range?: Range
2525
): IFormatter {

server/src/Linter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { map, mergeMap, switchMap } from 'rxjs/operators';
44
import { Diagnostic, TextDocument } from 'vscode-languageserver';
55
import {
66
documentConfigurationCache,
7-
RubyEnvironment,
7+
IEnvironment,
88
workspaceRubyEnvironmentCache,
99
RubyConfiguration,
1010
RubyCommandConfiguration,
@@ -27,7 +27,7 @@ export type LintResult = {
2727
function getLinter(
2828
name: string,
2929
document: TextDocument,
30-
env: RubyEnvironment,
30+
env: IEnvironment,
3131
config: RubyConfiguration
3232
): ILinter {
3333
const linter = LINTER_MAP[name];

server/src/Server.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
documentConfigurationCache,
2121
workspaceRubyEnvironmentCache,
2222
RubyConfiguration,
23-
RubyEnvironment,
23+
IEnvironment,
2424
} from './SettingsCache';
2525
import DocumentFormattingProvider from './providers/DocumentFormattingProvider';
2626

@@ -35,7 +35,7 @@ interface WorkspaceRubyEnvironmentParams {
3535
}
3636

3737
interface WorkspaceRubyEnvironmentResult {
38-
readonly [key: string]: RubyEnvironment;
38+
readonly [key: string]: IEnvironment;
3939
}
4040

4141
namespace WorkspaceRubyEnvironmentRequest {
@@ -78,7 +78,7 @@ export class Server implements ILanguageServer {
7878
if (this.calculator.clientCapabilities.workspace.rubyEnvironment) {
7979
workspaceRubyEnvironmentCache.fetcher = async (
8080
folders: string[]
81-
): Promise<RubyEnvironment[]> => {
81+
): Promise<IEnvironment[]> => {
8282
const result: WorkspaceRubyEnvironmentResult = await this.connection.sendRequest(
8383
WorkspaceRubyEnvironmentRequest.type,
8484
{
@@ -91,8 +91,8 @@ export class Server implements ILanguageServer {
9191
} else {
9292
workspaceRubyEnvironmentCache.fetcher = async (
9393
folders: string[]
94-
): Promise<RubyEnvironment[]> => {
95-
return folders.map(_f => process.env as RubyEnvironment);
94+
): Promise<IEnvironment[]> => {
95+
return folders.map(_f => process.env as IEnvironment);
9696
};
9797
}
9898
}

server/src/SettingsCache.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
import { TextDocument, WorkspaceFolder } from 'vscode-languageserver';
22

3-
export type RubyEnvironment = {
4-
PATH: string;
5-
RUBY_VERSION: string;
6-
RUBY_ROOT: string;
7-
GEM_HOME: string;
8-
GEM_PATH: string;
9-
GEM_ROOT: string;
10-
HOME: string;
11-
RUBOCOP_OPTS?: string;
12-
};
3+
export interface IEnvironment {
4+
[key: string]: string;
5+
}
136

147
export type RubyCommandConfiguration = {
158
command?: string;
@@ -105,4 +98,4 @@ class SettingsCache<P extends WorkspaceFolder | TextDocument, T> {
10598
}
10699

107100
export const documentConfigurationCache = new SettingsCache<TextDocument, RubyConfiguration>();
108-
export const workspaceRubyEnvironmentCache = new SettingsCache<WorkspaceFolder, RubyEnvironment>();
101+
export const workspaceRubyEnvironmentCache = new SettingsCache<WorkspaceFolder, IEnvironment>();

server/src/formatters/BaseFormatter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import {
99
DIFF_INSERT,
1010
DIFF_EQUAL,
1111
} from 'diff-match-patch';
12-
import { RubyEnvironment, RubyCommandConfiguration } from '../SettingsCache';
12+
import { IEnvironment, RubyCommandConfiguration } from '../SettingsCache';
1313

1414
export interface IFormatter {
1515
format(): Observable<TextEdit[]>;
1616
}
1717

1818
export type FormatterConfig = {
19-
env: RubyEnvironment;
19+
env: IEnvironment;
2020
executionRoot: string;
2121
config: RubyCommandConfiguration;
2222
range?: Range;

server/src/linters/BaseLinter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { Diagnostic, TextDocument } from 'vscode-languageserver';
22
import { spawn } from 'spawn-rx';
33
import { of, Observable, empty } from 'rxjs';
44
import { map, catchError } from 'rxjs/operators';
5-
import { RubyEnvironment, RubyCommandConfiguration } from '../SettingsCache';
5+
import { IEnvironment, RubyCommandConfiguration } from '../SettingsCache';
66

77
export interface ILinter {
88
lint(): Observable<Diagnostic[]>;
99
}
1010

1111
export type LinterConfig = {
12-
env: RubyEnvironment;
12+
env: IEnvironment;
1313
executionRoot: string;
1414
config: RubyCommandConfiguration;
1515
};

0 commit comments

Comments
 (0)