8000 fix: Normalize name and version correctly (#99) · codean-io/scip-python@cd63124 · GitHub
[go: up one dir, main page]

Skip to content

Commit cd63124

Browse files
fix: Normalize name and version correctly (sourcegraph#99)
1 parent db414af commit cd63124

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# < definition scip-python python package with space 0.1 main/__init__:
1+
# < definition scip-python python package with space 0.1 main/__init__:
22
#documentation (module) main
33

44
def main():
5-
# ^^^^ definition package with space 0.1 main/main().
5+
# ^^^^ definition package with space 0.1 main/main().
66
# documentation ```python
77
# > def main(): # -> None:
88
# > ```
99
pass
1010

1111
main()
12-
#^^^ reference package with space 0.1 main/main().
12+
#^^^ reference package with space 0.1 main/main().
1313

packages/pyright-scip/src/ScipSymbol.ts

Original file line numberDiff line numberDiff line change
@@ -7,10 +7,21 @@ export class ScipSymbol extends TypescriptScipSymbol {
77
}
88

99
public static override package(name: string, version: string): TypescriptScipSymbol {
10-
name = name.replace(/\./, '/');
11-
name = name.trim();
10+
name = normalizeNameOrVersion(name);
11+
version = normalizeNameOrVersion(version);
1212

1313
// @ts-ignore
1414
return new TypescriptScipSymbol(`scip-python python ${name} ${version} `);
1515
}
1616
}
17+
18+
// See https://github.com/sourcegraph/scip/blob/main/scip.proto#L118-L121
19+
function normalizeNameOrVersion(s: string): string {
20+
if (s === '') {
21+
return '.';
22+
}
23+
if (s.indexOf(' ') === -1) {
24+
return s;
25+
}
26+
return s.replace(/ /g, ' ');
27+
}