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

Low-hanging nullable fruit #5186

Merged
merged 19 commits into from
Apr 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
37 changes: 6 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -915,11 +915,7 @@
"description": "Show hints for implicit object creation"
},
"omnisharp.path": {
"type": [
"string",
"null"
],
"default": null,
"type": "string",
"scope": "machine",
"description": "Specifies the path to OmniSharp. When left empty the OmniSharp version pinned to the C# Extension is used. This can be the absolute path to an OmniSharp executable, a specific version number, or \"latest\". If a version number or \"latest\" is specified, the appropriate version of OmniSharp will be downloaded on your behalf. Setting \"latest\" is an opt-in into latest beta releases of OmniSharp."
},
Expand All @@ -946,20 +942,12 @@
"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."
},
"omnisharp.monoPath": {
"type": [
"string",
"null"
],
"default": null,
"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\""
},
"omnisharp.dotnetPath": {
"type": [
"string",
"null"
],
"default": null,
"type": "string",
"scope": "window",
"description": "Specified the path to a dotnet installation to use when \"useModernNet\" is set to true, instead of the default system one. Example: \"/home/username/mycustomdotnetdirectory\"."
},
Expand Down Expand Up @@ -998,7 +986,6 @@
},
"omnisharp.defaultLaunchSolution": {
"type": "string",
"default": null,
"description": "The name of the default solution used at start up if the repo has multiple solutions. e.g.'MyAwesomeSolution.sln'. Default value is `null` which will cause the first in alphabetical order to be chosen."
},
"omnisharp.useEditorFormattingSettings": {
Expand Down Expand Up @@ -1063,19 +1050,11 @@
"description": "Only run analyzers against open files when 'enableRoslynAnalyzers' is true"
},
"omnisharp.testRunSettings": {
"type": [
"string",
"null"
],
"default": null,
"type": "string",
"description": "Path to the .runsettings file which should be used when running unit tests."
},
"razor.plugin.path": {
"type": [
"string",
"null"
],
"default": null,
"type": "string",
"scope": "machine",
"description": "Overrides the path to the Razor plugin dll."
},
Expand All @@ -1090,11 +1069,7 @@
"description": "Specifies whether to disable Razor language features."
},
"razor.languageServer.directory": {
"type": [
"string",
"null"
],
"default": null,
"type": "string",
"scope": "machine",
"description": "Overrides the path to the Razor Language Server directory."
},
Expand Down
8 changes: 1 addition & 7 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ export function safeLength<T>(arr: T[] | undefined) {
return arr ? arr.length : 0;
}

export async function buildPromiseChain<T, TResult>(array: T[], builder: (item: T) => Promise<TResult>): Promise<TResult> {
return array.reduce(
async (promise, n) => promise.then(async () => builder(n)),
Promise.resolve<TResult>(null));
}

export async function execChildProcess(command: string, workingDirectory: string = getExtensionPath()): Promise<string> {
return new Promise<string>((resolve, reject) => {
cp.exec(command, { cwd: workingDirectory, maxBuffer: 500 * 1024 }, (error, stdout, stderr) => {
Expand Down Expand Up @@ -229,4 +223,4 @@ export function isSubfolderOf(subfolder: string, folder: string): boolean {
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/features/diagnosticsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class DiagnosticsProvider extends AbstractSupport {

this._subscriptions.push(this._validateCurrentDocumentPipe
.pipe(debounceTime(750))
.subscribe(x => this._validateDocument(x)));
.subscribe(async document => await this._validateDocument(document)));

this._subscriptions.push(this._validateAllPipe
.pipe(debounceTime(3000))
Expand Down
2 changes: 1 addition & 1 deletion src/features/dotnetTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export default class TestManager extends AbstractProvider {

private _getRunSettings(filename: string): string | undefined {
const testSettingsPath = this.optionProvider.GetLatestOptions().testRunSettings;
if (!testSettingsPath) {
if (testSettingsPath.length === 0) {
return undefined;
}

Expand Down
5 changes: 5 additions & 0 deletions src/features/fileOpenCloseProvider.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { IDisposable } from "../Disposable";
import { OmniSharpServer } from "../omnisharp/server";
import * as vscode from 'vscode';
Expand Down
7 changes: 4 additions & 3 deletions src/omnisharp/LanguageMiddlewareFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ type RemapParameterType<M extends keyof RemapApi> = GetRemapType<NonNullable<Rem

export class LanguageMiddlewareFeature implements IDisposable {
private readonly _middlewares: LanguageMiddleware[];
private _registration: IDisposable;
private _registration: IDisposable | undefined;

constructor() {
this._middlewares = [];
}

public dispose(): void {
this._registration.dispose();
// this._registration should always be defined, but just in case we never register...
this._registration?.dispose();
}

public register(): void {
Expand Down Expand Up @@ -69,4 +70,4 @@ export class LanguageMiddlewareFeature implements IDisposable {
return original;
}
}
}
}
2 changes: 1 addition & 1 deletion src/omnisharp/OmniSharpDotnetResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class OmniSharpDotnetResolver implements IHostExecutableResolver {
const dotnet = this.platformInfo.isWindows() ? 'dotnet.exe' : 'dotnet';
const env = { ...process.env };

if (options.dotnetPath) {
if (options.dotnetPath.length > 0) {
env['PATH'] = options.dotnetPath + path.delimiter + env['PATH'];
}

Expand Down
5 changes: 2 additions & 3 deletions src/omnisharp/OmniSharpMonoResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class OmniSharpMonoResolver implements IHostExecutableResolver {
private async configureEnvironmentAndGetInfo(options: Options): Promise<HostExecutableInformation> {
let env = { ...process.env };
let monoPath: string;
if (options.useGlobalMono !== "never" && options.monoPath !== undefined) {
if (options.useGlobalMono !== "never" && options.monoPath.length > 0) {
env['PATH'] = path.join(options.monoPath, 'bin') + path.delimiter + env['PATH'];
env['MONO_GAC_PREFIX'] = options.monoPath;
monoPath = options.monoPath;
Expand All @@ -40,7 +40,7 @@ export class OmniSharpMonoResolver implements IHostExecutableResolver {
if (options.useGlobalMono === "always") {
let isMissing = monoInfo.version === undefined;
if (isMissing) {
const suggestedAction = options.monoPath
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}`);
Expand All @@ -61,4 +61,3 @@ export class OmniSharpMonoResolver implements IHostExecutableResolver {
return undefined;
}
}

3 changes: 1 addition & 2 deletions src/omnisharp/OmnisharpDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ export class OmnisharpDownloader {
this.eventStream.post(new InstallationSuccess());
return true;
}

return false;
}
return false;
}

public async GetLatestVersion(serverUrl: string, latestVersionFileServerPath: string): Promise<string> {
Expand Down
4 changes: 2 additions & 2 deletions src/omnisharp/OmnisharpManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export class OmnisharpManager {
}

public async GetOmniSharpLaunchInfo(defaultOmnisharpVersion: string, omnisharpPath: string, useFramework: boolean, serverUrl: string, latestVersionFileServerPath: string, installPath: string, extensionPath: string): Promise<LaunchInfo> {
if (!omnisharpPath) {
if (omnisharpPath.length === 0) {
// If omnisharpPath was not specified, return the default path.
let basePath = path.resolve(extensionPath, '.omnisharp', defaultOmnisharpVersion + (useFramework ? '' : `-net${modernNetVersion}`));
const basePath = path.resolve(extensionPath, '.omnisharp', defaultOmnisharpVersion + (useFramework ? '' : `-net${modernNetVersion}`));
return this.GetLaunchInfo(this.platformInfo, useFramework, basePath);
}

Expand Down
4 changes: 2 additions & 2 deletions src/omnisharp/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export async function activate(context: vscode.ExtensionContext, packageJSON: an
const languageMiddlewareFeature = new LanguageMiddlewareFeature();
languageMiddlewareFeature.register();
disposables.add(languageMiddlewareFeature);
let localDisposables: CompositeDisposable;
let localDisposables: CompositeDisposable | undefined;
const testManager = new TestManager(optionProvider, server, eventStream, languageMiddlewareFeature);
const completionProvider = new CompletionProvider(server, languageMiddlewareFeature);

Expand Down Expand Up @@ -130,7 +130,7 @@ export async function activate(context: vscode.ExtensionContext, packageJSON: an
if (localDisposables) {
localDisposables.dispose();
}
localDisposables = null;
localDisposables = undefined;
}));

disposables.add(registerCommands(context, server, platformInfo, eventStream, optionProvider, omnisharpMonoResolver, packageJSON, extensionPath));
Expand Down
4 changes: 2 additions & 2 deletions src/omnisharp/fileOperationsResponseEditBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { toRange2 } from './typeConversion';
export async function buildEditForResponse(changes: FileOperationResponse[], languageMiddlewareFeature: LanguageMiddlewareFeature, token: vscode.CancellationToken): Promise<boolean> {
let edit = new vscode.WorkspaceEdit();

let fileToOpen: Uri = null;
let fileToOpen: Uri | undefined;

if (!changes || !Array.isArray(changes) || !changes.length) {
return true;
Expand Down Expand Up @@ -55,7 +55,7 @@ export async function buildEditForResponse(changes: FileOperationResponse[], lan
// and replaced with a command that can only close the active editor.
// If files were renamed that weren't the active editor, their tabs will
// be left open and marked as "deleted" by VS Code
return fileToOpen != null
return fileToOpen !== undefined
? applyEditPromise.then(_ => {
return vscode.commands.executeCommand("vscode.open", fileToOpen);
})
Expand Down
2 changes: 1 addition & 1 deletion src/omnisharp/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export function resourcesToLaunchTargets(resources: vscode.Uri[]): LaunchTarget[
let buckets: vscode.Uri[];

if (workspaceFolderToUriMap.has(folder.index)) {
buckets = workspaceFolderToUriMap.get(folder.index);
buckets = workspaceFolderToUriMap.get(folder.index)!; // Ensured valid via has.
} else {
buckets = [];
workspaceFolderToUriMap.set(folder.index, buckets);
Expand Down
2 changes: 1 addition & 1 deletion src/omnisharp/loggingEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class OmnisharpInitialisation implements BaseEvent {

export class OmnisharpLaunch implements BaseEvent {
type = EventType.OmnisharpLaunch;
constructor(public hostVersion: string, public hostPath: string, public hostIsMono: boolean, public command: string, public pid: number) { }
constructor(public hostVersion: string | undefined, public hostPath: string | undefined, public hostIsMono: boolean, public command: string, public pid: number) { }
}

export class PackageInstallStart implements BaseEvent {
Expand Down
Loading