Skip to content

Commit 1a6776e

Browse files
Generate correct scipSymbol for namespace imports (sourcegraph#195)
* Generate correct `scipSymbol` for namespace imports * Add `namespace` to the `import` test * Fix the `import` test
1 parent 8496b0d commit 1a6776e

File tree

6 files changed

+43
-26
lines changed

6 files changed

+43
-26
lines changed

snapshots/input/syntax/src/import.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as namespace from './namespace'
12
import { Class } from './class'
23
import { Enum } from './enum'
34
import { newFunction } from './function'
@@ -8,7 +9,8 @@ export function useEverything(): string {
89
new Class('a').classProperty +
910
renamedInterface().methodSignature('a') +
1011
Enum[Enum.A] +
11-
newFunction()
12+
newFunction() +
13+
namespace.a.value
1214
)
1315
}
1416

Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
declare namespace a {
1+
export declare namespace a {
22
function hello(): string
33
interface Interface {
44
hello: string
55
}
66
var i: Interface
7+
export const value = 1
78
}

snapshots/output/syntax/src/import.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import { Class } from './class'
1+
import * as namespace from './namespace'
22
// definition syntax 1.0.0 src/`import.ts`/
33
//documentation ```ts\nmodule "import.ts"\n```
4+
// ^^^^^^^^^ reference syntax 1.0.0 src/`namespace.ts`/
5+
// ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`namespace.ts`/
6+
import { Class } from './class'
47
// ^^^^^ reference syntax 1.0.0 src/`class.ts`/Class#
58
// ^^^^^^^^^ reference syntax 1.0.0 src/`class.ts`/
69
import { Enum } from './enum'
@@ -28,8 +31,12 @@
2831
// ^^^^ reference syntax 1.0.0 src/`enum.ts`/Enum#
2932
// ^^^^ reference syntax 1.0.0 src/`enum.ts`/Enum#
3033
// ^ reference syntax 1.0.0 src/`enum.ts`/Enum#A.
31-
newFunction()
34+
newFunction() +
3235
// ^^^^^^^^^^^ reference syntax 1.0.0 src/`function.ts`/newFunction().
36+
namespace.a.value
37+
// ^^^^^^^^^ reference syntax 1.0.0 src/`namespace.ts`/
38+
// ^ reference syntax 1.0.0 src/`namespace.ts`/a/
39+
// ^^^^^ reference syntax 1.0.0 src/`namespace.ts`/a/value.
3340
)
3441
}
3542

snapshots/output/syntax/src/namespace.d.ts

-21
This file was deleted.
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export declare namespace a {
2+
// definition syntax 1.0.0 src/`namespace.ts`/
3+
//documentation ```ts\nmodule "namespace.ts"\n```
4+
// ^ definition syntax 1.0.0 src/`namespace.ts`/a/
5+
// documentation ```ts\na: typeof a\n```
6+
function hello(): string
7+
// ^^^^^ definition syntax 1.0.0 src/`namespace.ts`/a/hello().
8+
// documentation ```ts\nfunction hello(): string\n```
9+
interface Interface {
10+
// ^^^^^^^^^ definition syntax 1.0.0 src/`namespace.ts`/a/Interface#
11+
// documentation ```ts\ninterface Interface\n```
12+
hello: string
13+
// ^^^^^ definition syntax 1.0.0 src/`namespace.ts`/a/Interface#hello.
14+
// documentation ```ts\n(property) hello: string\n```
15+
}
16+
var i: Interface
17+
// ^ definition syntax 1.0.0 src/`namespace.ts`/a/i.
18+
// documentation ```ts\nvar i: Interface\n```
19+
// ^^^^^^^^^ reference syntax 1.0.0 src/`namespace.ts`/a/Interface#
20+
export const value = 1
21+
// ^^^^^ definition syntax 1.0.0 src/`namespace.ts`/a/value.
22+
// documentation ```ts\nvar value: 1\n```
23+
}
24+

src/FileIndexer.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,11 @@ export class FileIndexer {
389389
return this.cached(node, this.scipSymbol(node.parent))
390390
}
391391

392-
if (ts.isImportSpecifier(node) || ts.isImportClause(node)) {
392+
if (
393+
ts.isImportSpecifier(node) ||
394+
ts.isImportClause(node) ||
395+
ts.isNamespaceImport(node)
396+
) {
393397
const tpe = this.checker.getTypeAtLocation(node)
394398
for (const declaration of tpe.symbol?.declarations || []) {
395399
return this.scipSymbol(declaration)

0 commit comments

Comments
 (0)