Skip to content

Commit 0e5ba6d

Browse files
committed
fix: fix lang from path logic: don't crash for non-. paths; workarounds for D
1 parent 16d2547 commit 0e5ba6d

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

src/ct/utilities/language_detection.nim

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const LANGS = {
3131
"py": LangPythonDb,
3232
"rb": LangRubyDb, # default for ruby for now
3333
"nr": LangNoir,
34+
"d": LangC, # TODO
3435
"small": LangSmall,
3536
"wasm": LangRustWasm, # TODO: can be Cpp or other as well, maybe pass
3637
# explicitly or check trace/other debug info?
@@ -44,15 +45,21 @@ const WASM_LANGS = {
4445

4546
proc detectLangFromPath*(path: string, isWasm: bool): Lang =
4647
let filename = path.extractFilename
47-
let extension = rsplit(filename[1..^1], ".", 1)[1].toLowerAscii()
48+
echo filename
49+
let tokens = rsplit(filename[1..^1], ".", 1)
50+
if tokens.len > 1:
51+
let extension = tokens[1].toLowerAscii()
4852

49-
if isWasm and WASM_LANGS.hasKey(extension):
50-
return WASM_LANGS[extension]
53+
if isWasm and WASM_LANGS.hasKey(extension):
54+
return WASM_LANGS[extension]
55+
56+
if LANGS.hasKey(extension):
57+
result = LANGS[extension] # TODO detectLangFromTrace(traceId) ?
58+
if result != LangUnknown:
59+
return result
60+
else:
61+
return LangUnknown
5162

52-
if LANGS.hasKey(extension):
53-
result = LANGS[extension] # TODO detectLangFromTrace(traceId) ?
54-
if result != LangUnknown:
55-
return result
5663

5764
proc detectLang*(program: string, lang: Lang, isWasm: bool = false): Lang =
5865
# TODO: under a debug print flag?

src/db-backend/src/lang.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ pub fn lang_from_context(path: &Path, trace_kind: TraceKind) -> Lang {
5656
}
5757
"c" => Lang::C,
5858
"cpp" => Lang::Cpp,
59+
"pas" => Lang::Pascal,
60+
"nim" => Lang::Nim,
61+
"d" => Lang::C, // TODO
62+
"go" => Lang::Go,
5963
_ => Lang::Unknown,
6064
}
6165
}

src/frontend/index/server_config.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,6 @@ when defined(server):
102102
debugPrint "call ready"
103103
discard jsAsFunction[proc: Future[void]](readyVar)()
104104
readyVar = undefined
105+
105106
infoPrint fmt"socket.io listening on localhost:{backendSocketPort}"
106107
httpServer.listen(backendSocketPort)

src/frontend/lang.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ proc toLang*(lang: cstring): Lang =
2323
lua: LangLua,
2424
nr: LangNoir,
2525
small: LangSmall,
26-
noir: LangNoir
26+
noir: LangNoir,
27+
d: LangC, # TODO
2728
}
2829
if langs.hasKey(lang):
2930
result = langs[lang]

0 commit comments

Comments
 (0)