Skip to content

Commit

Permalink
Added hover and code completion to python
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasArvidsson committed Jun 25, 2023
1 parent 0bd6c71 commit c22f020
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 115 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "andreas-talon",
"displayName": "Andreas Talon",
"description": "VSCode extension used by Talon Voice",
"version": "3.18.0",
"version": "3.19.0",
"publisher": "AndreasArvidsson",
"license": "MIT",
"main": "./out/extension.js",
Expand Down
2 changes: 1 addition & 1 deletion src/language/defaultActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ const actionsList: ActionDesc[] = Array.from(
};
});

export function getDefaultActions(match: TalonMatch): ActionDesc[] {
export function searchInDefaultActions(match: TalonMatch): ActionDesc[] {
if (match.type !== "action") {
return [];
}
Expand Down
53 changes: 49 additions & 4 deletions src/language/matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { ANY } from "./RegexUtils";

export type TalonMatchType = "action" | "capture" | "list";

interface TalonMatchName {
export interface TalonMatchName {
type: TalonMatchType;
name: string;
}

interface TalonMatchPrefix {
export interface TalonMatchPrefix {
type: TalonMatchType;
prefix: string;
}
Expand All @@ -18,7 +18,7 @@ export type TalonMatch = TalonMatchName | TalonMatchPrefix;
export function getTalonMatchAtPosition(
document: TextDocument,
position: Position
): TalonMatch | undefined {
): TalonMatchName | undefined {
const name = getNameAtPosition(document, position);
if (!name) {
return undefined;
Expand Down Expand Up @@ -56,7 +56,7 @@ export function getTalonMatchAtPosition(
export function getPythonMatchAtPosition(
document: TextDocument,
position: Position
): TalonMatch | undefined {
): TalonMatchName | undefined {
const name = getNameAtPosition(document, position);
if (!name) {
return undefined;
Expand All @@ -75,6 +75,51 @@ export function getPythonMatchAtPosition(
return undefined;
}

export function getTalonPrefixAtPosition(
document: TextDocument,
position: Position
): TalonMatchPrefix | undefined {
const line = document.lineAt(position.line);
const text = line.text.substring(0, position.character);
const prefix = text.match(/[\w\d.]+$/)?.[0] ?? "";
const isInScript = line.firstNonWhitespaceCharacterIndex !== 0 || text.includes(":");

// When in the script side of the command available values are the action names
if (isInScript) {
return { type: "action", prefix };
}

const prevChar =
text
.substring(0, text.length - prefix.length)
.trim()
.at(-1) ?? "";

// When in the rule side of the command available values are list and capture names
if (prevChar === "{") {
return { type: "list", prefix };
}

if (prevChar === "<") {
return { type: "capture", prefix };
}

return undefined;
}

export function getPythonPrefixAtPosition(
document: TextDocument,
position: Position
): TalonMatchPrefix | undefined {
const line = document.lineAt(position.line);
const text = line.text.substring(0, position.character);
const prefix = text.trimStart().match(/actions.[\w\d.]*$/)?.[0];
if (!prefix) {
return undefined;
}
return { type: "action", prefix: prefix.substring(8) };
}

function getNameAtPosition(document: TextDocument, position: Position): string | undefined {
const range = document.getWordRangeAtPosition(position, /\w+(\.\w+)*/);
if (!range || range.isEmpty || !range.isSingleLine) {
Expand Down
Loading

0 comments on commit c22f020

Please sign in to comment.