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

Fix: Open Chat instruction selects range of code in active editor #187

Merged
merged 2 commits into from
Oct 28, 2024

Conversation

alashchev17
Copy link
Contributor

Added logic of lines selection in active editor's tab, if contentMsg is empty (no messages were provided)

@alashchev17 alashchev17 self-assigned this Oct 28, 2024
return contentMsg
.replace("%CURRENT_FILE%", relativePath?.toString() ?: filePath.toString())
.replace("%CURSOR_LINE%", line1.toString())
.replace("%CODE_SELECTION%", text)
}

@OptIn(DelicateCoroutinesApi::class)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting, is DelicateCoroutinesApi OptIn?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there any other way to implement setTimeout functionality? Without that, sometimes chat is not ready yet and file is not getting attached

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OptIn was kindly suggested by IDE when I tried to use GlobalScope.launch :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By the way, changed GlobalScope to CoroutineScope, now we should be fine

Copy link
Collaborator

Choose a reason for hiding this comment

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

Timer().schedule(500) {
    val pos1 = LogicalPosition(line1, 0)
    val pos2 = LogicalPosition(line2, editor.document.getLineEndOffset(line2))

    editor.selectionModel.setSelection(
        editor.logicalPositionToOffset(pos1),
        editor.logicalPositionToOffset(pos2)
    )
}

Might work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is CoroutineScope undesirable?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it should be fine since we use coroutines else where :)

@alashchev17 alashchev17 merged commit 95cb519 into codelens Oct 28, 2024
1 check passed
@alashchev17 alashchev17 deleted the fix/open-chat-selects-code branch October 29, 2024 10:44
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.

2 participants