Skip to content

Commit 7eac784

Browse files
Break dependency of Options.Read() on vscode
1 parent cefa8dd commit 7eac784

File tree

7 files changed

+24
-25
lines changed

7 files changed

+24
-25
lines changed

src/features/codeActionProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default class CodeActionProvider extends AbstractProvider implements vsco
3232
}
3333

3434
private _resetCachedOptions(): void {
35-
this._options = Options.Read();
35+
this._options = Options.Read(vscode);
3636
}
3737

3838
public async provideCodeActions(document: vscode.TextDocument, range: vscode.Range, context: vscode.CodeActionContext, token: vscode.CancellationToken): Promise<vscode.Command[]> {

src/features/codeLensProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default class OmniSharpCodeLensProvider extends AbstractProvider implemen
3939
}
4040

4141
private _resetCachedOptions(): void {
42-
this._options = Options.Read();
42+
this._options = Options.Read(vscode);
4343
}
4444

4545
private static filteredSymbolNames: { [name: string]: boolean } = {

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<CSharp
6161
eventStream.subscribe(omnisharpLogObserver.post);
6262
eventStream.subscribe(omnisharpChannelObserver.post);
6363

64-
let warningMessageObserver = new WarningMessageObserver(vscode, () => Options.Read().disableMSBuildDiagnosticWarning || false);
64+
let warningMessageObserver = new WarningMessageObserver(vscode, () => Options.Read(vscode).disableMSBuildDiagnosticWarning || false);
6565
eventStream.subscribe(warningMessageObserver.post);
6666

6767
let informationMessageObserver = new InformationMessageObserver(vscode);

src/omnisharp/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export async function activate(context: vscode.ExtensionContext, eventStream: Ev
4343
scheme: 'file' // only files from disk
4444
};
4545

46-
const options = Options.Read();
46+
const options = Options.Read(vscode);
4747
const server = new OmniSharpServer(vscode, provider, eventStream, packageJSON, platformInfo);
4848
omnisharp = server;
4949
const advisor = new Advisor(server); // create before server is started

src/omnisharp/launcher.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function findLaunchTargets(): Thenable<LaunchTarget[]> {
4141
return Promise.resolve([]);
4242
}
4343

44-
const options = Options.Read();
44+
const options = Options.Read(vscode);
4545

4646
return vscode.workspace.findFiles(
4747
/*include*/ '{**/*.sln,**/*.csproj,**/project.json,**/*.csx,**/*.cake}',
@@ -204,9 +204,9 @@ export interface LaunchResult {
204204
monoVersion?: string;
205205
}
206206

207-
export async function launchOmniSharp(cwd: string, args: string[], launchInfo: LaunchInfo, platformInfo: PlatformInformation): Promise<LaunchResult> {
207+
export async function launchOmniSharp(cwd: string, args: string[], launchInfo: LaunchInfo, platformInfo: PlatformInformation, options: Options): Promise<LaunchResult> {
208208
return new Promise<LaunchResult>((resolve, reject) => {
209-
launch(cwd, args, launchInfo, platformInfo)
209+
launch(cwd, args, launchInfo, platformInfo, options)
210210
.then(result => {
211211
// async error - when target not not ENEOT
212212
result.process.on('error', err => {
@@ -222,9 +222,7 @@ export async function launchOmniSharp(cwd: string, args: string[], launchInfo: L
222222
});
223223
}
224224

225-
async function launch(cwd: string, args: string[], launchInfo: LaunchInfo, platformInfo: PlatformInformation): Promise<LaunchResult> {
226-
const options = Options.Read();
227-
225+
async function launch(cwd: string, args: string[], launchInfo: LaunchInfo, platformInfo: PlatformInformation, options: Options): Promise<LaunchResult> {
228226
if (options.useEditorFormattingSettings) {
229227
let globalConfig = vscode.workspace.getConfiguration();
230228
let csharpConfig = vscode.workspace.getConfiguration('[csharp]');

src/omnisharp/options.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import * as vscode from 'vscode';
6+
import { vscode, WorkspaceConfiguration } from '../vscodeAdapter';
77

88
export class Options {
99
constructor(
@@ -21,7 +21,7 @@ export class Options {
2121
public disableCodeActions: boolean,
2222
public disableMSBuildDiagnosticWarning: boolean) { }
2323

24-
public static Read(): Options {
24+
public static Read(vscode: vscode): Options {
2525
// Extra effort is taken below to ensure that legacy versions of options
2626
// are supported below. In particular, these are:
2727
//
@@ -74,7 +74,7 @@ export class Options {
7474
disableMSBuildDiagnosticWarning);
7575
}
7676

77-
private static readPathOption(csharpConfig: vscode.WorkspaceConfiguration, omnisharpConfig: vscode.WorkspaceConfiguration): string | null {
77+
private static readPathOption(csharpConfig: WorkspaceConfiguration, omnisharpConfig: WorkspaceConfiguration): string | null {
7878
if (omnisharpConfig.has('path')) {
7979
// If 'omnisharp.path' setting was found, use it.
8080
return omnisharpConfig.get<string>('path');
@@ -89,7 +89,7 @@ export class Options {
8989
}
9090
}
9191

92-
private static readUseGlobalMonoOption(omnisharpConfig: vscode.WorkspaceConfiguration, csharpConfig: vscode.WorkspaceConfiguration): string {
92+
private static readUseGlobalMonoOption(omnisharpConfig: WorkspaceConfiguration, csharpConfig: WorkspaceConfiguration): string {
9393
function toUseGlobalMonoValue(value: boolean): string {
9494
// True means 'always' and false means 'auto'.
9595
return value ? "always" : "auto";

src/omnisharp/server.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ export class OmniSharpServer {
8585
private _launchTarget: LaunchTarget;
8686
private _requestQueue: RequestQueueCollection;
8787
private _serverProcess: ChildProcess;
88-
private _options: Options;
8988

9089
private _omnisharpManager: OmnisharpManager;
9190
private updateProjectDebouncer = new Subject<ObservableEvents.ProjectModified>();
@@ -237,7 +236,7 @@ export class OmniSharpServer {
237236

238237
// --- start, stop, and connect
239238

240-
private async _start(launchTarget: LaunchTarget): Promise<void> {
239+
private async _start(launchTarget: LaunchTarget, options: Options): Promise<void> {
241240

242241
let disposables = new CompositeDisposable();
243242

@@ -292,25 +291,24 @@ export class OmniSharpServer {
292291

293292
const solutionPath = launchTarget.target;
294293
const cwd = path.dirname(solutionPath);
295-
this._options = Options.Read();
296294

297295
let args = [
298296
'-s', solutionPath,
299297
'--hostPID', process.pid.toString(),
300298
'--stdio',
301299
'DotNet:enablePackageRestore=false',
302300
'--encoding', 'utf-8',
303-
'--loglevel', this._options.loggingLevel
301+
'--loglevel', options.loggingLevel
304302
];
305303

306-
if (this._options.waitForDebugger === true) {
304+
if (options.waitForDebugger === true) {
307305
args.push('--debug');
308306
}
309307

310308
let launchInfo: LaunchInfo;
311309
try {
312310
let extensionPath = utils.getExtensionPath();
313-
launchInfo = await this._omnisharpManager.GetOmniSharpLaunchInfo(this.packageJSON.defaults.omniSharp, this._options.path, serverUrl, latestVersionFileServerPath, installPath, extensionPath);
311+
launchInfo = await this._omnisharpManager.GetOmniSharpLaunchInfo(this.packageJSON.defaults.omniSharp, options.path, serverUrl, latestVersionFileServerPath, installPath, extensionPath);
314312
}
315313
catch (error) {
316314
this.eventStream.post(new ObservableEvents.OmnisharpFailure(`Error occured in loading omnisharp from omnisharp.path\nCould not start the server due to ${error.toString()}`, error));
@@ -321,15 +319,15 @@ export class OmniSharpServer {
321319
this._fireEvent(Events.BeforeServerStart, solutionPath);
322320

323321
try {
324-
let launchResult = await launchOmniSharp(cwd, args, launchInfo, this.platformInfo);
322+
let launchResult = await launchOmniSharp(cwd, args, launchInfo, this.platformInfo, options);
325323
this.eventStream.post(new ObservableEvents.OmnisharpLaunch(launchResult.monoVersion, launchResult.command, launchResult.process.pid));
326324

327325
this._serverProcess = launchResult.process;
328326
this._delayTrackers = {};
329327
this._setState(ServerState.Started);
330328
this._fireEvent(Events.ServerStart, solutionPath);
331329

332-
await this._doConnect();
330+
await this._doConnect(options);
333331

334332
this._telemetryIntervalId = setInterval(() => this._reportTelemetry(), TelemetryReportingDelay);
335333
this._requestQueue.drain();
@@ -417,7 +415,10 @@ export class OmniSharpServer {
417415
public async restart(launchTarget: LaunchTarget = this._launchTarget): Promise<void> {
418416
if (launchTarget) {
419417
await this.stop();
420-
await this._start(launchTarget);
418+
419+
const options = Options.Read(this.vscode);
420+
421+
await this._start(launchTarget, options);
421422
}
422423
}
423424

@@ -503,7 +504,7 @@ export class OmniSharpServer {
503504
});
504505
}
505506

506-
private async _doConnect(): Promise<void> {
507+
private async _doConnect(options: Options): Promise<void> {
507508

508509
this._serverProcess.stderr.on('data', (data: any) => {
509510
this._fireEvent('stderr', String(data));
@@ -519,7 +520,7 @@ export class OmniSharpServer {
519520
let listener: Disposable;
520521

521522
// Convert the timeout from the seconds to milliseconds, which is required by setTimeout().
522-
const timeoutDuration = this._options.projectLoadTimeout * 1000;
523+
const timeoutDuration = options.projectLoadTimeout * 1000;
523524

524525
// timeout logic
525526
const handle = setTimeout(() => {

0 commit comments

Comments
 (0)