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

Do not start OmniSharp server in Live Share scenarios #4038

Merged
merged 6 commits into from
Dec 7, 2020
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
34 changes: 30 additions & 4 deletions src/omnisharp/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export enum LaunchTargetKind {
ProjectJson,
Folder,
Csx,
Cake
Cake,
LiveShare
}

/**
Expand All @@ -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
Expand All @@ -55,7 +74,7 @@ export async function findLaunchTargets(options: Options): Promise<LaunchTarget[
return resourcesToLaunchTargets(projectFiles.concat(csFiles));
}

function resourcesToLaunchTargets(resources: vscode.Uri[]): LaunchTarget[] {
export function resourcesToLaunchTargets(resources: vscode.Uri[]): LaunchTarget[] {
// The list of launch targets is calculated like so:
// * If there are .csproj files, .sln files are considered as launch targets.
// * Any project.json file is considered a launch target.
Expand All @@ -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<number, vscode.Uri[]>();

for (let resource of resources) {
for (let resource of localResources) {
let folder = vscode.workspace.getWorkspaceFolder(resource);
if (folder) {
let buckets: vscode.Uri[];
Expand Down
7 changes: 6 additions & 1 deletion src/omnisharp/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -246,6 +246,11 @@ export class OmniSharpServer {

private async _start(launchTarget: LaunchTarget, options: Options): Promise<void> {

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 =>
Expand Down
41 changes: 41 additions & 0 deletions test/integrationTests/launcher.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import { assert } from "chai";
import { resourcesToLaunchTargets, vsls, vslsTarget } from "../../src/omnisharp/launcher";

const chai = require('chai');
chai.use(require('chai-arrays'));
chai.use(require('chai-fs'));

suite(`launcher:`, () => {

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.");
});
});