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

Provide actionable error messages for .NET SDK issues #5225

Merged
merged 1 commit into from
May 25, 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
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Known Issues in 1.25.0
## Known Issues in 1.25.1

* For Mono-based development (e.g. Unity) that requires full .NET framework, you need to set `"omnisharp.useModernNet": false`.
* After selecting a solution filter (*.slnf) from the project selector, the solution's name will be displayed in the status bar instead of the filter's.
Expand All @@ -12,7 +12,10 @@
* Renaming symbol fails within a file that had recently been renamed without saving changes.
* As a workaround, make an edit within the file before using Rename Symbol.

## 1.25.0
## 1.25.1
* Provide actionable error messages for .NET SDK issues ([#5223](https://github.com/OmniSharp/omnisharp-vscode/issues/5223), PR: [#5225](https://github.com/OmniSharp/omnisharp-vscode/pull/5225))

## 1.25.0 (May 24th, 2022)
* Make SDK build of OmniSharp the default ([#5120](https://github.com/OmniSharp/omnisharp-vscode/issues/5120), PR: [#5176](https://github.com/OmniSharp/omnisharp-vscode/pull/5176))
* Add auto complete name to class, interface, enum, struct etc. snippets (PR: [#5198](https://github.com/OmniSharp/omnisharp-vscode/pull/5198))
* Add a fallback for ps in remoteProcessPickerScript ([#4096](https://github.com/OmniSharp/omnisharp-vscode/issues/4096), PR: [#5207](https://github.com/OmniSharp/omnisharp-vscode/pull/5207))
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ If you still need Unity or .NET Framework support, you can set `omnisharp.useMod

See issue [#5120](https://github.com/OmniSharp/omnisharp-vscode/issues/5120) for more details.

## What's new in 1.25.1
* Provide actionable error messages for .NET SDK issues ([#5223](https://github.com/OmniSharp/omnisharp-vscode/issues/5223), PR: [#5225](https://github.com/OmniSharp/omnisharp-vscode/pull/5225))

## What's new in 1.25.0
* Make SDK build of OmniSharp the default ([#5120](https://github.com/OmniSharp/omnisharp-vscode/issues/5120), PR: [#5176](https://github.com/OmniSharp/omnisharp-vscode/pull/5176))
* Add auto complete name to class, interface, enum, struct etc. snippets (PR: [#5198](https://github.com/OmniSharp/omnisharp-vscode/pull/5198))
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "csharp",
"publisher": "ms-dotnettools",
"version": "1.25.0",
"version": "1.25.1",
"description": "C# for Visual Studio Code (powered by OmniSharp).",
"displayName": "C#",
"author": "Microsoft Corporation",
Expand Down
19 changes: 10 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ export async function activate(context: vscode.ExtensionContext): Promise<CSharp
util.setExtensionPath(extension.extensionPath);

const eventStream = new EventStream();

let platformInfo: PlatformInformation;
try {
platformInfo = await PlatformInformation.GetCurrent();
}
catch (error) {
eventStream.post(new ActivationFailure());
}

const optionStream = createOptionStream(vscode);
let optionProvider = new OptionProvider(optionStream);

Expand All @@ -79,7 +88,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<CSharp
eventStream.subscribe(csharpLogObserver.post);

let omnisharpChannel = vscode.window.createOutputChannel('OmniSharp Log');
let omnisharpLogObserver = new OmnisharpLoggerObserver(omnisharpChannel);
let omnisharpLogObserver = new OmnisharpLoggerObserver(omnisharpChannel, platformInfo);
let omnisharpChannelObserver = new OmnisharpChannelObserver(omnisharpChannel, vscode);
eventStream.subscribe(omnisharpLogObserver.post);
eventStream.subscribe(omnisharpChannelObserver.post);
Expand Down Expand Up @@ -117,14 +126,6 @@ export async function activate(context: vscode.ExtensionContext): Promise<CSharp
eventStream.subscribe(omnisharpDebugModeLoggerObserver.post);
}

let platformInfo: PlatformInformation;
try {
platformInfo = await PlatformInformation.GetCurrent();
}
catch (error) {
eventStream.post(new ActivationFailure());
}

if (!isSupportedPlatform(platformInfo)) {
const platform: string = platformInfo.platform ? platformInfo.platform : "this platform";
const architecture: string = platformInfo.architecture ? platformInfo.architecture : " and <unknown processor architecture>";
Expand Down
27 changes: 26 additions & 1 deletion src/observers/OmnisharpLoggerObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ import { BaseLoggerObserver } from "./BaseLoggerObserver";
import { BaseEvent, OmnisharpInitialisation, OmnisharpLaunch, OmnisharpFailure, OmnisharpServerMessage, OmnisharpServerOnServerError, OmnisharpServerOnError, OmnisharpServerMsBuildProjectDiagnostics, OmnisharpServerOnStdErr, OmnisharpEventPacketReceived } from "../omnisharp/loggingEvents";
import * as os from 'os';
import { EventType } from "../omnisharp/EventType";
import * as vscode from 'vscode';
import { PlatformInformation } from "../platform";
import { Logger } from "../logger";

export class OmnisharpLoggerObserver extends BaseLoggerObserver {
constructor(channel: vscode.OutputChannel | Logger, private platformInformation: PlatformInformation) {
super(channel);
}

public post = (event: BaseEvent) => {
switch (event.type) {
case EventType.OmnisharpInitialisation:
Expand All @@ -34,7 +41,7 @@ export class OmnisharpLoggerObserver extends BaseLoggerObserver {
this.handleOmnisharpServerMsBuildProjectDiagnostics(<OmnisharpServerMsBuildProjectDiagnostics>event);
break;
case EventType.OmnisharpServerOnStdErr:
this.logger.append((<OmnisharpServerOnStdErr>event).message);
this.handleOmnisharpServerOnStdErr(<OmnisharpServerOnStdErr>event);
break;
case EventType.OmnisharpEventPacketReceived:
this.handleOmnisharpEventPacketReceived(<OmnisharpEventPacketReceived>event);
Expand All @@ -43,9 +50,27 @@ export class OmnisharpLoggerObserver extends BaseLoggerObserver {
}

private handleOmnisharpServerOnServerError(event: OmnisharpServerOnServerError) {
if (event.err.cmd === "dotnet --version") {
this.logger.appendLine('[ERROR] A .NET 6 SDK was not found. Please install the latest SDK from https://dotnet.microsoft.com/en-us/download/dotnet/6.0.');
return;
}
else if (event.err.message?.startsWith("Found dotnet version")) {
this.logger.appendLine(`[ERROR] ${event.err} Please install the latest SDK from https://dotnet.microsoft.com/en-us/download/dotnet/6.0.`);
return;
}

this.logger.appendLine('[ERROR] ' + event.err);
}

private handleOmnisharpServerOnStdErr(event: OmnisharpServerOnStdErr) {
if (event.message.startsWith("System.BadImageFormatException: Could not load file or assembly")) {
this.logger.appendLine(`[ERROR] A .NET 6 SDK for ${this.platformInformation.architecture} was not found. Please install the latest ${this.platformInformation.architecture} SDK from https://dotnet.microsoft.com/en-us/download/dotnet/6.0.`);
return;
}

this.logger.appendLine('[STDERR] ' + event.message);
}

private handleOmnisharpInitialisation(event: OmnisharpInitialisation) {
this.logger.appendLine(`Starting OmniSharp server at ${event.timeStamp.toLocaleString()}`);
this.logger.increaseIndent();
Expand Down
10 changes: 8 additions & 2 deletions test/unitTests/logging/OmnisharpLoggerObserver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ import { should, expect } from 'chai';
import { getNullChannel } from '../testAssets/Fakes';
import { OmnisharpLoggerObserver } from '../../../src/observers/OmnisharpLoggerObserver';
import { OmnisharpServerMsBuildProjectDiagnostics, EventWithMessage, OmnisharpServerOnStdErr, OmnisharpServerMessage, OmnisharpServerOnServerError, OmnisharpInitialisation, OmnisharpLaunch, OmnisharpServerOnError, OmnisharpFailure, OmnisharpEventPacketReceived } from '../../../src/omnisharp/loggingEvents';
import { OutputChannel } from 'vscode';
import { PlatformInformation } from '../../../src/platform';

suite("OmnisharpLoggerObserver", () => {
suiteSetup(() => should());

let logOutput = "";
let observer = new OmnisharpLoggerObserver({
let channel = <OutputChannel>{
...getNullChannel(),
append: (text: string) => { logOutput += text; },
append: (text: string) => { logOutput += text; }
};
let observer = new OmnisharpLoggerObserver(channel, <PlatformInformation>{
architecture: "x128",
platform: "TestOS"
});

setup(() => {
Expand Down