Skip to content

Commit

Permalink
markdown variable suggestion from the same python file name
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhlongviolin1 committed Dec 14, 2022
1 parent 7920692 commit 6493d60
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions gui/src/gui/completion.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { existsSync } from "fs";
import path from "path";
import {
CancellationToken,
commands,
Expand All @@ -11,6 +13,7 @@ import {
SymbolInformation,
SymbolKind,
TextDocument,
Uri,
} from "vscode";
import { defaultElementList, defaultElementProperties, defaultOnFunctionList } from "./constant";
import { markdownDocumentFilter, pythonDocumentFilter } from "./utils";
Expand All @@ -35,6 +38,17 @@ export class GuiCompletionItemProvider implements CompletionItemProvider {
const line = document.lineAt(position).text;
const linePrefix = line.slice(0, position.character);
let completionList: CompletionItem[] = [];
if ((document.fileName.endsWith(".md") || document.languageId === "markdown") && linePrefix.endsWith("{")) {
const potentialPythonFile = path.join(path.dirname(document.uri.fsPath), path.parse(document.fileName).name + ".py");
if (existsSync(potentialPythonFile)) {
let symbols = (await commands.executeCommand(
"vscode.executeDocumentSymbolProvider",
Uri.file(potentialPythonFile)
)) as SymbolInformation[];
symbols = symbols.filter((v) => v.kind === SymbolKind.Variable);
return symbols.map((v) => new CompletionItem(v.name, CompletionItemKind.Variable));
}
}
if ((document.fileName.endsWith(".py") || document.languageId === "python") && linePrefix.endsWith("{")) {
let symbols = (await commands.executeCommand(
"vscode.executeDocumentSymbolProvider",
Expand All @@ -54,8 +68,7 @@ export class GuiCompletionItemProvider implements CompletionItemProvider {
)) as SymbolInformation[];
symbols = symbols.filter((v) => v.kind === SymbolKind.Function);
return symbols.map((v) => new CompletionItem(v.name, CompletionItemKind.Function));
}
else if (linePrefix.endsWith("|")) {
} else if (linePrefix.endsWith("|")) {
const foundElements = defaultElementList.reduce((p: string[], c: string) => {
linePrefix.includes(`|${c}`) && p.push(c);
return p;
Expand Down

0 comments on commit 6493d60

Please sign in to comment.