Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Star Problems Extension && All Problems Category#188

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Vigilans wants to merge10 commits intoLeetCode-OpenSource:masterfromVigilans:enhanced-context
Closed

Star Problems Extension && All Problems Category#188

Vigilans wants to merge10 commits intoLeetCode-OpenSource:masterfromVigilans:enhanced-context

Conversation

Vigilans
Copy link
Contributor

Introduction

Solved following issues:

Details

Feature

  • LeetCodeNode now exposes its innerIProblem data throughnodeData property.
  • TreeDataProvider now preserves aallProblems field which holds the reference of all problems.
  • TreeDataProvider now provides ability to update one specific problem data with the help ofallProblems field.
  • The starred problem will be appended with "♥" in the tree item name.
  • The hovering tooltip is enhanced to work forAll Problems Category andFavorite Category.

Flaw

  • After star/unstar problems, the tree view return to uncollapsed state. It is because we do not store collapse state in theTreeDataProvider.

Demonstration

image
image
image

@jdneo
Copy link
Member

@Vigilans Thank you for your contribution, will take a look later~

@jdneojdneo self-requested a reviewMarch 6, 2019 10:27
if (this.allProblems.has(problem.id)) {
this.updateTreeDataByProblem(problem); // only modify the content of tree data, problem is not updated.
Object.assign(this.allProblems.get(problem.id), problem); // update problem, where reference is preserved.
this.onDidChangeTreeDataEvent.fire();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I guess that the reason that explorer returns to uncollapsed state is that, we do not pass the node element intothis.onDidChangeTreeDataEvent.fire() (This API can accept a node element. Then all the data are cleared before the explorer rerendering.

Copy link
ContributorAuthor

@VigilansVigilansMar 6, 2019
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

After some investigations I seems to get the hang of this API. Maybe we can keep another reference container here:

allTreeNodes:Map<string,LeetcodeNode[]>// id -> relative nodes

Then, inupdateProblem function, we can fire events to request all relative nodes to be updated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@Vigilans Cool. Noticed that now the same problem in the different category has different id. So if we refresh theTwo Sum inAll Problem, will theTwo Sum inDifficulty be refreshed?

That means, I'm thinking that if we should make the same problem has the same id in the whole explorer. Not sure the real behavior of it.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

After further investigations, to accomplish this feature, there are some important changes which I think should be discussed in next PR. In this PR, we may temporarily accept the current behavior?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

SoupdateProblem() is not used in this PR, right?

@@ -46,7 +56,7 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod

const idPrefix: number = Date.now();
return {
label: element.isProblem ? `[${element.id}] ${element.name}` : element.name,
label: element.isProblem ? `[${element.id}] ${element.name} ${element.isFavorite ? "♥" : ""}` : element.name,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Curious about the appearance on different OS platforms, haha.

@@ -13,6 +13,8 @@ import { LeetCodeNode } from "./LeetCodeNode";

export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCodeNode> {

private allProblems: Map<string, IProblem>; // store reference of all problems.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Any reason we separateallProblems withtreeData?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

  • allProblems is an id-IProblem dictionary primarily for fast lookup, whose structure is not compatible withtreeData;
  • allProblems serves as a buffer which holds all the problems' ownership, where elements intreeData is just references to the problems;
  • with regard tothis.onDidChangeTreeDataEvent.fire(problem) review below, we may need another lookup dictionary for fast retrieving relative nodes.allProblems seems more similar to it rather thantreeData.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

NowallProblems is decoupled withtreeData, and will be grouped withallTreeNodes as an object pool in next PR.

private updateTreeDataByProblem(problem: IProblem): void {
const origin: IProblem | undefined = this.allProblems.get(problem.id);
if (origin && origin.isFavorite !== problem.isFavorite) {
const problemIndex: number = this.treeData.Favorite.findIndex((p: LeetCodeNode) => Number(p.id) >= Number(problem.id));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

can we directly comparep.id withproblem.id?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The problems are originally in number-ascending order, thus the comparation in index searching should also be done this way.
e.g. the favorite problems' ids are ["1", "4", "16", "23"], I want to delete the problem with id "23" and id is compared directly. Since "4" >= "23" === true, the search process stops at "4", thus the deletion is incorrect.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

IMO, the main problem here is that we store the Favorite problems as an array instead of a Map(id -> Problem).

So you may observe that we have to usefindIndex andsplice to add/remove items, which I think is hard to read.

Can we change it to a Map?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Maybe it can be discussed in subsequent PRs, when updatingtreeData[Category.Company/Tag] field is necessary(delete problem from treeview after it is solved)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes, can be solved in another PR.

@@ -197,6 +230,18 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
].join(os.EOL);
}

private updateTreeDataByProblem(problem: IProblem): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The method name her is confusing. Cuz we only handleisFavorite here, but the method name looks like we can update all the fields.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I thought we might handle the case of updating othertreeData fields the at a later time. Seems a overdesign here?
Should I leave a comment announcingmodification of other categories is not needed yet here, or just change the method name?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Make sure now other fields will be updated here in the near PRs, e.g. when a problem is accepted, there will be some code here to update other fields.

@Vigilans
Copy link
ContributorAuthor

Vigilans commentedMar 7, 2019
edited
Loading

In order to hide solved problems inAll Problems category,Category.All is added as a field oftreeData.

Now,allProblems holds the ownership of every problem, whereastreeData[Category.All] may hide any problem that is solved.

return {
label: element.name,
tooltip: this.getSubCategoryTooltip(element),
id: `LeetCode.Category::${element.parentId}.${element.id}`,
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Now that we haveelement.parentId,Data.Now() prefix seems no longer necessary.

Btw, the TreeItem Generation code here is separated here for better readability, as well as convenience for next PR(store generated TreeItem somewhere in TreeProvider or LeetCodeNode)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

So you will send out another PR to removeelement.parentId &Data.Now(), right?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Data.Now() has already been removed here, which is taken place by element.parentId

@jdneo
Copy link
Member

I'll take a deep look at the weekend.

};

private onDidChangeTreeDataEvent: vscode.EventEmitter<any> = new vscode.EventEmitter<any>();
private onDidChangeTreeDataEvent: vscode.EventEmitter<LeetCodeNode> = new vscode.EventEmitter<LeetCodeNode>();
Copy link
Member

@jdneojdneoMar 8, 2019
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We can also support refresh the whole explorer, so the parameter type can be written asLeetCodeNode | null | undefined

You can address it in the next PR

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The event fire's parameter isfire(data: T?) where T=LeetCodeNode, so no need to append null and undefined here

@VigilansVigilans mentioned this pull requestMar 8, 2019
@Vigilans
Copy link
ContributorAuthor

Vigilans commentedMar 8, 2019
edited
Loading

There are so many interesting and important things about treeview...which will make our explorer far better than current form.

TreeItem.id & Collapse State

TreeItem.description

/** * A human readable string which is rendered less prominent. * When `true`, it is derived from [resourceUri](#TreeItem.resourceUri) and when `falsy`, it is not shown. */description?: string | boolean;

This field is officially public since vscode engine 1.30, andgitlens has already adopted it:
image
May be we can show some message including difficulty and pass rate to solve#192.

TreeItem.highlight

Update: proposed API is only available in insider...pass.

Toggle Favorite through button

This is the solution adopted by gitlens, which I think perfectly suits the situation:
image
image

Reference Repo

vscode-sample
GitLens

I think this PR could be temporarily suspended for further discussion, or merge it for now and then progressively refactoring the TreeDataProvider.

@jdneo
Copy link
Member

@Vigilans looks like we have a lot of works to do with the explorer. Yes, my personal suggestion is to suspend the PR just for now and implement the improvement one by one.

You can separately create issues for each of them, and we can discuss the implementation in each issue before sending out the PR.

@VigilansVigilans mentioned this pull requestMar 11, 2019
@Allianzcortex
Copy link

If we can add more search options(e.g. from easy->difficult) when displaying the problems in one category ,it can be awesome . The order of problems up to now is based on number order.

@jdneo
Copy link
Member

@Vigilans

Seems this PR is out of date. Shall we close this and open another PR abouttoggle the favorite problem? (Show all problems have been resolved)

@Vigilans
Copy link
ContributorAuthor

@jdneo Yes, and there are some more improvements that could be done ontoggleFavorite, like using a button to toggle.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@jdneojdneojdneo left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@Vigilans@jdneo@Allianzcortex

[8]ページ先頭

©2009-2025 Movatter.jp