AI Assistant: Add initial inline chat widget activation

Change-Id: I25e22172960c06a6bc6913ecdb5088a1c8737352
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
Lukasz Papierkowski
2024-08-21 21:15:46 +02:00
committed by lie
parent 3e72f59396
commit d79c9506bf

View File

@@ -9,11 +9,13 @@ local TextEditor = require('TextEditor')
local mm = require('MessageManager') local mm = require('MessageManager')
local fetch = require('Fetch').fetch local fetch = require('Fetch').fetch
local Install = require('Install') local Install = require('Install')
local Action = require("Action")
Hooks = {} Hooks = {}
AutoSuggestionDelay = 2000 AutoSuggestionDelay = 2000
ServerName = "qtaiassistantserver" ServerName = "qtaiassistantserver"
ServerReleasesURL = "https://qtaiassistant.gitlab-pages.qt.io/qtails/releases/" .. ServerName .. ".json" ServerReleasesURL = "https://qtaiassistant.gitlab-pages.qt.io/qtails/releases/" .. ServerName .. ".json"
InlineChatActive = false
local function collectSuggestions(responseTable) local function collectSuggestions(responseTable)
local suggestions = {} local suggestions = {}
@@ -371,6 +373,50 @@ local function requestSuggestions()
sendRequest(request_msg) sendRequest(request_msg)
end end
local function activateInlineChat()
print("activateInlineChat() called")
if InlineChatActive == true then
print("Inline chat is already active")
return
end
InlineChatActive = true
local _ENV = using(Gui)
local closeButton = PushButton {
text = "x",
onClicked = function()
ChatWidget:close()
InlineChatActive = false
end
}
local chatInput = S.StringAspect.create({
displayStyle = S.StringDisplayStyle.TextEdit,
placeHolderText = "Search",
macroExpander = Null
})
ChatWidget = Widget {
size = {538, 68},
Column {
Row {
chatInput, closeButton,
},
Label {
text = "Write something and you'll see results here.",
},
}
}
local editor = TextEditor.currentEditor()
local main_cursor = editor:cursor():mainCursor()
local pos = main_cursor:position()
editor:addFloatingWidget(ChatWidget, pos)
end
local function requestSuggestionsSafe() local function requestSuggestionsSafe()
local suggestion = TextEditor.currentSuggestion() local suggestion = TextEditor.currentSuggestion()
if suggestion ~= nil then if suggestion ~= nil then
@@ -403,11 +449,16 @@ local function setup(parameters)
setupAspect() setupAspect()
setupClient() setupClient()
Action = require("Action")
Action.create("Trigger.suggestions", { Action.create("Trigger.suggestions", {
text = "Trigger AI suggestions", text = "Trigger AI suggestions",
onTrigger = function() a.sync(requestSuggestionsSafe)() end, onTrigger = function() a.sync(requestSuggestionsSafe)() end,
defaultKeySequences = { "Meta+Shift+A", "Ctrl+Shift+Alt+A" }, defaultKeySequences = { "Meta+Shift+Alt+A", "Ctrl+Shift+Alt+A" },
})
Action.create("Trigger.inlineChat", {
text = "Trigger AI Inline Chat",
onTrigger = activateInlineChat,
defaultKeySequences = { "Meta+Shift+A", "Ctrl+Shift+A" },
}) })
end end