Skip to content

Commit da5934a

Browse files
committed
added ability to pass formatting env. variables into omnisharp
1 parent fe153eb commit da5934a

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/omnisharp/launcher.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,25 @@ function launch(cwd: string, args: string[]): Promise<LaunchResult> {
161161
return PlatformInformation.GetCurrent().then(platformInfo => {
162162
const options = Options.Read();
163163

164+
let editorConfig = vscode.workspace.getConfiguration('editor');
165+
166+
let envVars = {
167+
'formattingOptions:useTabs': !editorConfig.get('insertSpaces', true),
168+
'formattingOptions:tabSize': editorConfig.get('tabSize', 4),
169+
'formattingOptions:indentationSize': editorConfig.get('tabSize', 4)
170+
};
171+
164172
if (options.path && options.useMono) {
165-
return launchNixMono(options.path, cwd, args);
173+
return launchNixMono(options.path, cwd, args, envVars);
166174
}
167175

168176
const launchPath = options.path || getLaunchPath(platformInfo);
169177

170178
if (platformInfo.isWindows()) {
171-
return launchWindows(launchPath, cwd, args);
179+
return launchWindows(launchPath, cwd, args, envVars);
172180
}
173181
else {
174-
return launchNix(launchPath, cwd, args);
182+
return launchNix(launchPath, cwd, args, envVars);
175183
}
176184
});
177185
}
@@ -184,7 +192,7 @@ function getLaunchPath(platformInfo: PlatformInformation): string {
184192
: path.join(binPath, 'run');
185193
}
186194

187-
function launchWindows(launchPath: string, cwd: string, args: string[]): LaunchResult {
195+
function launchWindows(launchPath: string, cwd: string, args: string[], envVars: any): LaunchResult {
188196
function escapeIfNeeded(arg: string) {
189197
const hasSpaceWithoutQuotes = /^[^"].* .*[^"]/;
190198
return hasSpaceWithoutQuotes.test(arg)
@@ -193,6 +201,7 @@ function launchWindows(launchPath: string, cwd: string, args: string[]): LaunchR
193201
}
194202

195203
let argsCopy = args.slice(0); // create copy of args
204+
argsCopy.push('--debug');
196205
argsCopy.unshift(launchPath);
197206
argsCopy = [[
198207
'/s',
@@ -203,7 +212,8 @@ function launchWindows(launchPath: string, cwd: string, args: string[]): LaunchR
203212
let process = spawn('cmd', argsCopy, <any>{
204213
windowsVerbatimArguments: true,
205214
detached: false,
206-
cwd: cwd
215+
cwd: cwd,
216+
env: envVars
207217
});
208218

209219
return {
@@ -213,10 +223,11 @@ function launchWindows(launchPath: string, cwd: string, args: string[]): LaunchR
213223
};
214224
}
215225

216-
function launchNix(launchPath: string, cwd: string, args: string[]): LaunchResult {
226+
function launchNix(launchPath: string, cwd: string, args: string[], envVars: any): LaunchResult {
217227
let process = spawn(launchPath, args, {
218228
detached: false,
219-
cwd: cwd
229+
cwd: cwd,
230+
env: envVars
220231
});
221232

222233
return {
@@ -226,15 +237,16 @@ function launchNix(launchPath: string, cwd: string, args: string[]): LaunchResul
226237
};
227238
}
228239

229-
function launchNixMono(launchPath: string, cwd: string, args: string[]): Promise<LaunchResult> {
240+
function launchNixMono(launchPath: string, cwd: string, args: string[], envVars: any): Promise<LaunchResult> {
230241
return canLaunchMono()
231242
.then(() => {
232243
let argsCopy = args.slice(0); // create copy of details args
233244
argsCopy.unshift(launchPath);
234245

235246
let process = spawn('mono', argsCopy, {
236247
detached: false,
237-
cwd: cwd
248+
cwd: cwd,
249+
env: envVars
238250
});
239251

240252
return {

0 commit comments

Comments
 (0)