Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'omnisharp.autoStart' option that allows users to control whether OmniSharp is started automatically or not #721

Merged
merged 1 commit into from
Aug 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@
"verbose"
],
"description": "Specifies the level of logging output from the OmniSharp server."
},
"omnisharp.autoStart": {
"type": "boolean",
"default": true,
"description": "Specifies whether the OmniSharp server will be automatically started or not. If false, OmniSharp can be started with the 'Restart OmniSharp' command"
}
}
},
Expand Down
11 changes: 10 additions & 1 deletion src/features/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {DotNetAttachItemsProviderFactory, AttachPicker} from './processPicker'
let channel = vscode.window.createOutputChannel('.NET');

export default function registerCommands(server: OmnisharpServer, extensionPath: string) {
let d1 = vscode.commands.registerCommand('o.restart', () => server.restart());
let d1 = vscode.commands.registerCommand('o.restart', () => restartOmniSharp(server));
let d2 = vscode.commands.registerCommand('o.pickProjectAndStart', () => pickProjectAndStart(server));
let d3 = vscode.commands.registerCommand('o.showOutput', () => server.getChannel().show(vscode.ViewColumn.Three));
let d4 = vscode.commands.registerCommand('dotnet.restore', () => dotnetRestoreAllProjects(server));
Expand All @@ -40,6 +40,15 @@ export default function registerCommands(server: OmnisharpServer, extensionPath:
return vscode.Disposable.from(d1, d2, d3, d4, d5, d6, d7, d8);
}

function restartOmniSharp(server: OmnisharpServer) {
if (server.isRunning()) {
server.restart();
}
else {
server.autoStart('');
}
}

function pickProjectAndStart(server: OmnisharpServer) {

return findLaunchTargets().then(targets => {
Expand Down
8 changes: 6 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import reportDiagnostics,{Advisor} from './features/diagnosticsProvider';
import SignatureHelpProvider from './features/signatureHelpProvider';
import registerCommands from './features/commands';
import {StdioOmnisharpServer} from './omnisharp/server';
import {readOptions} from './omnisharp/options';
import forwardChanges from './features/changeForwarding';
import reportStatus from './features/status';
import * as coreclrdebug from './coreclr-debug/activate';
Expand All @@ -28,7 +29,6 @@ import * as vscode from 'vscode';
import TelemetryReporter from 'vscode-extension-telemetry';
import {DefinitionMetadataDocumentProvider} from './features/definitionMetadataDocumentProvider';


export function activate(context: vscode.ExtensionContext): any {

const extensionId = 'ms-vscode.csharp';
Expand Down Expand Up @@ -88,7 +88,11 @@ export function activate(context: vscode.ExtensionContext): any {

// read and store last solution or folder path
disposables.push(server.onBeforeServerStart(path => context.workspaceState.update('lastSolutionPathOrFolder', path)));
server.autoStart(context.workspaceState.get<string>('lastSolutionPathOrFolder'));

const options = readOptions();
if (options.autoStart) {
server.autoStart(context.workspaceState.get<string>('lastSolutionPathOrFolder'));
}

// stop server on deactivate
disposables.push(new vscode.Disposable(() => {
Expand Down
6 changes: 0 additions & 6 deletions src/omnisharp/omnisharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
import * as fs from 'fs-extra-promise';
import * as path from 'path';

export interface Options {
path?: string;
useMono?: boolean;
loggingLevel?: string;
}

export enum Flavor {
CoreCLR,
Mono,
Expand Down
39 changes: 39 additions & 0 deletions src/omnisharp/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

'use strict';

import * as vscode from 'vscode';

export interface Options {
path?: string;
useMono?: boolean;
loggingLevel?: string;
autoStart?: boolean;
}

export function readOptions(): Options {
// Extra effort is taken below to ensure that legacy versions of options
// are supported below. In particular, these are:
//
// - "csharp.omnisharp" -> "omnisharp.path"
// - "csharp.omnisharpUsesMono" -> "omnisharp.useMono"

const omnisharpConfig = vscode.workspace.getConfiguration('omnisharp');
const csharpConfig = vscode.workspace.getConfiguration('csharp');

const path = omnisharpConfig.has('path')
? omnisharpConfig.get<string>('path')
: csharpConfig.get<string>('omnisharp');

const useMono = omnisharpConfig.has('useMono')
? omnisharpConfig.get<boolean>('useMono')
: csharpConfig.get<boolean>('omnisharpUsesMono');

const loggingLevel = omnisharpConfig.get<string>('loggingLevel');
const autoStart = omnisharpConfig.get<boolean>('autoStart', true);

return { path, useMono, loggingLevel, autoStart };
}
30 changes: 4 additions & 26 deletions src/omnisharp/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {launchOmniSharp} from './launcher';
import * as protocol from './protocol';
import * as omnisharp from './omnisharp';
import * as download from './download';
import {readOptions} from './options';
import {Logger} from './logger';
import {DelayTracker} from './delayTracker';
import {LaunchTarget, findLaunchTargets, getDefaultFlavor} from './launcher';
Expand Down Expand Up @@ -107,29 +108,6 @@ export abstract class OmnisharpServer {
}
}

private _readOptions(): omnisharp.Options {
// Extra effort is taken below to ensure that legacy versions of options
// are supported below. In particular, these are:
//
// - "csharp.omnisharp" -> "omnisharp.path"
// - "csharp.omnisharpUsesMono" -> "omnisharp.useMono"

const omnisharpConfig = vscode.workspace.getConfiguration('omnisharp');
const csharpConfig = vscode.workspace.getConfiguration('csharp');

const path = omnisharpConfig.has('path')
? omnisharpConfig.get<string>('path')
: csharpConfig.get<string>('omnisharp');

const useMono = omnisharpConfig.has('useMono')
? omnisharpConfig.get<boolean>('useMono')
: csharpConfig.get<boolean>('omnisharpUsesMono');

const loggingLevel = omnisharpConfig.get<string>('loggingLevel');

return { path, useMono, loggingLevel };
}

private _recordRequestDelay(requestName: string, elapsedTime: number) {
let tracker = this._delayTrackers[requestName];
if (!tracker) {
Expand Down Expand Up @@ -252,7 +230,7 @@ export abstract class OmnisharpServer {
// --- start, stop, and connect

private _start(launchTarget: LaunchTarget): Promise<void> {
const options = this._readOptions();
const options = readOptions();

let flavor: omnisharp.Flavor;
if (options.path !== undefined && options.useMono === true) {
Expand Down Expand Up @@ -403,7 +381,7 @@ export abstract class OmnisharpServer {
// If there's more than one launch target, we start the server if one of the targets
// matches the preferred path. Otherwise, we fire the "MultipleLaunchTargets" event,
// which is handled in status.ts to display the launch target selector.
if (launchTargets.length > 1) {
if (launchTargets.length > 1 && preferredPath) {

for (let launchTarget of launchTargets) {
if (launchTarget.target === preferredPath) {
Expand All @@ -425,7 +403,7 @@ export abstract class OmnisharpServer {
// Attempt to find launch file path first from options, and then from the default install location.
// If OmniSharp can't be found, download it.

const options = this._readOptions();
const options = readOptions();
const installDirectory = omnisharp.getInstallDirectory(flavor);

return new Promise<string>((resolve, reject) => {
Expand Down