diff options
| author | Nate Sesti <sestinj@gmail.com> | 2023-06-27 11:17:26 -0700 | 
|---|---|---|
| committer | Nate Sesti <sestinj@gmail.com> | 2023-06-27 11:17:26 -0700 | 
| commit | c3106d3540efbf48de694ac9b9294d56b520493a (patch) | |
| tree | d5923db2a1151517181f0a26ee32a3a873e019f9 /extension/src/languages/python/index.ts | |
| parent | bedd5f31e7a1d7b915fbb2a47a92f58035c96415 (diff) | |
| parent | 3a39f7029f7faf5c77d4678ce6d796e4c99b558b (diff) | |
| download | sncontinue-c3106d3540efbf48de694ac9b9294d56b520493a.tar.gz sncontinue-c3106d3540efbf48de694ac9b9294d56b520493a.tar.bz2 sncontinue-c3106d3540efbf48de694ac9b9294d56b520493a.zip | |
Merge branch 'main' into newer-simpler-stream-algo
Diffstat (limited to 'extension/src/languages/python/index.ts')
| -rw-r--r-- | extension/src/languages/python/index.ts | 74 | 
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; | 
