Skip to content

Commit c9ba020

Browse files
authored
Merge branch 'master' into remoteprocessscript-patch-1
2 parents 59b3027 + a1a1532 commit c9ba020

File tree

3 files changed

+77
-5
lines changed

3 files changed

+77
-5
lines changed

src/omnisharp/launcher.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export enum LaunchTargetKind {
1717
ProjectJson,
1818
Folder,
1919
Csx,
20-
Cake
20+
Cake,
21+
LiveShare
2122
}
2223

2324
/**
@@ -31,6 +32,24 @@ export interface LaunchTarget {
3132
kind: LaunchTargetKind;
3233
}
3334

35+
export const vslsTarget: LaunchTarget = {
36+
label: "VSLS",
37+
description: "Visual Studio Live Share",
38+
directory: "",
39+
target: "",
40+
kind: LaunchTargetKind.LiveShare
41+
};
42+
43+
/** Live share scheme */
44+
export const vsls = 'vsls';
45+
46+
/*
47+
* File scheme for which OmniSharp language feature should be disabled
48+
*/
49+
export const disabledSchemes = new Set([
50+
vsls,
51+
]);
52+
3453
/**
3554
* Returns a list of potential targets on which OmniSharp can be launched.
3655
* This includes `project.json` files, `*.sln` files (if any `*.csproj` files are found), and the root folder
@@ -55,7 +74,7 @@ export async function findLaunchTargets(options: Options): Promise<LaunchTarget[
5574
return resourcesToLaunchTargets(projectFiles.concat(csFiles));
5675
}
5776

58-
function resourcesToLaunchTargets(resources: vscode.Uri[]): LaunchTarget[] {
77+
export function resourcesToLaunchTargets(resources: vscode.Uri[]): LaunchTarget[] {
5978
// The list of launch targets is calculated like so:
6079
// * If there are .csproj files, .sln files are considered as launch targets.
6180
// * Any project.json file is considered a launch target.
@@ -67,13 +86,20 @@ function resourcesToLaunchTargets(resources: vscode.Uri[]): LaunchTarget[] {
6786
// * It should be possible to choose a .sln file even when no .csproj files are found
6887
// within the root.
6988

70-
if (!Array.isArray(resources)) {
89+
if (!Array.isArray(resources) || resources.length === 0) {
7190
return [];
7291
}
7392

93+
// Since language server functionality is run on the server instance there is no need
94+
// to start OmniSharp on the LiveShare client.
95+
const localResources = resources.filter(resource => !disabledSchemes.has(resource.scheme));
96+
if (localResources.length === 0) {
97+
return [vslsTarget];
98+
}
99+
74100
let workspaceFolderToUriMap = new Map<number, vscode.Uri[]>();
75101

76-
for (let resource of resources) {
102+
for (let resource of localResources) {
77103
let folder = vscode.workspace.getWorkspaceFolder(resource);
78104
if (folder) {
79105
let buckets: vscode.Uri[];

src/omnisharp/server.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as utils from '../common';
1111
import * as serverUtils from '../omnisharp/utils';
1212
import { vscode, CancellationToken } from '../vscodeAdapter';
1313
import { ChildProcess, exec } from 'child_process';
14-
import { LaunchTarget, findLaunchTargets } from './launcher';
14+
import { LaunchTarget, findLaunchTargets, LaunchTargetKind } from './launcher';
1515
import { ReadLine, createInterface } from 'readline';
1616
import { Request, RequestQueueCollection } from './requestQueue';
1717
import { DelayTracker } from './delayTracker';
@@ -246,6 +246,11 @@ export class OmniSharpServer {
246246

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

249+
if (launchTarget.kind === LaunchTargetKind.LiveShare) {
250+
this.eventStream.post(new ObservableEvents.OmnisharpServerMessage("During Live Share sessions language services are provided by the Live Share server."));
251+
return;
252+
}
253+
249254
let disposables = new CompositeDisposable();
250255

251256
disposables.add(this.onServerError(err =>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as vscode from 'vscode';
7+
import { assert } from "chai";
8+
import { resourcesToLaunchTargets, vsls, vslsTarget } from "../../src/omnisharp/launcher";
9+
10+
const chai = require('chai');
11+
chai.use(require('chai-arrays'));
12+
chai.use(require('chai-fs'));
13+
14+
suite(`launcher:`, () => {
15+
16+
test(`Returns the LiveShare launch target when processing vsls resources`, () => {
17+
const testResources: vscode.Uri[] = [
18+
vscode.Uri.parse(`${vsls}:/test.sln`),
19+
vscode.Uri.parse(`${vsls}:/test/test.csproj`),
20+
vscode.Uri.parse(`${vsls}:/test/Program.cs`),
21+
];
22+
23+
const launchTargets = resourcesToLaunchTargets(testResources);
24+
25+
const liveShareTarget = launchTargets.find(target => target === vslsTarget);
26+
assert.exists(liveShareTarget, "Launch targets was not the Visual Studio Live Share target.");
27+
});
28+
29+
test(`Does not return the LiveShare launch target when processing local resources`, () => {
30+
const testResources: vscode.Uri[] = [
31+
vscode.Uri.parse(`/test.sln`),
32+
vscode.Uri.parse(`/test/test.csproj`),
33+
vscode.Uri.parse(`/test/Program.cs`),
34+
];
35+
36+
const launchTargets = resourcesToLaunchTargets(testResources);
37+
38+
const liveShareTarget = launchTargets.find(target => target === vslsTarget);
39+
assert.notExists(liveShareTarget, "Launch targets contained the Visual Studio Live Share target.");
40+
});
41+
});

0 commit comments

Comments
 (0)