From d79c9506bf9ded3bb6b28ccfe99c39912e2a8f5f Mon Sep 17 00:00:00 2001 From: Lukasz Papierkowski Date: Wed, 21 Aug 2024 21:15:46 +0200 Subject: [PATCH] AI Assistant: Add initial inline chat widget activation Change-Id: I25e22172960c06a6bc6913ecdb5088a1c8737352 Reviewed-by: Marcus Tillmanns --- .../lua-plugins/ai_asistant/init.lua | 55 ++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/share/qtcreator/lua-plugins/ai_asistant/init.lua b/share/qtcreator/lua-plugins/ai_asistant/init.lua index 634efa6f683..3c0fbeff2ba 100644 --- a/share/qtcreator/lua-plugins/ai_asistant/init.lua +++ b/share/qtcreator/lua-plugins/ai_asistant/init.lua @@ -9,11 +9,13 @@ local TextEditor = require('TextEditor') local mm = require('MessageManager') local fetch = require('Fetch').fetch local Install = require('Install') +local Action = require("Action") Hooks = {} AutoSuggestionDelay = 2000 ServerName = "qtaiassistantserver" ServerReleasesURL = "https://qtaiassistant.gitlab-pages.qt.io/qtails/releases/" .. ServerName .. ".json" +InlineChatActive = false local function collectSuggestions(responseTable) local suggestions = {} @@ -371,6 +373,50 @@ local function requestSuggestions() sendRequest(request_msg) 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 suggestion = TextEditor.currentSuggestion() if suggestion ~= nil then @@ -403,11 +449,16 @@ local function setup(parameters) setupAspect() setupClient() - Action = require("Action") Action.create("Trigger.suggestions", { text = "Trigger AI suggestions", 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