Skip to content

Commit e0e516d

Browse files
author
lhy
committed
完善非空判断
1 parent 472d9ad commit e0e516d

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/main.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ErrorHandler } from "./errorHandler";
1313
import { WebviewProvider } from "./webviewProvider";
1414
import { ApiService } from "./apiService";
1515
import { PasswordManager } from "./PasswordManager";
16+
import { isBlank } from "./utils/pawsqlUtils";
1617

1718
export class PawSQLExtension {
1819
private readonly decorationManager: DecorationManager;
@@ -56,11 +57,11 @@ export class PawSQLExtension {
5657
): Promise<void> {
5758
try {
5859
const config = vscode.workspace.getConfiguration("pawsql");
59-
const email = config.get<string>("email");
60-
const password = await this.passwordManager.getPassword();
61-
const backendUrl = config.get<string>("backendUrl");
60+
const email = config.get<string>("email") ?? "";
61+
const password = (await this.passwordManager.getPassword()) ?? "";
62+
const backendUrl = config.get<string>("backendUrl") ?? "";
6263

63-
if (!email || !password || !backendUrl) {
64+
if (isBlank(email) || isBlank(password) || isBlank(backendUrl)) {
6465
return;
6566
}
6667

src/utils/pawsqlUtils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,15 @@ const findNextValidQuery = (
150150

151151
return null;
152152
};
153+
154+
export function isNotBlank(
155+
a: string | null | undefined
156+
): a is Exclude<string, null | undefined> {
157+
return a !== undefined && a !== null && a !== "";
158+
}
159+
160+
export function isBlank(
161+
a: string | null | undefined
162+
): a is Exclude<string, null | undefined> {
163+
return a === undefined || a === null || a === "";
164+
}

0 commit comments

Comments
 (0)