[ADD] owl-vision: vscode extension initial commit

Owl Vision is a vscode extension that improves owl developpement by adding
syntax highlights in templates and commands to easly navigate between
components and templates.

It also adds a Component snippet.

Commands:

* `Owl Vision: Find Template`:
    - If the cursor is on a template name, finds the corresponding template.
    - If the cursor is on a component, finds the template of the selected component.
* `Owl Vision: Find Component`: Finds the selected component definition.
* `Owl Vision: Switch`: Finds the corresponding template or component
    depending on the current file.
* `Owl Vision: Switch Besides`: Finds the corresponding template or component
    depending on the current file and opens it besides.

Settings:

* `owl-vision.js.include`: Javascript files to include in search.
* `owl-vision.js.exclude`: Javascript files to exclude in search.
* `owl-vision.xml.include`: XML files to include in search.
* `owl-vision.xml.exclude`: XML files to exclude in search.
This commit is contained in:
Bastien Fafchamps (bafa)
2023-10-19 11:13:16 +02:00
committed by Géry Debongnie
parent acbe316689
commit 166cada8ff
21 changed files with 7392 additions and 1 deletions
+69
View File
@@ -0,0 +1,69 @@
import * as vscode from 'vscode';
let statusMessage: vscode.StatusBarItem | undefined = undefined;
export function showStatusMessage(text: string) {
if (!statusMessage) {
statusMessage = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
}
statusMessage.text = `$(sync~spin) ${text}`;
statusMessage.show();
}
export function hideStatusMessage() {
statusMessage?.hide();
}
export function getActiveCursorIndex(lineDelta = 0): number {
const editor = vscode.window.activeTextEditor;
if (!editor) {
return 0;
}
const position = editor.selection.active.translate(lineDelta);
return editor.document.offsetAt(position);
}
export function getSelectedText(regex?: RegExp, document?: vscode.TextDocument, position?: vscode.Position): string | undefined {
const editor = vscode.window.activeTextEditor;
if (!document) {
if (!editor) {
return;
}
document = editor.document;
}
position = position || vscode.window.activeTextEditor?.selection.active;
if (!position) {
return;
}
const wordRange = document.getWordRangeAtPosition(position, regex);
if (!wordRange) {
return;
}
return document.getText(wordRange);
}
export function getClosestMatch(str: string, regex: RegExp, lineDelta = 0): string | undefined {
const index = getActiveCursorIndex(lineDelta);
const matches = [...str.matchAll(regex)];
if (matches.length === 0) {
return;
}
let closestMatch = matches[0];
let closestDistance = Math.abs(index - (closestMatch.index || 0));
for (const match of matches) {
const matchIndex = match.index || 0;
const distance = Math.abs(index - matchIndex);
if (matchIndex < index && distance < closestDistance) {
closestMatch = match;
closestDistance = distance;
}
}
return closestMatch[1];
}