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

Extract leetcode webview base class & add md settings listener#270

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

Merged
jdneo merged 9 commits intomasterfromvigilans/webview-base
Apr 16, 2019

Conversation

Vigilans
Copy link
Contributor

@VigilansVigilans changed the titleExtract leetcode webview base class & add md setings listenerExtract leetcode webview base class & add md settings listenerApr 14, 2019
}
}

protected showWebviewInternal(): this is { panel: WebviewPanel } {
Copy link
Member

Choose a reason for hiding this comment

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

Could you explain more about this method? The return type isthis, but the actual returned value istrue

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

param is type is a user-definedtype guard in typescript's grammar.

It reduced the scope of union type:

functionisTypeDefined(obj:Type|undefined):obj isType{returnobj!==undefined;}leta:Type|undefined;a.method()// ts error, a may be undefinedif(isTypeDefined(a)){a.method();// now a's type is only `Type`, `undefined` is reduced}

this is type is a way to guard a class member's type:
microsoft/TypeScript#26212

this is { panel: WebviewPanel } makes surethis.panel is not undefined.

So the code here do not need to usethis.panel!.method() to assert defined:

if(this.showWebviewInternal()){this.panel.title=`${node.name}: Preview`;// now this.panel's undefined type is reducedthis.panel.reveal(ViewColumn.One);}

Copy link
Member

Choose a reason for hiding this comment

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

Then why we are not just callingshowWebviewInternal() but put it in the if block.

I do not see any benefits to do this.

Copy link
ContributorAuthor

@VigilansVigilansApr 15, 2019
edited
Loading

Choose a reason for hiding this comment

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

You mean the code below?

this.showWebviewInternal();this.panel!.title=`${node.name}: Preview`;// this.panel's undefined type is not reducedthis.panel!.reveal(ViewColumn.One);

Copy link
Member

Choose a reason for hiding this comment

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

The main problem here is, we should extract the fields inILeetCodeWebviewOption as the member of the base class. The reason for doing that:

  1. Each web view has its own uniqueviewType
  2. Each web view has its own location to display - theviewColumn
  3. Each web view has the member title to determine the title of the editor.

So after the extraction, what you need to do is:

  1. Move all the logic about the panel update intoshowWebviewInternal()
  2. Update the title field when needed.
this.title=xxxxthis.showWebviewInternal();

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I've brought everything exceptsideMode in next PR to this PR. It includes the improvement on the webview base class, like mentioned above.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Do you really think there is no relationship? Did you ever test yourself what is the visual effect when the title keepsA so long long long long long name: preview andA so long long long long long name: solution in Column 2? Will the user be able to easily change between the tabs?

Why do you pay more attention to something in the next PR which I haven't given illustration yet?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I just want leetcode tabs in column 2 look like this way:
image

Otherwise, in my small-screen PC, aSo long long long a name: Preview just occupies all the room in the Column 2.

Copy link
Member

Choose a reason for hiding this comment

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

Of cause I need to understand what you will do in the next PR since they have some relationship. This will determine whether we need to keepgetWebviewOption() or make them as the class member.

The codes written in a good way should not only have good experience but also good at self-explain. This is very important to attract more community contribution. That's why I'm keeping asking you those questions. From the code itself, I cannot get your point. There's no GIF/picture to illustrate that. Then how could I know your point is that the tab is so long that make the experience bad?

Besides, From my understanding, the reason to rename to the title toDescription is that you hope the size of the tab is not too big when VS Code has two columns. The real reason actually is having limited resolution, and multiple columns is one of the possible reason to cause the limited resolution.

Take the VS Code embedded Markdown extension as an example, You can see there is no optimization when the tab is too long.
image

Copy link
Member

Choose a reason for hiding this comment

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

I'm not saying that we should not do the optimation. It's acceptable to do it as long as the code logic is easy to understand.

localResourceRoots: markdownEngine.localResourceRoots,
});
this.panel.onDidDispose(this.onDidDisposeWebview, this, this.context.subscriptions);
this.panel.webview.onDidReceiveMessage(this.onDidReceiveMessage, this, this.context.subscriptions);
Copy link
Member

@jdneojdneoApr 15, 2019
edited
Loading

Choose a reason for hiding this comment

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

nit: TheonDidReceiveMessage can also be disposed inonDidDisposeWebview

Put it intosubscriptions is fine though.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

another alternative is to passthis.context.subscriptions toworkspace.onDidChangeConfiguration, and do not maintainconfigListener inLeetCodeWebview?

Copy link
Member

Choose a reason for hiding this comment

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

Just my personal opinion: putting intosubscriptions is a passive way to clean up the memory:

An array to which disposables can be added. When this extension is deactivated the disposables will be disposed.

It's more suitable for the command, global objects, etc. Since once the command is registered, in most cases you will not remove it during the extension is running.

While here, once the panel is disposed. We need to dispose the listener as well to avoid that multiple listeners are working in the meantime. So disposing them in theonDidDisposeWebview() could be better.

Copy link
ContributorAuthor

@VigilansVigilansApr 15, 2019
edited
Loading

Choose a reason for hiding this comment

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

This way?

private listeners:Disposable[]=[];//...this.panel.onDidDispose(this.onDidDisposeWebview,this,this.listeners);this.panel.webview.onDidReceiveMessage(this.onDidReceiveMessage,this,this.listeners);workspace.onDidChangeConfiguration(this.onDidChangeConfiguration,this,this.listeners);//...protectedonDidDisposeWebview():void{    this.panel=undefined;for(constlistenerofthis.listeners){listener.dispose();}this.listeners=[];}

In this way,this.context will reportnever used by tslint. We could make such modification:

publicinitialize(context:ExtensionContext):void{    this.context=context;this.context.subscriptions.push(this);}

It separates the intialization code inactivate function. Or, we could just movethis.context out of webview.

Copy link
Member

Choose a reason for hiding this comment

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

just movethis.context out of webview looks good to me.

}
}

protected showWebviewInternal(): this is { panel: WebviewPanel } {
Copy link
Member

Choose a reason for hiding this comment

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

Then why we are not just callingshowWebviewInternal() but put it in the if block.

I do not see any benefits to do this.

@Vigilans
Copy link
ContributorAuthor

illustration about side mode:

Walkthrough:
WalkThrough

ShowProblem command also benefits from it:
ShowProblem

Solution weview always follows the state of preview:
Preview   Solution

What if the title doesn't change (this is on a wide-screen computer):
WhatIf

@Vigilans
Copy link
ContributorAuthor

My argument for usinggetWebviewOption() is that it is in parallel withgetWebviewContent():

  1. They all provide the function of dynamic updating.
    Now thatviewColumn andtitle's need to be updated dynamiclly is recognized, we can viewgetWebviewOption() andgetWebviewContent() as two decoupled procedures of updating a webview.
    show() is only a stub receiving input parameters, followed withshowWebviewInternal().

  2. .title,.viewColumn &.webivew.html should be three equal-level buiding-blocks of a webview.
    If we keeptitle as a member of base class, then the same applies for.webview.html.

  3. As a class member,.title,.viewColumn &.webivew.html has already been saved inthis.panel, we don't need to keep another copy of them.

Copy link
Member

@jdneojdneo left a comment

Choose a reason for hiding this comment

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

Thank you for the GIFs. Much more clear now.

@jdneojdneo merged commit781feb2 intomasterApr 16, 2019
@VigilansVigilans deleted the vigilans/webview-base branchApril 16, 2019 11:54
@jdneojdneo added this to the0.13.4 milestoneApr 17, 2019
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@jdneojdneojdneo approved these changes

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

Successfully merging this pull request may close these issues.

2 participants
@Vigilans@jdneo

[8]ページ先頭

©2009-2025 Movatter.jp