-
Notifications
You must be signed in to change notification settings - Fork 74
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
feat: add doctor visibility provider & extract doctor #930
Merged
kpodsiad
merged 2 commits into
scalameta:main
from
kpodsiad:feat/doctor-visibility-provider
Mar 31, 2022
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { ClientCommands, ServerCommands } from "metals-languageclient"; | ||
import { ViewColumn, WebviewPanel, window } from "vscode"; | ||
import { | ||
Disposable, | ||
ExecuteCommandParams, | ||
ExecuteCommandRequest, | ||
LanguageClient, | ||
NotificationType, | ||
} from "vscode-languageclient/node"; | ||
|
||
export interface DoctorVisibilityDidChangeParams { | ||
visible: boolean; | ||
} | ||
|
||
const doctorEndpoint = "metals/doctorVisibilityDidChange"; | ||
const doctorNotification = | ||
new NotificationType<DoctorVisibilityDidChangeParams>(doctorEndpoint); | ||
|
||
export class DoctorProvider implements Disposable { | ||
doctor: WebviewPanel | undefined; | ||
isVisible = false; | ||
|
||
constructor(private client: LanguageClient) {} | ||
|
||
dispose(): void { | ||
this.doctor?.dispose(); | ||
} | ||
|
||
private getDoctorPanel(isReload: boolean): WebviewPanel { | ||
if (!this.doctor) { | ||
this.doctor = window.createWebviewPanel( | ||
"metals-doctor", | ||
"Metals Doctor", | ||
ViewColumn.Active, | ||
{ enableCommandUris: true } | ||
); | ||
this.isVisible = true; | ||
|
||
this.doctor.onDidDispose(() => { | ||
this.client.sendNotification(doctorNotification, { visible: false }); | ||
this.isVisible = false; | ||
this.doctor = undefined; | ||
}); | ||
} else if (!isReload) { | ||
this.doctor.reveal(); | ||
} | ||
return this.doctor; | ||
} | ||
|
||
reloadOrRefreshDoctor(params: ExecuteCommandParams): void { | ||
const isRun = params.command === ClientCommands.RunDoctor; | ||
const isReload = params.command === ClientCommands.ReloadDoctor; | ||
if (isRun || (this.doctor && isReload)) { | ||
const html = params.arguments && params.arguments[0]; | ||
if (typeof html === "string") { | ||
const panel = this.getDoctorPanel(isReload); | ||
panel.webview.html = html; | ||
} | ||
} | ||
} | ||
|
||
async runDoctor(): Promise<void> { | ||
await this.client.sendRequest(ExecuteCommandRequest.type, { | ||
command: ServerCommands.DoctorRun, | ||
}); | ||
this.isVisible = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
There is also an option to change visibility if this tab isn't focused.
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.
onDidChangeViewState
fires when webview isn't focused or stops being visible?I assumed that if the webview is open then we should always treat it as "visible" - user may come to it anytime and we should display them actual status.
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.
Haha. Actually, this
visible
word usage attracted my attention to that and I decided to check if it really about visibility or not.Won't it be equal to the just opening a doctor page?
I think if we introduce some kind of cache it won't take a lot of time to refresh it after focusing on it back.