From bb101a210f3253c646173f7f85b1e7031708ed9c Mon Sep 17 00:00:00 2001 From: "sheche@microsoft.com" Date: Tue, 14 May 2019 20:44:09 +0800 Subject: [PATCH] fix: leetcode.hideSolved not working --- src/explorer/explorerNodeManager.ts | 7 ++++++- src/utils/settingUtils.ts | 12 ++++++++++++ src/utils/uiUtils.ts | 2 +- src/utils/workspaceUtils.ts | 4 ---- 4 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 src/utils/settingUtils.ts diff --git a/src/explorer/explorerNodeManager.ts b/src/explorer/explorerNodeManager.ts index e58dc8ea..95053263 100644 --- a/src/explorer/explorerNodeManager.ts +++ b/src/explorer/explorerNodeManager.ts @@ -4,7 +4,8 @@ import * as _ from "lodash"; import { Disposable } from "vscode"; import * as list from "../commands/list"; -import { Category, defaultProblem } from "../shared"; +import { Category, defaultProblem, ProblemState } from "../shared"; +import { shouldHideSolvedProblem } from "../utils/settingUtils"; import { LeetCodeNode } from "./LeetCodeNode"; class ExplorerNodeManager implements Disposable { @@ -14,7 +15,11 @@ class ExplorerNodeManager implements Disposable { public async refreshCache(): Promise { this.dispose(); + const shouldHideSolved: boolean = shouldHideSolvedProblem(); for (const problem of await list.listProblems()) { + if (shouldHideSolved && problem.state === ProblemState.AC) { + continue; + } this.explorerNodeMap.set(problem.id, new LeetCodeNode(problem)); for (const company of problem.companies) { this.companySet.add(company); diff --git a/src/utils/settingUtils.ts b/src/utils/settingUtils.ts new file mode 100644 index 00000000..c6c643c4 --- /dev/null +++ b/src/utils/settingUtils.ts @@ -0,0 +1,12 @@ +// Copyright (c) jdneo. All rights reserved. +// Licensed under the MIT license. + +import { workspace, WorkspaceConfiguration } from "vscode"; + +export function getWorkspaceConfiguration(): WorkspaceConfiguration { + return workspace.getConfiguration("leetcode"); +} + +export function shouldHideSolvedProblem(): boolean { + return getWorkspaceConfiguration().get("hideSolved", false); +} diff --git a/src/utils/uiUtils.ts b/src/utils/uiUtils.ts index 845865e8..1fec63e3 100644 --- a/src/utils/uiUtils.ts +++ b/src/utils/uiUtils.ts @@ -4,7 +4,7 @@ import * as vscode from "vscode"; import { getLeetCodeEndpoint } from "../commands/plugin"; import { leetCodeChannel } from "../leetCodeChannel"; -import { getWorkspaceConfiguration } from "./workspaceUtils"; +import { getWorkspaceConfiguration } from "./settingUtils"; export namespace DialogOptions { export const open: vscode.MessageItem = { title: "Open" }; diff --git a/src/utils/workspaceUtils.ts b/src/utils/workspaceUtils.ts index 425074df..f2f2d16b 100644 --- a/src/utils/workspaceUtils.ts +++ b/src/utils/workspaceUtils.ts @@ -40,7 +40,3 @@ export async function getActiveFilePath(uri?: vscode.Uri): Promise