From d77bd5f1352141dd483caf148a61171c89506150 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Thu, 3 Sep 2020 17:07:27 -0700 Subject: [PATCH 1/2] Do not start OmniSharp during LiveShare sessions --- src/omnisharp/launcher.ts | 32 +++++++++++++++++++++++++++++--- src/omnisharp/server.ts | 7 ++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/omnisharp/launcher.ts b/src/omnisharp/launcher.ts index ef8041ab4..1287fba72 100644 --- a/src/omnisharp/launcher.ts +++ b/src/omnisharp/launcher.ts @@ -17,7 +17,8 @@ export enum LaunchTargetKind { ProjectJson, Folder, Csx, - Cake + Cake, + LiveShare } /** @@ -31,6 +32,24 @@ export interface LaunchTarget { kind: LaunchTargetKind; } +export const vslsTarget: LaunchTarget = { + label: "VSLS", + description: "Visual Studio Live Share", + directory: "", + target: "", + kind: LaunchTargetKind.LiveShare +}; + +/** Live share scheme */ +export const vsls = 'vsls'; + +/* + * File scheme for which OmniSharp language feature should be disabled + */ +export const disabledSchemes = new Set([ + vsls, +]); + /** * Returns a list of potential targets on which OmniSharp can be launched. * This includes `project.json` files, `*.sln` files (if any `*.csproj` files are found), and the root folder @@ -67,13 +86,20 @@ function resourcesToLaunchTargets(resources: vscode.Uri[]): LaunchTarget[] { // * It should be possible to choose a .sln file even when no .csproj files are found // within the root. - if (!Array.isArray(resources)) { + if (!Array.isArray(resources) || resources.length === 0) { return []; } + // Since language server functionality is run on the server instance there is no need + // to start OmniSharp on the LiveShare client. + const localResources = resources.filter(resource => !disabledSchemes.has(resource.scheme)); + if (localResources.length === 0) { + return [vslsTarget]; + } + let workspaceFolderToUriMap = new Map(); - for (let resource of resources) { + for (let resource of localResources) { let folder = vscode.workspace.getWorkspaceFolder(resource); if (folder) { let buckets: vscode.Uri[]; diff --git a/src/omnisharp/server.ts b/src/omnisharp/server.ts index 4384e0f76..9549189cd 100644 --- a/src/omnisharp/server.ts +++ b/src/omnisharp/server.ts @@ -11,7 +11,7 @@ import * as utils from '../common'; import * as serverUtils from '../omnisharp/utils'; import { vscode, CancellationToken } from '../vscodeAdapter'; import { ChildProcess, exec } from 'child_process'; -import { LaunchTarget, findLaunchTargets } from './launcher'; +import { LaunchTarget, findLaunchTargets, LaunchTargetKind } from './launcher'; import { ReadLine, createInterface } from 'readline'; import { Request, RequestQueueCollection } from './requestQueue'; import { DelayTracker } from './delayTracker'; @@ -246,6 +246,11 @@ export class OmniSharpServer { private async _start(launchTarget: LaunchTarget, options: Options): Promise { + if (launchTarget.kind === LaunchTargetKind.LiveShare) { + this.eventStream.post(new ObservableEvents.OmnisharpServerMessage("During Live Share sessions language services are provided by the Live Share server.")); + return; + } + let disposables = new CompositeDisposable(); disposables.add(this.onServerError(err => From e0a13b371c4c876ce17d9f07ac70a52e81140a8f Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Fri, 4 Sep 2020 11:08:44 -0700 Subject: [PATCH 2/2] Add tests for liveshare target. --- src/omnisharp/launcher.ts | 2 +- test/integrationTests/launcher.test.ts | 41 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 test/integrationTests/launcher.test.ts diff --git a/src/omnisharp/launcher.ts b/src/omnisharp/launcher.ts index 1287fba72..ce8ce79d2 100644 --- a/src/omnisharp/launcher.ts +++ b/src/omnisharp/launcher.ts @@ -74,7 +74,7 @@ export async function findLaunchTargets(options: Options): Promise { + + test(`Returns the LiveShare launch target when processing vsls resources`, () => { + const testResources: vscode.Uri[] = [ + vscode.Uri.parse(`${vsls}:/test.sln`), + vscode.Uri.parse(`${vsls}:/test/test.csproj`), + vscode.Uri.parse(`${vsls}:/test/Program.cs`), + ]; + + const launchTargets = resourcesToLaunchTargets(testResources); + + const liveShareTarget = launchTargets.find(target => target === vslsTarget); + assert.exists(liveShareTarget, "Launch targets was not the Visual Studio Live Share target."); + }); + + test(`Does not return the LiveShare launch target when processing local resources`, () => { + const testResources: vscode.Uri[] = [ + vscode.Uri.parse(`/test.sln`), + vscode.Uri.parse(`/test/test.csproj`), + vscode.Uri.parse(`/test/Program.cs`), + ]; + + const launchTargets = resourcesToLaunchTargets(testResources); + + const liveShareTarget = launchTargets.find(target => target === vslsTarget); + assert.notExists(liveShareTarget, "Launch targets contained the Visual Studio Live Share target."); + }); +}); \ No newline at end of file