summaryrefslogtreecommitdiff
path: root/extension/src/languages/python/index.ts
diff options
context:
space:
mode:
authorNate Sesti <sestinj@gmail.com>2023-06-26 16:39:07 -0700
committerNate Sesti <sestinj@gmail.com>2023-06-26 16:39:07 -0700
commitf3c6533d4054de5a71c8867c2b76fc8b0747447c (patch)
tree8e53ce9533aa42ee5d0a31504aa07be691d87157 /extension/src/languages/python/index.ts
parentf403bbe26b8864ff5367eab08afe4a01fdde8e72 (diff)
parent292d4d10ce28d720d61f97918c490b0d9cdae9e7 (diff)
downloadsncontinue-f3c6533d4054de5a71c8867c2b76fc8b0747447c.tar.gz
sncontinue-f3c6533d4054de5a71c8867c2b76fc8b0747447c.tar.bz2
sncontinue-f3c6533d4054de5a71c8867c2b76fc8b0747447c.zip
Merge branch 'main' into styled-code
Diffstat (limited to 'extension/src/languages/python/index.ts')
-rw-r--r--extension/src/languages/python/index.ts74
1 files changed, 0 insertions, 74 deletions
diff --git a/extension/src/languages/python/index.ts b/extension/src/languages/python/index.ts
deleted file mode 100644
index 50282b45..00000000
--- a/extension/src/languages/python/index.ts
+++ /dev/null
@@ -1,74 +0,0 @@
-import path = require("path");
-import { LanguageLibrary } from "../index.d";
-
-const tracebackStart = "Traceback (most recent call last):";
-const tracebackEnd = (buf: string): string | undefined => {
- let lines = buf
- .split("\n")
- .filter((line: string) => line.trim() !== "~~^~~")
- .filter((line: string) => line.trim() !== "");
- for (let i = 0; i < lines.length; i++) {
- if (
- lines[i].startsWith(" File") &&
- i + 2 < lines.length &&
- lines[i + 2][0] !== " "
- ) {
- return lines.slice(0, i + 3).join("\n");
- }
- }
- return undefined;
-};
-
-function parseFirstStacktrace(stdout: string): string | undefined {
- let startIdx = stdout.indexOf(tracebackStart);
- if (startIdx < 0) return undefined;
- stdout = stdout.substring(startIdx);
- return tracebackEnd(stdout);
-}
-
-function lineIsFunctionDef(line: string): boolean {
- return line.startsWith("def ");
-}
-
-function parseFunctionDefForName(line: string): string {
- return line.split("def ")[1].split("(")[0];
-}
-
-function lineIsComment(line: string): boolean {
- return line.trim().startsWith("#");
-}
-
-function writeImport(
- sourcePath: string,
- pathToImport: string,
- namesToImport: string[] | undefined = undefined
-): string {
- let segs = path.relative(sourcePath, pathToImport).split(path.sep);
- let importFrom = "";
- for (let seg of segs) {
- if (seg === "..") {
- importFrom = "." + importFrom;
- } else {
- if (!importFrom.endsWith(".")) {
- importFrom += ".";
- }
- importFrom += seg.split(".").slice(0, -1).join(".");
- }
- }
-
- return `from ${importFrom} import ${
- namesToImport ? namesToImport.join(", ") : "*"
- }`;
-}
-
-const pythonLangaugeLibrary: LanguageLibrary = {
- language: "python",
- fileExtensions: [".py"],
- parseFirstStacktrace,
- lineIsFunctionDef,
- parseFunctionDefForName,
- lineIsComment,
- writeImport,
-};
-
-export default pythonLangaugeLibrary;