Skip to content
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

chore: basic example how to use openTab on client/server side #865

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

volodkevych
Copy link
Contributor

@volodkevych volodkevych commented Mar 24, 2025

Problem

DO NOT MERGE

Solution

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@@ -52,6 +64,35 @@ export function registerChat(languageClient: LanguageClient, extensionUri: Uri,
languageClient.info(`[VSCode Client] Received telemetry event from server ${JSON.stringify(e)}`)
})

languageClient.onRequest(openTabRequestType.method, async (params, _) => {
const mapErrorType = (type: string | undefined): number => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it necessary to re-create this function every request?

Copy link
Contributor

Choose a reason for hiding this comment

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

its only an example change so that I can start working on the open tab story

const endTime = Date.now() + 60000 // 1 minute from now
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
while (Date.now() < endTime) {
if (openTabResponseQueue.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are tab requests and responses guaranteed to be in order? Can we index them by requestId instead?

@@ -132,12 +173,30 @@ export function registerChat(languageClient: LanguageClient, extensionUri: Uri,
if (!isValidAuthFollowUpType(message.params.followUp.type))
languageClient.sendNotification(followUpClickNotificationType, message.params)
break
case openTabRequestType.method:
openTabResponseQueue.push(message.params)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we resolve the promise here immediately instead of spinning a loop every 100ms?

default:
if (isServerEvent(message.command)) languageClient.sendNotification(message.command, message.params)
break
}
}, undefined)

async function waitForOpenTabResult(): Promise<UiMessageResultParams | undefined> {
const endTime = Date.now() + 60000 // 1 minute from now
Copy link
Contributor

Choose a reason for hiding this comment

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

Why one minute? How expensive is it to create a tab?

@@ -105,6 +105,17 @@ export const QChatServer =
return chatController.onCodeInsertToCursorPosition(params)
})

chat.onReady(_ => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the expected behavior? To create a new tab on load?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants