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

Make SDK build of OmniSharp the default #5176

Merged
merged 15 commits into from
May 19, 2022
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
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ indent_size = 4
trim_trailing_whitespace = true

# 2 space indentation and utf-8 for *.yml, package.json, and .json files under src
[{*.yml,package.json,src/**/*.json}]
[{*.yml,package.json,*.json}]
indent_size = 2
charset = utf-8
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
- name: Setup virtual display
run: /usr/bin/Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &

- name: Install .NET Core 5.0 SDK
- name: Install .NET Core 6.0 SDK
uses: actions/setup-dotnet@v1.7.2
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x

- name: Install Node.js 15.x
uses: actions/setup-node@v1
Expand Down
110 changes: 54 additions & 56 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 5 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"@types/unzipper": "^0.9.1",
"@types/vscode": "1.65.0",
"@types/yauzl": "2.9.1",
"@vscode/test-electron": "2.1.3",
"archiver": "5.3.0",
"chai": "4.3.4",
"chai-arrays": "2.2.0",
Expand All @@ -121,7 +122,6 @@
"typescript": "4.2.4",
"unzipper": "0.10.11",
"vsce": "1.100.2",
"vscode-test": "1.6.1",
"webpack": "5.34.0",
"webpack-cli": "4.6.0"
},
Expand Down Expand Up @@ -921,30 +921,15 @@
},
"omnisharp.useModernNet": {
"type": "boolean",
"default": false,
"default": true,
"scope": "window",
"title": "Use .NET 6 build of OmniSharp (experimental)",
"description": "Use OmniSharp build for .NET 6. This version _does not_ support non-SDK-style .NET Framework projects, including Unity. SDK-style Framework, .NET Core, and .NET 5+ projects should see significant performance improvements, but there may still be bugs. Please open issues if you find any bugs."
},
"omnisharp.useGlobalMono": {
"type": "string",
"default": "auto",
"enum": [
"auto",
"always",
"never"
],
"enumDescriptions": [
"Automatically launch OmniSharp with internal \"mono\", since \"mono\" 6.12.0 does not support .NET Core 3.1.40x or .NET 5 SDKs.",
"Always launch OmniSharp with \"mono\". If version 6.4.0 or greater is not available on the PATH, an error will be printed.",
"Never launch OmniSharp on a globally-installed Mono."
],
"description": "Launch OmniSharp with the globally-installed Mono. If set to \"always\", \"mono\" version 6.4.0 or greater must be available on the PATH. If set to \"auto\", OmniSharp will be launched with \"mono\" if version 6.4.0 or greater is available on the PATH."
"title": "Use .NET 6 build of OmniSharp",
"description": "Use OmniSharp build for .NET 6. This version _does not_ support non-SDK-style .NET Framework projects, including Unity. SDK-style Framework, .NET Core, and .NET 5+ projects should see significant performance improvements."
},
"omnisharp.monoPath": {
"type": "string",
"scope": "machine",
"description": "Specifies the path to a mono installation to use when \"useGlobalMono\" is set to \"always\", instead of the default system one. Example: \"/Library/Frameworks/Mono.framework/Versions/Current\""
"description": "Specifies the path to a mono installation to use when \"useModernNet\" is set to false, instead of the default system one. Example: \"/Library/Frameworks/Mono.framework/Versions/Current\""
},
"omnisharp.dotnetPath": {
"type": "string",
Expand Down
9 changes: 3 additions & 6 deletions src/features/reportIssue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,9 @@ async function getMonoIfPlatformValid(isValidPlatformForMono: boolean, options:
if (isValidPlatformForMono) {
let monoVersion: string;
try {
let globalMonoInfo = await monoResolver.getHostExecutableInfo(options);
if (globalMonoInfo) {
monoVersion = `OmniSharp using global mono :${globalMonoInfo.version}`;
}
else {
monoVersion = `OmniSharp using built-in mono`;
let monoInfo = await monoResolver.getHostExecutableInfo(options);
if (monoInfo) {
monoVersion = `OmniSharp using mono :${monoInfo.version}`;
}
}
catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/observers/OmnisharpLoggerObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class OmnisharpLoggerObserver extends BaseLoggerObserver {
this.logger.append(`OmniSharp server started`);
if (event.hostVersion) {
this.logger.append(` with ${event.hostIsMono ? 'Mono' : '.NET'} ${event.hostVersion}`);
if (event.hostPath !== undefined) {
if (event.hostPath?.length > 0) {
this.logger.append(` (${event.hostPath})`);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/observers/OptionChangeObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type OptionsKey = keyof Options;

const omniSharpOptions: ReadonlyArray<OptionsKey> = [
"path",
"useGlobalMono",
"enableMsBuildLoadProjectsOnDemand",
"waitForDebugger",
"loggingLevel",
Expand Down
41 changes: 17 additions & 24 deletions src/omnisharp/OmniSharpMonoResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ export class OmniSharpMonoResolver implements IHostExecutableResolver {
}

private async configureEnvironmentAndGetInfo(options: Options): Promise<HostExecutableInformation> {
let env = { ...process.env };
const env = { ...process.env };
let monoPath: string;
if (options.useGlobalMono !== "never" && options.monoPath.length > 0) {

if (options.monoPath.length > 0) {
env['PATH'] = path.join(options.monoPath, 'bin') + path.delimiter + env['PATH'];
env['MONO_GAC_PREFIX'] = options.monoPath;
monoPath = options.monoPath;
}

let version = await this.getMonoVersion(env);
const version = await this.getMonoVersion(env);

return {
version,
Expand All @@ -35,29 +36,21 @@ export class OmniSharpMonoResolver implements IHostExecutableResolver {
}

public async getHostExecutableInfo(options: Options): Promise<HostExecutableInformation> {
let monoInfo = await this.configureEnvironmentAndGetInfo(options);
let isValid = monoInfo.version && satisfies(monoInfo.version, `>=${this.minimumMonoVersion}`);
if (options.useGlobalMono === "always") {
let isMissing = monoInfo.version === undefined;
if (isMissing) {
const suggestedAction = options.monoPath.length > 0
? "Update the \"omnisharp.monoPath\" setting to point to the folder containing Mono's '/bin' folder."
: "Ensure that Mono's '/bin' folder is added to your environment's PATH variable.";
throw new Error(`Unable to find Mono. ${suggestedAction}`);
}

if (!isValid) {
throw new Error(`Found Mono version ${monoInfo.version}. Cannot start OmniSharp because Mono version >=${this.minimumMonoVersion} is required.`);
}

return monoInfo;
const monoInfo = await this.configureEnvironmentAndGetInfo(options);
const isValid = monoInfo.version && satisfies(monoInfo.version, `>=${this.minimumMonoVersion}`);

const isMissing = monoInfo.version === undefined;
if (isMissing) {
const suggestedAction = options.monoPath
? "Update the \"omnisharp.monoPath\" setting to point to the folder containing Mono's '/bin' folder."
: "Ensure that Mono's '/bin' folder is added to your environment's PATH variable.";
throw new Error(`Unable to find Mono. ${suggestedAction}`);
}
else if (options.useGlobalMono === "auto" && isValid) {
// While waiting for Mono to ship with a MSBuild version 16.8 or higher, we will treat "auto"
// as "Use included Mono".
// return monoInfo;

if (!isValid) {
throw new Error(`Found Mono version ${monoInfo.version}. Cannot start OmniSharp because Mono version >=${this.minimumMonoVersion} is required.`);
}

return undefined;
return monoInfo;
}
}
38 changes: 10 additions & 28 deletions src/omnisharp/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,21 +312,7 @@ async function launch(cwd: string, args: string[], launchInfo: LaunchInfo, platf
return launchWindows(launchInfo.LaunchPath, cwd, args);
}

let monoInfo = await monoResolver.getHostExecutableInfo(options);

if (monoInfo) {
const launchPath = launchInfo.MonoLaunchPath || launchInfo.LaunchPath;
let childEnv = monoInfo.env;
return {
...launchNixMono(launchPath, cwd, args, childEnv, options.waitForDebugger),
hostIsMono: true,
hostVersion: monoInfo.version,
hostPath: monoInfo.path
};
}
else {
return launchNix(launchInfo.LaunchPath, cwd, args);
}
return await launchNix(launchInfo, cwd, args, options, monoResolver);
}

function getConfigurationValue(globalConfig: vscode.WorkspaceConfiguration, csharpConfig: vscode.WorkspaceConfiguration,
Expand Down Expand Up @@ -393,20 +379,20 @@ function launchWindows(launchPath: string, cwd: string, args: string[]): LaunchR
};
}

function launchNix(launchPath: string, cwd: string, args: string[]): LaunchResult {
let process = spawn(launchPath, args, {
detached: false,
cwd: cwd
});
async function launchNix(launchInfo: LaunchInfo, cwd: string, args: string[], options: Options, monoResolver: IHostExecutableResolver): Promise<LaunchResult> {
const monoInfo = await monoResolver.getHostExecutableInfo(options);
const launchPath = launchInfo.MonoLaunchPath || launchInfo.LaunchPath;

return {
process,
process: launchNixMono(launchPath, cwd, args, monoInfo.env, options.waitForDebugger),
command: launchPath,
hostIsMono: false
hostIsMono: true,
hostVersion: monoInfo.version,
hostPath: monoInfo.path
};
}

function launchNixMono(launchPath: string, cwd: string, args: string[], environment: NodeJS.ProcessEnv, useDebugger: boolean): LaunchResult {
function launchNixMono(launchPath: string, cwd: string, args: string[], environment: NodeJS.ProcessEnv, useDebugger: boolean): ChildProcess {
let argsCopy = args.slice(0); // create copy of details args
argsCopy.unshift(launchPath);
argsCopy.unshift("--assembly-loader=strict");
Expand All @@ -422,9 +408,5 @@ function launchNixMono(launchPath: string, cwd: string, args: string[], environm
env: environment
});

return {
process,
command: launchPath,
hostIsMono: true
};
return process;
}
Loading