-
Notifications
You must be signed in to change notification settings - Fork 665
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Sync with upstream
@Vigilans Thank you for your contribution, will take a look later~ |
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(); |
There was a problem hiding this comment.
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 into this.onDidChangeTreeDataEvent.fire()
(This API can accept a node element. Then all the data are cleared before the explorer rerendering.
There was a problem hiding this comment.
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, in updateProblem
function, we can fire events to request all relative nodes to be updated.
There was a problem hiding this comment.
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 the Two Sum
in All Problem
, will the Two Sum
in Difficulty
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So updateProblem()
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, |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason we separate allProblems
with treeData
?
There was a problem hiding this comment.
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 to
this.onDidChangeTreeDataEvent.fire(problem)
review below, we may need another lookup dictionary for fast retrieving relative nodes.allProblems
seems more similar to it rather thantreeData
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now allProblems
is decoupled with treeData
, and will be grouped with allTreeNodes
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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we directly compare p.id
with problem.id
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 use findIndex
and splice
to add/remove items, which I think is hard to read.
Can we change it to a Map?
There was a problem hiding this comment.
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 updating treeData[Category.Company/Tag]
field is necessary(delete problem from treeview after it is solved)?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 handle isFavorite
here, but the method name looks like we can update all the fields.
There was a problem hiding this comment.
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 other treeData
fields the at a later time. Seems a overdesign here?
Should I leave a comment announcing modification of other categories is not needed yet
here, or just change the method name?
There was a problem hiding this comment.
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.
In order to hide solved problems in Now, |
return { | ||
label: element.name, | ||
tooltip: this.getSubCategoryTooltip(element), | ||
id: `LeetCode.Category::${element.parentId}.${element.id}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we have element.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)
There was a problem hiding this comment.
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 remove element.parentId
& Data.Now()
, right?
There was a problem hiding this comment.
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
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>(); |
There was a problem hiding this comment.
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 as LeetCodeNode | null | undefined
You can address it in the next PR
There was a problem hiding this comment.
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 is fire(data: T?)
where T=LeetCodeNode, so no need to append null and undefined here
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
This field is officially public since vscode engine 1.30, and TreeItem.highlight
Toggle Favorite through buttonThis is the solution adopted by gitlens, which I think perfectly suits the situation: Reference RepoI think this PR could be temporarily suspended for further discussion, or merge it for now and then progressively refactoring the TreeDataProvider. |
@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. |
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. |
Seems this PR is out of date. Shall we close this and open another PR about |
@jdneo Yes, and there are some more improvements that could be done on |
Introduction
Solved following issues:
All
problem list #184Details
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.All Problems
Category andFavorite
Category.Flaw
TreeDataProvider
.Demonstration