feat/preview #3
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "fabelous-autocoder",
|
"name": "fabelous-autocoder",
|
||||||
"version": "0.2.74",
|
"version": "0.2.0",
|
||||||
"displayName": "Fabelous Autocoder",
|
"displayName": "Fabelous Autocoder",
|
||||||
"description": "A simple to use Ollama autocompletion Plugin",
|
"description": "A simple to use Ollama autocompletion Plugin",
|
||||||
"icon": "icon.png",
|
"icon": "icon.png",
|
||||||
|
@ -111,9 +111,8 @@
|
||||||
"commands": [
|
"commands": [
|
||||||
{
|
{
|
||||||
"command": "fabelous-autocoder.autocomplete",
|
"command": "fabelous-autocoder.autocomplete",
|
||||||
"title": "Fabelous autocompletion"
|
"title": "Fabelous Autocompletion"
|
||||||
}
|
}]
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"vscode:prepublish": "npm run compile",
|
"vscode:prepublish": "npm run compile",
|
||||||
|
|
|
@ -61,7 +61,6 @@ const previewDecorationType = vscode.window.createTextEditorDecorationType({
|
||||||
textDecoration: 'none; display: none;', // Hide the original text
|
textDecoration: 'none; display: none;', // Hide the original text
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationToken?: vscode.CancellationToken) {
|
async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationToken?: vscode.CancellationToken) {
|
||||||
const document = textEditor.document;
|
const document = textEditor.document;
|
||||||
const position = textEditor.selection.active;
|
const position = textEditor.selection.active;
|
||||||
|
@ -117,8 +116,6 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo
|
||||||
let previewInserted = false;
|
let previewInserted = false;
|
||||||
let originalContent: string;
|
let originalContent: string;
|
||||||
let previewStartLine: number;
|
let previewStartLine: number;
|
||||||
|
|
||||||
// Store the original content and insert preview
|
|
||||||
const storeAndInsertPreview = async () => {
|
const storeAndInsertPreview = async () => {
|
||||||
previewStartLine = startLine;
|
previewStartLine = startLine;
|
||||||
const endLine = document.lineCount - 1;
|
const endLine = document.lineCount - 1;
|
||||||
|
@ -128,20 +125,27 @@ const storeAndInsertPreview = async () => {
|
||||||
|
|
||||||
const previewContent = completionText + '\n'.repeat(1);
|
const previewContent = completionText + '\n'.repeat(1);
|
||||||
const edit = new vscode.WorkspaceEdit();
|
const edit = new vscode.WorkspaceEdit();
|
||||||
edit.replace(document.uri, fullRange, previewContent); // Overwrite the context
|
edit.replace(document.uri, fullRange, previewContent); // Overwrite the content
|
||||||
await vscode.workspace.applyEdit(edit);
|
await vscode.workspace.applyEdit(edit);
|
||||||
|
|
||||||
// Move the cursor to the end of the inserted content
|
// Split the preview content into lines
|
||||||
const previewLines = previewContent.split('\n');
|
const previewLines = previewContent.split('\n');
|
||||||
|
|
||||||
|
// Calculate the exact position of the last character of the preview content
|
||||||
const lastPreviewLineIndex = previewStartLine + previewLines.length - 1;
|
const lastPreviewLineIndex = previewStartLine + previewLines.length - 1;
|
||||||
const lastPreviewLine = previewLines[previewLines.length - 1];
|
const lastPreviewLine = previewLines[previewLines.length - 2]; // Second to last line (last line is newline)
|
||||||
const newPosition = new vscode.Position(lastPreviewLineIndex, lastPreviewLine.length);
|
const newPosition = new vscode.Position(lastPreviewLineIndex - 1, lastPreviewLine.length); // Place cursor at end of last line
|
||||||
|
|
||||||
|
// Set the new cursor position after inserting preview
|
||||||
textEditor.selection = new vscode.Selection(newPosition, newPosition);
|
textEditor.selection = new vscode.Selection(newPosition, newPosition);
|
||||||
|
|
||||||
|
// Explicitly scroll to reveal the cursor position at the end of the preview
|
||||||
|
textEditor.revealRange(new vscode.Range(newPosition, newPosition), vscode.TextEditorRevealType.InCenter);
|
||||||
|
|
||||||
// Set decorations on the newly inserted lines
|
// Set decorations on the newly inserted lines
|
||||||
const previewRanges: vscode.DecorationOptions[] = [];
|
const previewRanges: vscode.DecorationOptions[] = [];
|
||||||
for (let i = 0; i < previewLines.length; i++) {
|
for (let i = 0; i < previewLines.length; i++) {
|
||||||
const range = new vscode.Range(previewStartLine + i, 0, previewStartLine + i + 1, 0);
|
const range = new vscode.Range(previewStartLine + i, 0, previewStartLine + i, previewLines[i].length);
|
||||||
previewRanges.push({
|
previewRanges.push({
|
||||||
range,
|
range,
|
||||||
renderOptions: {
|
renderOptions: {
|
||||||
|
@ -156,26 +160,30 @@ const storeAndInsertPreview = async () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const disposable = vscode.workspace.onDidChangeTextDocument(async (event) => {
|
const disposable = vscode.workspace.onDidChangeTextDocument(async (event) => {
|
||||||
if (event.document.uri.toString() === document.uri.toString() && previewInserted) {
|
const textEditor = vscode.window.activeTextEditor;
|
||||||
console.log("URI matches and preview inserted");
|
if (!textEditor || event.document.uri.toString() !== textEditor.document.uri.toString() || !previewInserted) {
|
||||||
if (event.contentChanges.length > 0) {
|
return;
|
||||||
const change = event.contentChanges[0];
|
|
||||||
console.log("Change:", change);
|
|
||||||
|
|
||||||
// Accept preview with Tab key
|
|
||||||
if (change && change.text === '\t' && previewInserted) {
|
|
||||||
console.log("Tab key pressed, accepting preview");
|
|
||||||
await acceptPreview(textEditor, document, startLine, position, completionText);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep the existing backspace functionality
|
// Determine tab size setting
|
||||||
if (change.text === '' && change.range.start.line >= previewStartLine) {
|
const tabSize = textEditor.options.tabSize as number || 4;
|
||||||
console.log("Backspace detected");
|
|
||||||
|
for (const change of event.contentChanges) {
|
||||||
|
const changeStartLine = change.range.start.line;
|
||||||
|
|
||||||
|
// Detect Backspace by a single-character deletion
|
||||||
|
if (change.text === '' && change.rangeLength === 1 && changeStartLine >= previewStartLine) {
|
||||||
await restoreOriginalContent();
|
await restoreOriginalContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Detect Tab by checking if the change is a multiple of spaces equal to the tab size
|
||||||
|
if (/^[ ]+$/.test(change.text) && change.text.length === tabSize && changeStartLine >= previewStartLine) {
|
||||||
|
await acceptPreview(textEditor, document, startLine, position, completionText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const restoreOriginalContent = async () => {
|
const restoreOriginalContent = async () => {
|
||||||
if (!previewInserted) return;
|
if (!previewInserted) return;
|
||||||
|
|
||||||
|
@ -197,8 +205,6 @@ const storeAndInsertPreview = async () => {
|
||||||
textEditor.selection = new vscode.Selection(newPosition, newPosition);
|
textEditor.selection = new vscode.Selection(newPosition, newPosition);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Modify the acceptPreview function to match the working version
|
// Modify the acceptPreview function to match the working version
|
||||||
const acceptPreview = async (textEditor: vscode.TextEditor, document: vscode.TextDocument, startLine: number, position: vscode.Position, completionText: string) => {
|
const acceptPreview = async (textEditor: vscode.TextEditor, document: vscode.TextDocument, startLine: number, position: vscode.Position, completionText: string) => {
|
||||||
console.log("Accepting preview");
|
console.log("Accepting preview");
|
||||||
|
@ -225,7 +231,6 @@ const storeAndInsertPreview = async () => {
|
||||||
console.log("Preview accepted");
|
console.log("Preview accepted");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Call this function to initiate the preview
|
// Call this function to initiate the preview
|
||||||
await storeAndInsertPreview();
|
await storeAndInsertPreview();
|
||||||
|
|
||||||
|
@ -240,6 +245,7 @@ const storeAndInsertPreview = async () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, cancellationToken: vscode.CancellationToken) {
|
async function provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, cancellationToken: vscode.CancellationToken) {
|
||||||
const item = new vscode.CompletionItem("Fabelous autocompletion");
|
const item = new vscode.CompletionItem("Fabelous autocompletion");
|
||||||
item.insertText = new vscode.SnippetString('${1:}');
|
item.insertText = new vscode.SnippetString('${1:}');
|
||||||
|
|
|
@ -0,0 +1,175 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def quicksort(arr):
|
||||||
|
if len(arr) <= 1:
|
||||||
|
return arr
|
||||||
|
else:
|
||||||
|
pivot = arr[len(arr)//2] # choose the middle element as the pivot
|
||||||
|
left_partition = [i for i in arr if i < pivot]
|
||||||
|
right_partition = [i for i in arr if i > pivot]
|
||||||
|
|
||||||
|
return quicksort(left_partition) + [pivot] + quicksort(right_partition)
|
||||||
|
|
||||||
|
|
||||||
|
def quicksort(arr):
|
||||||
|
if len(arr) <= 1:
|
||||||
|
return arr
|
||||||
|
mid = int(len(arr)/2)
|
||||||
|
left = [item for i, item in enumerate(arr) if i<mid]
|
||||||
|
right = [item for i, item in enumerate(arr) if i>=mid]
|
||||||
|
|
||||||
|
return quicksort(left)+[arr[mid]]+quicksort(right)
|
||||||
|
def is_fibunccai(num):
|
||||||
|
num = str(num)
|
||||||
|
size = len(num)
|
||||||
|
|
||||||
|
# Create 1s array for DP table to store last 10 digits of Fibonacci sequence
|
||||||
|
fib = [1] * 10
|
||||||
|
|
||||||
|
# Initialize last two numbers in Fibonacci sequence as 1 and 2
|
||||||
|
def binary_search(arr, num) :
|
||||||
|
left = 0; right = len(arr) - 1
|
||||||
|
|
||||||
|
while (left <= right) :
|
||||||
|
mid = int((right + left) / 2)
|
||||||
|
|
||||||
|
if arr[mid] == num :
|
||||||
|
return mid
|
||||||
|
|
||||||
|
elif arr[mid] > num :
|
||||||
|
right = mid - 1
|
||||||
|
|
||||||
|
else:
|
||||||
|
left = mid + 1
|
||||||
|
|
||||||
|
return -1
|
||||||
|
|
||||||
|
arr = [2, 4, 5, 7, 8, 9, 10, 11, 12]
|
||||||
|
num = 9
|
||||||
|
index = binary_search(arr, num)
|
||||||
|
|
||||||
|
if index!= -1:
|
||||||
|
print("Element is present at ", index)
|
||||||
|
else:
|
||||||
|
print("Element is not present in array")
|
||||||
|
|
||||||
|
def quicksort(arr):
|
||||||
|
if len(arr) <= 1:
|
||||||
|
return arr
|
||||||
|
|
||||||
|
pivot = arr[len(arr)//2]
|
||||||
|
left_partition, right_partition = [], []
|
||||||
|
|
||||||
|
for i in range(len(arr)):
|
||||||
|
if arr[i] < pivot:
|
||||||
|
left_partition.append(arr[i])
|
||||||
|
else:
|
||||||
|
right_partition.append(arr[i])
|
||||||
|
|
||||||
|
return quicksort(left_partition) + [pivot] + quicksort(right_partition)
|
||||||
|
|
||||||
|
def merge_sort(arr):
|
||||||
|
if len(arr) > 1:
|
||||||
|
mid = len(arr) // 2
|
||||||
|
left_half = arr[:mid]
|
||||||
|
right_half = arr[mid:]
|
||||||
|
|
||||||
|
# Recursive call for sorting the two halves
|
||||||
|
merge_sort(left_half)
|
||||||
|
merge_sort(right_half)
|
||||||
|
|
||||||
|
i = j = k = 0
|
||||||
|
|
||||||
|
while i < len(left_half) and j < len(right_half):
|
||||||
|
if left_half[i] < right_half[j]:
|
||||||
|
arr[k] = left_half[i]
|
||||||
|
i += 1
|
||||||
|
else:
|
||||||
|
arr[k] = right_half[j]
|
||||||
|
j += 1
|
||||||
|
k += 1
|
||||||
|
|
||||||
|
# Checking if any element was left
|
||||||
|
while i < len(left_half):
|
||||||
|
arr[k] = left_half[i]
|
||||||
|
i += 1
|
||||||
|
k += 1
|
||||||
|
|
||||||
|
while j < len(right_half):
|
||||||
|
arr[k] = right_half[j]
|
||||||
|
j += 1
|
||||||
|
k += 1
|
||||||
|
# Driver code to test above
|
||||||
|
arr = [24, 32, 10, 67, 55, 38, 19]
|
||||||
|
print(arr)
|
||||||
|
merge_sort(arr)
|
||||||
|
|
||||||
|
print("Sorted array is:")
|
||||||
|
print(arr)
|
||||||
|
r) // 2
|
||||||
|
left_half = arr[:mid]
|
||||||
|
right_half = arr[mid:]
|
||||||
|
|
||||||
|
# Recursive call for sorting the two halves
|
||||||
|
merge_sort(left_half)
|
||||||
|
merge_sort(right_half)
|
||||||
|
|
||||||
|
i = j = k = 0
|
||||||
|
|
||||||
|
while i < len(left_half) and j < len(right_half):
|
||||||
|
if left_half[i] < right_half[j]:
|
||||||
|
arr[k] = left_half[i]
|
||||||
|
i += 1
|
||||||
|
else:
|
||||||
|
arr[k] = right_half[j]
|
||||||
|
j += 1
|
||||||
|
k += 1
|
||||||
|
|
||||||
|
# Checking if any element was left
|
||||||
|
while i < len(left_half):
|
||||||
|
arr[k] = left_half[i]
|
||||||
|
i += 1
|
||||||
|
k += 1
|
||||||
|
|
||||||
|
while j < len(right_half):
|
||||||
|
arr[k] = right_half[j]
|
||||||
|
j += 1
|
||||||
|
k += 1
|
||||||
|
# Driver code to test above
|
||||||
|
arr = [24, 32, 10, 67, 55, 38, 19]
|
||||||
|
print(arr)
|
||||||
|
merge_sort(arr)
|
||||||
|
|
||||||
|
print("Sorted array is:")
|
||||||
|
print(arr)
|
||||||
|
|
||||||
|
def is_fibuncacci(num):
|
||||||
|
if (num < 2):
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Base case
|
||||||
|
if num == 1:
|
||||||
|
return True
|
||||||
|
|
||||||
|
for i in range(2, num + 1):
|
||||||
|
if is_fibonacci(i) and is_fibonacci(num - i):
|
||||||
|
return True
|
||||||
|
|
||||||
|
# If we reach here, then n
|
||||||
|
|
||||||
|
|
||||||
|
# Base case
|
||||||
|
if num == 1:
|
||||||
|
return True
|
||||||
|
|
||||||
|
for i in range(2, num + 1):
|
||||||
|
if is_fibonacci(i) and is_fibonacci(num - i):
|
||||||
|
return True
|
||||||
|
|
||||||
|
# If we reach here, then n
|
||||||
|
|
||||||
|
|
||||||
|
def quicksort(arr)
|
Loading…
Reference in New Issue