forked from qt-creator/qt-creator
AI Assistant: Add automatic suggestions
Change-Id: I5d3297a96a215ed07dfb9d2afa85c9bb081c5cf2 Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -23,6 +23,9 @@ It will try to install it if it is not found.
|
||||
contentsChanged = function(document, position, charsRemoved, charsAdded)
|
||||
require 'init'.Hooks.onDocumentContentsChanged(document, position, charsRemoved, charsAdded)
|
||||
end,
|
||||
currentChanged = function(editor)
|
||||
require 'init'.Hooks.onCurrentChanged(editor)
|
||||
end,
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@@ -8,6 +8,7 @@ local a = require('async')
|
||||
local TextEditor = require('TextEditor')
|
||||
|
||||
Hooks = {}
|
||||
AutoSuggestionDelay = 500
|
||||
|
||||
local function collectSuggestions(responseTable)
|
||||
local suggestions = {}
|
||||
@@ -209,19 +210,24 @@ local function requestSuggestions()
|
||||
sendRequest(request_msg)
|
||||
end
|
||||
|
||||
local function requstSuggestionsSafe()
|
||||
local function requestSuggestionsSafe()
|
||||
local ok, err = pcall(requestSuggestions)
|
||||
if not ok then
|
||||
print("echo Error fetching: " .. err)
|
||||
end
|
||||
end
|
||||
|
||||
function Hooks.onDocumentContentsChanged(document, position, charsRemoved, charsAdded)
|
||||
print("onDocumentcontentsChanged() called, position, charsRemoved, charsAdded:", position, charsRemoved, charsAdded)
|
||||
AutoSuggestionTimer = Utils.Timer.create(AutoSuggestionDelay, true,
|
||||
function() a.sync(requestSuggestionsSafe)() end)
|
||||
|
||||
Position = position
|
||||
local line, char = document:blockAndColumn(position)
|
||||
print("Line: ", line, "Char: ", char)
|
||||
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)
|
||||
@@ -231,7 +237,7 @@ local function setup(parameters)
|
||||
Action = require("Action")
|
||||
Action.create("Trigger.suggestions", {
|
||||
text = "Trigger AI suggestions",
|
||||
onTrigger = function() a.sync(requstSuggestionsSafe)() end,
|
||||
onTrigger = function() a.sync(requestSuggestionsSafe)() end,
|
||||
defaultKeySequences = { "Meta+Shift+A", "Ctrl+Shift+Alt+A" },
|
||||
})
|
||||
end
|
||||
|
Reference in New Issue
Block a user