From 46b6f75b40eb43db22ec4a73d30d8fce8e77e62f Mon Sep 17 00:00:00 2001 From: Mariusz Szczepanik Date: Tue, 3 Sep 2024 13:12:58 +0200 Subject: [PATCH] AiAssistant: Remove LUA plugin Change-Id: I6e48b5bbbbafd6cc33972b514de5c7518b995a37 Reviewed-by: Marcus Tillmanns --- .../lua-plugins/ai_asistant/ai_asistant.lua | 129 ----- .../images/inlinechat_close_lua.png | Bin 355 -> 0 bytes .../images/inlinechat_close_lua@2x.png | Bin 605 -> 0 bytes .../images/inlinechat_settings_lua.png | Bin 405 -> 0 bytes .../images/inlinechat_settings_lua@2x.png | Bin 656 -> 0 bytes .../images/settingscategory_ai_assistant.png | Bin 251 -> 0 bytes .../lua-plugins/ai_asistant/init.lua | 459 ------------------ 7 files changed, 588 deletions(-) delete mode 100644 share/qtcreator/lua-plugins/ai_asistant/ai_asistant.lua delete mode 100644 share/qtcreator/lua-plugins/ai_asistant/images/inlinechat_close_lua.png delete mode 100644 share/qtcreator/lua-plugins/ai_asistant/images/inlinechat_close_lua@2x.png delete mode 100644 share/qtcreator/lua-plugins/ai_asistant/images/inlinechat_settings_lua.png delete mode 100644 share/qtcreator/lua-plugins/ai_asistant/images/inlinechat_settings_lua@2x.png delete mode 100644 share/qtcreator/lua-plugins/ai_asistant/images/settingscategory_ai_assistant.png delete mode 100644 share/qtcreator/lua-plugins/ai_asistant/init.lua diff --git a/share/qtcreator/lua-plugins/ai_asistant/ai_asistant.lua b/share/qtcreator/lua-plugins/ai_asistant/ai_asistant.lua deleted file mode 100644 index 1ff9a885d57..00000000000 --- a/share/qtcreator/lua-plugins/ai_asistant/ai_asistant.lua +++ /dev/null @@ -1,129 +0,0 @@ --- Copyright (C) 2024 The Qt Company Ltd. --- SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 -return { - Id = "aiassistant", - Name = "Qt AI Assistant", - Version = "1.0.0", - CompatVersion = "1.0.0", - VendorId = "theqtcompany", - Vendor = "The Qt Company", - Category = "Language Client", - Description = "Qt AI Assistant", - Experimental = true, - DisabledByDefault = true, - LongDescription = [[ -Qt AI Assistant is a coding assistant. When connected to a Large Language -Model (LLM), it auto-completes your code, as well as writes test cases and -code documentation. - -Qt AI Assistant is available for selected commercial Qt developer -license holders. For more information on licensing, select `Compare` -in [Qt pricing](https://www.qt.io/pricing). - -> **Note:** Qt AI Assistant is LLM-agnostic. The subscription to a third-party -LLM service or a third-party LLM for local or cloud deployment is not a part -of it. You need to connect to a third-party LLM and agree to the terms and -conditions, as well as to the acceptable use policy of the LLM provider. By -using Qt AI Assistant, you agree to -[Terms & Conditions - Qt Development Framework](https://www.qt.io/terms-conditions/qt-dev-framework). - -Qt AI Assistant is currently experimental and powered by generative AI. Check -all suggestions to make sure that they are fit for use in your project. - -> **Note:** [Install and load](https://doc.qt.io/qtcreator/creator-how-to-load-extensions.html) -the Qt AI Assistant extension to use it. - -## Connect to a LLM - -You can connect to the following LLMs: -- Meta Llama 3.1 70B (running in a cloud deployment of your choice -- Anthropic Claude 3.5 Sonnet (provided as subscription-based service by Anthropic) - -To connect to a LLM: - -1. Go to `Preferences` > `AI Assistant` -1. Select the use cases and programming languages to use the LLM for -1. Enter the authentication token, user name, and API URL of the LLM. - For more information on where to get the access information, see the - third-party LLM provider documentation. - -## Automatic code-completion - -Qt AI Assistant can help you write code by suggesting what to write next. -It prompts the LLM to make one or several code suggestions based on the -current cursor position and the code before and after the cursor when you -stop typing. The code suggestions are shown after the cursor in grey color. - -To accept the entire suggestion, press the `Tab` key. - -To accept parts of the suggestions, press `Alt+Right`. - -To dismiss the suggestion, press `Esc` or navigate to another position in -the code editor. - -To interact with Qt AI Assistant using the mouse, hover over the suggestion. - -When you hover over a suggestion, you can accept parts of the suggested code -snippet word-by-word. Or, cycle through alternative suggestions in the code -completion bar by selecting the `<` and `>` buttons. - -To close the code completion bar, press `Esc` key or move the cursor to -another position. - -To turn auto-completion of code on or off globally for all projects, go to -`Preferences` > `AI Assistant`. Qt AI Assistant consumes a significant number -of tokens from the LLM. To cut costs, disable the auto-completion feature when -not needed, and use keyboard shortcuts for code completion. - -## Complete code from the keyboard - -To trigger code suggestions manually, press `Ctrl+Shift+A` (`Cmd+Shift+A` on macOS). - -## Chat with the assistant - -In an inline chat window in the code editor, you can prompt the assistant to -implement your requests in human language, ask questions, or execute -*smart commands*. To open the chat, press `Ctrl+Shift+D` (`Cmd+Shift+D` on macOS). - -To close the chat, press `Esc` or select the `Close` button. - -To go to Qt AI Assistant preferences from the chat, select the `Settings` button. - -### Request suggestions using human language - -To request suggestions using human language, type your requests in the chat. -Qt AI Assistant shows a suggestion that you can copy to the clipboard by -selecting the `Copy` button in the chat. - -### Request test cases in Qt Test syntax - -To write test cases with Qt AI Assistant: - -- Highlight code in the code editor -- Press `Ctrl+Shift+D` (`Cmd+Shift+D` on macOS) to open the chat -- Select the `qtest` smart command. - -Qt AI Assistant generates a test case in [Qt Test](https://doc.qt.io/qt-6/qttest-index.html) -format that you can copy and paste to your -[Qt test project](https://doc.qt.io/qtcreator/creator-how-to-create-qt-tests.html). - ]], - Dependencies = { - { Id = "lua", Version = "14.0.0" }, - { Id = "lualanguageclient", Version = "14.0.0" } - }, - hooks = { - editors = { - text = { - contentsChanged = function(document, position, charsRemoved, charsAdded) - require 'init'.Hooks.onDocumentContentsChanged(document, position, charsRemoved, charsAdded) - end, - currentChanged = function(editor) - require 'init'.Hooks.onCurrentChanged(editor) - end, - } - } - }, - setup = function() - require 'init'.setup() - end, -} --[[@as QtcPlugin]] diff --git a/share/qtcreator/lua-plugins/ai_asistant/images/inlinechat_close_lua.png b/share/qtcreator/lua-plugins/ai_asistant/images/inlinechat_close_lua.png deleted file mode 100644 index 15527d838ab7b42d2d0c029985873c6219ea6a32..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 355 zcmeAS@N?(olHy`uVBq!ia0y~yV2}V|4rT@hhU+WOo?>8Na1HPYab;j&m_L91dN5eE zYSsGn>({JVvu@qGwQJX|U%wuWgm59U>yW_DfZc8k3=Co=L4Lsu0s;yK1_AL2`33b2 z{S(%&-?0Du{r4yM#TPL!Fl_g9aSYLzICtXNq9Y1C&HIn3GJaE!PI~=Uerx*#-xogm zt0%jgP1AW0?2}rW89m+pkIbtN3%^c?GW58)^!Ca7B41ZzzbL#CIq}>|ky+I*SH%Q~ z#{X?(UMd-}+TnHcYOw_;&&Kes_{EqI%yj0dp80_%3?3WG%l@7HbGzW?4z0}Bk4i<( z$L@I-=C^yD?Rw2)%--g#n;%toJdyqIStyC~?)jCwpLjEA`&Pw$PqVkvN^^U1UG3*; dpPH_C%e%Y`S^De#FfcGMc)I$ztaD0e0su>pr}h8< diff --git a/share/qtcreator/lua-plugins/ai_asistant/images/inlinechat_close_lua@2x.png b/share/qtcreator/lua-plugins/ai_asistant/images/inlinechat_close_lua@2x.png deleted file mode 100644 index bb5f1328201498e6f082f1ca919387670446730b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 605 zcmeAS@N?(olHy`uVBq!ia0y~yU@!n-4rT@hhJ-tuTNxM_!UKFlTp1V`=FgwM9tKvg zUcG+(`Za6TtXsEkzK8tVquuqI zOIuSbc;)-IdzpL@UMpB^^B~YKJ@UM?#tjj*oLAll9osJ-uc_t%wfXJq%b8H zJ+YS78_5qPf;AHiqI@2|+`fu6-ORsBv`OjNy}FZ3Gk(;D-z{Ht<(l#QDJ*>d=Bt1E zxY=Jr{*YP?cU}7S$}fqNlEQ7fO?DeaHWh#1sJPx(EOav5OS$aGN74G`-Srt-Qg@u& zKQ3WRRXp-&QK#*^fFrl0%Zr;nNUD`bd@kSfYQoYh`I;Z2yx1nb6VB}O$PNi>{Ak{2 zTM+4fVMpHM-BmFMw|Lq}i5p05&tEIDfHURnvSX)1{2SdbHO%t-pdYe3x7@2~lSWf_ zSxF;XzPosl)&50Xt7q5>H{P+Bck+y1!t!Lr+27ih>P%g|==CIt*L!zdP85CIDt6L$ z_MOif-?dKt4bhGl`JQvLnQdcb|NIvZwU4KX9QCUDH(}eSwSPBf-*fh^EBec9-|q1K TlX561*)Vvz`njxgN@xNAwkjU7 diff --git a/share/qtcreator/lua-plugins/ai_asistant/images/inlinechat_settings_lua.png b/share/qtcreator/lua-plugins/ai_asistant/images/inlinechat_settings_lua.png deleted file mode 100644 index 26b8af6dbbe6043066dc094b8e6a746204ee1d03..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 405 zcmeAS@N?(olHy`uVBq!ia0y~yV2}V|4rT@hhU+WOo?>8Nhzjrtab;j&m_L91dN5eE zYSsGn>sPN{y?*`rHEY(aU%!6cx^-*Uu3f)=JsJt&u357Nt^mSVhXj7ks`6l9V2~{d z@(X4V5Ku5MaBv6+h)>8bsBh?>Fn|7n1?$&u*nj^1``Z_fu`w_(ob_~Z43UsrdhlV; zAp?Qdi|ZqqxNb2eWpAp!|KHU2R$^OYeHGvT4}w8Gdpx3eZK|g?YkyXlUS;DQzro}A z#nl@NO$}8&?!TIIRl|Pj(TJOy-oy&Wp2%3!lD7D!_KTQ(%-p7l6Jq_Q$1-ltJDI2T zVAafCmPw954M*m(EM)Xy>hvwM6p7W1{mQI(|Kd)Y=GIvTC)Rn1TV1%ZNW-mo!e!r8 z?K>s3XP>@kdQmmJTuz~P;jx=fUR`$Gb-;JmoGe4R6w4j=DyD6bsxWL7ng8dmeolk% WFNf(bxEUB27(8A5T-G@yGywo*0KRJg diff --git a/share/qtcreator/lua-plugins/ai_asistant/images/inlinechat_settings_lua@2x.png b/share/qtcreator/lua-plugins/ai_asistant/images/inlinechat_settings_lua@2x.png deleted file mode 100644 index 9217e8dfdf56c6a70631d58b778d189c14bf5f03..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 656 zcmeAS@N?(olHy`uVBq!ia0y~yU@!n-4rT@hhJ-tuTNxM_q5^zETp1V`=FgwM9t>8k zTD5-t`qisfuV24@-MV#a)~s2#Zr$3oYuB$|k48ec$O<4T*C7FBjR`3X3=Fa*L4Lsu z0s;yK1`ZDX0r3g>1@#U66XwrfuwecA4g1gEe}6|I`UnF9;|Wg}#}JR>cc+SvT#A0nfhw*?q>2ufz4qLi4;7IZw(9rM$5{z9QUy+IzE~r)M4C={het&>*(i zY5$~;H&-mUd&Jdf&ouFH?eDMC%B^>HKMr^w#d$3KedlrIza{TxFsv;as>_x=CLT{|vs=?ONS4i#4R{ zUF003Jw506H$CxR=N2_tO-awh&dhYf%HDmuYN{qz6mDLg5Gozf*|V_Whv&g{g1ijV z&TD?3RMf($Y88IKIk)9i=oNP7Sqz3I6Vw_){U=XR-Ir&)aiV1Bk|~R9+P1`QKj<6P z?BS7ma)GOM-mk(x+dAB{j`g(&{lEY2HTzQ6#^58q{f~BPnAj~2-m`vJ{pI&v_RpsJ W+nijcrpmy;z~JfX=d#Wzp$Pyd^f~PS diff --git a/share/qtcreator/lua-plugins/ai_asistant/images/settingscategory_ai_assistant.png b/share/qtcreator/lua-plugins/ai_asistant/images/settingscategory_ai_assistant.png deleted file mode 100644 index 9a47fb241351b4566a0fdf77b425396a31a6f94d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 251 zcmeAS@N?(olHy`uVBq!ia0y~yV2}V|4h9AWhNCh`Dhvz^hdf;zLp07O|LA8n2#9}l zz0XJAIr#jRv-Sb1d@BtZ7}*81-#AUPIIwQ|~;R$P!9-Lqc z+MRm;kZM{=;|Wvl@Uv_eMPmy(8~8SC*~U3z-aC%z1|OJ(_OCr8^u-~sE3n1e!_e&B zt(U7leQjNLciQdPGjj?!73;0l&TTNS|6kMdIBg3@x{Jq|AOFA0ANl$J-=FwSrAC&H zNfF&T8~GI#3*{ppsp`ip;x|1~{Xi%_Ky}{*jVwb3hRCQ7zQVi9_&~n$boFyt=akR{ E0EdNUS^xk5 diff --git a/share/qtcreator/lua-plugins/ai_asistant/init.lua b/share/qtcreator/lua-plugins/ai_asistant/init.lua deleted file mode 100644 index 6f3f6377d3d..00000000000 --- a/share/qtcreator/lua-plugins/ai_asistant/init.lua +++ /dev/null @@ -1,459 +0,0 @@ --- Copyright (C) 2024 The Qt Company Ltd. --- SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 -local LSP = require('LSP') -local Utils = require('Utils') -local S = require('Settings') -local Gui = require('Gui') -local a = require('async') -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" -InlineChatActive = false - -local function collectSuggestions(responseTable) - local suggestions = {} - - if type(responseTable.result) == "table" and type(responseTable.result.completions) == "table" then - for _, completion in pairs(responseTable.result.completions) do - if type(completion) == "table" then - local text = completion.text or "" - local startLine = completion.range and completion.range.start and completion.range.start.line or 0 - local startCharacter = completion.range and completion.range.start and completion.range.start.character or 0 - local endLine = completion.range and completion.range["end"] and completion.range["end"].line or 0 - local endCharacter = completion.range and completion.range["end"] and completion.range["end"].character or 0 - - local suggestion = TextEditor.Suggestion.create(startLine, startCharacter, endLine, endCharacter, text) - table.insert(suggestions, suggestion) - end - end - end - - return suggestions -end - -local function createCommand() - local cmd = { Settings.binary.expandedValue:nativePath() } - return cmd -end - -local function createInitOptions() - local llm_config = { - cppLLM = Settings.cppLLM.dataValue, - qmlLLM = Settings.qmlLLM.dataValue, - otherLLM = Settings.otherLLM.dataValue, - debugLLM = Settings.debugLLM.dataValue, - reviewLLM = Settings.reviewLLM.dataValue, - explainLLM = Settings.explainLLM.dataValue - } - - local auth_token_config = { - authTokenLama35 = Settings.authTokenLlama3.value, - authTokenClaude35 = Settings.authTokenClaude35.value - } - - return { - llm_config = llm_config, - auth_token_config = auth_token_config - } -end - -local function installOrUpdateServer() - local data = a.wait(fetch({ - url = "https://qtccache.qt.io/QtAIAssistant/LatestRelease", - convertToTable = true - })) - - if not data then - print("Failed to fetch release data.") - return - end - - local id = string.format("%.0f", data["id"]) - print("Found version:", id) - - local lspPkgInfo = Install.packageInfo(ServerName) - if not lspPkgInfo or lspPkgInfo.version ~= id then - local osTr = { mac = "macos", windows = "windows", linux = "ubuntu" } - local os = osTr[Utils.HostOsInfo.os] - - print("Attempt to download server for: ", Utils.HostOsInfo.os) - - local expectedFileName = "project-build-" .. os - local asset = nil - for _, a in ipairs(data["assets"]) do - if string.find(a.name, expectedFileName, 1, true) then - asset = a - break - end - end - - if not asset then - print("No assets found for this platform. Expected file base name:", expectedFileName) - return - end - - local assetId = string.format("%.0f", asset["id"]) - local downloadUrl = "https://qtccache.qt.io/QtAIAssistant/Asset?assetId=" .. assetId - print("Using download URL:", downloadUrl) - - local res, err = a.wait(Install.install( - "Do you want to install the " .. ServerName .. "?", { - name = ServerName, - url = downloadUrl, - version = id - })) - - if not res then - mm.writeFlashing("Failed to install " .. ServerName .. ": " .. err .. ". Please make sure you have 7z installed for package extraction.") - return - end - - lspPkgInfo = Install.packageInfo(ServerName) - print("Installed:", lspPkgInfo.name, " version:", lspPkgInfo.version, " at:", lspPkgInfo.path) - end - - local binary = ServerName - if Utils.HostOsInfo.isWindowsHost() then - binary = binary .. ".exe" - end - - Settings.binary:setValue(lspPkgInfo.path:resolvePath(binary)) - Settings:apply() -end - -IsTryingToInstall = false - -local function setupClient() - Client = LSP.Client.create({ - name = 'AI Assistant Server', - cmd = createCommand, - transport = 'stdio', - initializationOptions = createInitOptions, - languageFilter = { - patterns = { '*.*' }, - }, - settings = Settings, - startBehavior = "AlwaysOn", - showInSettings = false, - onStartFailed = function() - a.sync(function() - if IsTryingToInstall == true then - return - end - IsTryingToInstall = true - installOrUpdateServer() - IsTryingToInstall = false - end)() - end - }) -end - -local function using(tbl) - local result = _G - for k, v in pairs(tbl) do result[k] = v end - return result -end - -local function layoutSettings() - local _ENV = using(Gui) - - local layout = Form { - Settings.binary, br, - Row { - PushButton { - text = "Try to install AI Assistant Server", - onClicked = function() a.sync(installOrUpdateServer)() end, - br, - }, - st - }, - br, - Settings.cppLLM, br, - Settings.qmlLLM, br, - Settings.otherLLM, br, - Settings.debugLLM, br, - Settings.reviewLLM, br, - Settings.explainLLM, br, - Settings.authTokenLlama3, br, - Settings.authTokenClaude35 - } - - return layout -end - -local available_llms = { - { name = "Llama 3 70B Fine-Tuned", data = "Llama3" }, - { name = "Claude 3.5 Sonnet", data = "Claude35" } -} - -local function createSelectionAspect(settingsKey, displayName) - return S.SelectionAspect.create({ - settingsKey = settingsKey, - options = available_llms, - displayStyle = S.SelectionDisplayStyle.ComboBox, - displayName = displayName - }) -end - -local function addLLMSetting(keySuffix, displayText) - Settings[keySuffix] = createSelectionAspect("AIAssistant." .. keySuffix, displayText) -end - -local function addAuthTokenSetting(llm_name, displayText) - Settings["authToken" .. llm_name] = S.StringAspect.create({ - settingsKey = "AIAssistant.AuthToken." .. llm_name, - labelText = displayText .. ":", - displayStyle = S.StringDisplayStyle.LineEdit, - defaultValue = "AUTH_TOKEN", - }) -end - -local function setupAspect() - Settings = S.AspectContainer.create({ - autoApply = false, - layouter = layoutSettings, - }) - - Settings.binary = S.FilePathAspect.create({ - settingsKey = "AIAssistant.Binary", - displayName = "Binary", - labelText = "Binary:", - toolTip = "The path to the AI Assistant Server", - expectedKind = S.Kind.ExistingCommand, - defaultPath = Utils.FilePath.fromUserInput("/path/to/server"), - }) - - addLLMSetting("cppLLM", "LLM for C++:") - addLLMSetting("qmlLLM", "LLM for QML:") - addLLMSetting("otherLLM", "LLM for other languages:") - addLLMSetting("debugLLM", "LLM for debug:") - addLLMSetting("reviewLLM", "LLM for review") - addLLMSetting("explainLLM", "LLM for explain:") - - addAuthTokenSetting("Llama3", "Llama 3 API authentication Token") - addAuthTokenSetting("Claude35", "Claude 3.5 API authentication Token") - - Options = S.OptionsPage.create({ - aspectContainer = Settings, - categoryId = "AIAssistant.OptionsPage", - displayName = tr("AI Assistant"), - id = "AIAssistant.Settings", - displayCategory = "AI Assistant", - categoryIconPath = PluginSpec.pluginDirectory:resolvePath("images/settingscategory_ai_assistant.png") - }) - - return Settings -end - -local function buildRequest() - local editor = TextEditor.currentEditor() - if editor == nil then - print("No editor found") - return - end - - local document = editor:document() - local filePath = document:file() - local ok, doc_version = Client:documentVersion(filePath) - if not ok then - print("No document version found:", doc_version) - return - end - - local ok, doc_uri = Client:hostPathToServerUri(filePath) - if not ok then - print("No document uri found", doc_uri) - return - end - - local main_cursor = editor:cursor():mainCursor() - local block = main_cursor:blockNumber() - local column = main_cursor:columnNumber() - - local request_msg = { - jsonrpc = "2.0", - method = "getCompletionsCycling", - params = { - doc = { - position = { - character = column, - line = block - }, - uri = doc_uri, - version = doc_version - } - } - } - - return request_msg -end - -local function completionResponseCallback(response) - print("completionResponseCallback() called") - - local editor = TextEditor.currentEditor() - if editor == nil then - print("No editor found") - return - end - - local suggestions = collectSuggestions(response) - if next(suggestions) == nil then - print("No suggestions found") - return - end - - local document = editor:document() - document:setSuggestions(suggestions) -end - -local function sendRequest(request) - print("sendRequest() called") - - if Client == nil then - print("No client found") - return - end - - local editor = TextEditor.currentEditor() - if editor == nil or editor == "" then - print("No editor found") - return - end - - local document = editor:document() - local result = a.wait(Client:sendMessageWithIdForDocument(document, request)) - completionResponseCallback(result) - -end - -local function requestSuggestions() - local main_cursor = TextEditor.currentEditor():cursor():mainCursor() - if main_cursor == nil then - print("No cursor found") - return - end - - if(main_cursor:hasSelection()) then - print("Ignoring requestSuggestions() due to cursor selection") - return - end - - local request_msg = buildRequest() - if(request_msg == nil) then - print("requestSuggestions() failed to build request message") - return - end - - 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 { - iconPath = PluginSpec.pluginDirectory:resolvePath("images/inlinechat_close_lua.png"), - flat = true, - onClicked = function() - ChatWidget:close() - InlineChatActive = false - end - } - - local settingsButton = PushButton { - iconPath = PluginSpec.pluginDirectory:resolvePath("images/inlinechat_settings_lua.png"), - flat = true, - onClicked = function() - Options:show() - end - } - - local chatInput = S.StringAspect.create({ - displayStyle = S.StringDisplayStyle.TextEdit, - placeHolderText = "Search", - macroExpander = Null - }) - - ChatWidget = Widget { - size = {538, 68}, - autoFillBackground = true, - Column { - Row { - chatInput, settingsButton, 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 - if suggestion:isLocked() then - print("Ignoring suggestion due to locked suggestion") - return - end - end - - local ok, err = pcall(requestSuggestions) - if not ok then - print("echo Error fetching: " .. err) - end -end - -AutoSuggestionTimer = Utils.Timer.create(AutoSuggestionDelay, true, - function() a.sync(requestSuggestionsSafe)() end) - -function Hooks.onDocumentContentsChanged(document, position, charsRemoved, charsAdded) - print("onDocumentContentsChanged() called, position, charsRemoved, charsAdded:", position, charsRemoved, charsAdded) - AutoSuggestionTimer:start() -end - -function Hooks.onCurrentChanged(editor) - print("onCurrentChanged() called") - AutoSuggestionTimer:stop() -end - -local function setup(parameters) - setupAspect() - setupClient() - - Action.create("Trigger.suggestions", { - text = "Trigger AI suggestions", - onTrigger = function() a.sync(requestSuggestionsSafe)() end, - 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 - -return { - setup = function() a.sync(setup)() end, - Hooks = Hooks, -}