Skip to content

Commit 292bcb4

Browse files
committed
Add support for SymbolInformation.signature
Companion PRs: * sourcegraph/scip#231 * sourcegraph/cody#3142 Previously, scip-typescript didn't emit any structured information about signatures. This PR solves that problem, which unblocks new exciting use-cases for SCIP. Keeping this PR open for a while since we are not planning to merge signature support to SCIP just yet. For now, the Cody repo can use this branch instead.
1 parent ea22136 commit 292bcb4

34 files changed

+7694
-158
lines changed

.tool-versions

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
nodejs 20.8.1
1+
nodejs 20.4.0
22
pnpm 8.9.2

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"editor.formatOnSave": true
2+
"editor.formatOnSave": true,
3+
"editor.defaultFormatter": "esbenp.prettier-vscode"
34
}

snapshots/input/syntax/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
},
99
"author": "",
1010
"license": "ISC",
11-
"private": true
11+
"private": true,
12+
"devDependencies": {
13+
"@types/vscode": "1.86.0"
14+
}
1215
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// format-options: showSignatures
2+
export namespace minimized {
3+
export enum NumericLiteralEnum {
4+
One = 1,
5+
TwoThousand = 2_000,
6+
}
7+
8+
export const doubleConstant = 3.14
9+
10+
export enum StringLiteralEnum {
11+
Saturday = 'saturday',
12+
Sunday = 'sunday',
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// format-options: showSignatures
2+
3+
export interface OptionalProperty {
4+
optional1?: string
5+
optional2?: number | null
6+
optional3?: number | undefined
7+
optional4?: undefined
8+
}
+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// format-options: showSignatures
2+
3+
export type Requests = {
4+
'workspace/edit': [WorkspaceEditParams, boolean]
5+
'chat/submitMessage': [WorkspaceEditParams, boolean]
6+
}
7+
8+
export type Notifications = {
9+
'workspace/edit': [WorkspaceEditParams]
10+
}
11+
12+
export type Intersection = { uri: string } & { size: number }
13+
export type Union = { uri: string } | { size: number }
14+
export type Builtin = Pick<WorkspaceEditParams, 'changes'>
15+
export type Builtin2 = Partial<WorkspaceEditParams>
16+
export interface WorkspaceEditParams {
17+
changes: { uri: string }[]
18+
}
19+
20+
export interface OptionalProperty {
21+
optional1?: string
22+
optional2?: number | null
23+
optional3?: number | undefined
24+
optional4?: undefined
25+
}
26+
27+
export interface ExampleSuperInterface<T> {
28+
a: T
29+
b: string
30+
}
31+
export interface ExampleInterface<T> extends ExampleSuperInterface<T> {
32+
c: number
33+
}
34+
export class ExampleSuperClass<T> {
35+
constructor(
36+
public a: T,
37+
public b: string
38+
) {}
39+
}
40+
41+
export class ExampleClass<T>
42+
extends ExampleSuperClass<T>
43+
implements ExampleSuperInterface<T>, ExampleInterface<T>
44+
{
45+
public d: Record<string, any>
46+
47+
#e = true
48+
49+
constructor(
50+
public a: T,
51+
public b: string,
52+
public c: number,
53+
d: Record<string, any>
54+
) {
55+
super(a, b)
56+
this.d = d
57+
}
58+
public getC(): number {
59+
return this.c
60+
}
61+
62+
get e(): boolean {
63+
return this.#e
64+
}
65+
66+
set setB(b: string) {
67+
this.#e = true
68+
this.b = b
69+
}
70+
}
71+
72+
export function basicFunction<T>(a: T, b: number): string {
73+
return `${a}${b}`
74+
}
75+
export const constant = 42
76+
export const variable: <T>(a: T, b: number) => string = (a, b) => `${a}${b}`
77+
78+
export interface User {
79+
name: string
80+
age: number
81+
customHeaders: Record<string, string>
82+
}
83+
84+
export interface ChatHistory {
85+
chatID: User
86+
[a: number]: User
87+
[_: string]: User
88+
}
89+
90+
export class ModelProvider {
91+
default = true
92+
}
93+
94+
export enum NumericLiteralEnum {
95+
MinusOne = -1,
96+
Expression = 1 + 23 - 2,
97+
One = 1,
98+
TwoThousand = 2_000,
99+
}
100+
101+
export const doubleConstant = 3.14
102+
103+
export enum StringLiteralEnum {
104+
Saturday = 'saturday',
105+
Sunday = 'sunday',
106+
}

snapshots/input/syntax/src/structural-type.ts

+3
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@ export function bar2(): Promise<number> {
1010

1111
type OptionsFlags<Type> = { [Property in keyof Type]: boolean }
1212
type FeatureFlags = { darkMode: () => void }
13+
export type PropertySignature = {
14+
'chat/submit': [{ text: { value: string } }]
15+
}
1316
export type FeatureOptions = OptionsFlags<FeatureFlags> // implicitly // type FeatureOptions = { // darkMode: boolean; // } const fo: FeatureOptions = { darkMode: true }; // ^ go to def
1417
export const fo: FeatureOptions = { darkMode: true }

snapshots/output/enclosing-ranges-ts/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
interface Foo {
88
// ^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/Foo#
99
bar: string
10-
//^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/Foo#bar.
10+
//^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/bar0:
1111
test: () => void
12-
//^^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/Foo#test.
12+
//^^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/test0:
1313
}
1414
// < end enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/Foo#
1515

@@ -18,7 +18,7 @@ interface Single<T> {
1818
// ^^^^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/Single#
1919
// ^ definition enclosing-ranges-ts 1.0.0 `index.ts`/Single#[T]
2020
t: T
21-
//^ definition enclosing-ranges-ts 1.0.0 `index.ts`/Single#t.
21+
//^ definition enclosing-ranges-ts 1.0.0 `index.ts`/t0:
2222
// ^ reference enclosing-ranges-ts 1.0.0 `index.ts`/Single#[T]
2323
}
2424
// < end enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/Single#

snapshots/output/pure-js/src/main.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ function print_fib(a) {
2020
console.log(fib(a))
2121
//^^^^^^^ reference typescript 5.3.3 lib/`lib.dom.d.ts`/console.
2222
//^^^^^^^ reference @types/node 20.10.5 `globals.d.ts`/global/console.
23-
//^^^^^^^ reference @types/node 20.10.5 `console.d.ts`/`"node:console"`/global/console/
24-
//^^^^^^^ reference @types/node 20.10.5 `console.d.ts`/`"node:console"`/global/console.
23+
//^^^^^^^ reference @types/node 20.10.5 `console.d.ts`/`node:console`/global/console/
24+
//^^^^^^^ reference @types/node 20.10.5 `console.d.ts`/`node:console`/global/console.
2525
// ^^^ reference typescript 5.3.3 lib/`lib.dom.d.ts`/Console#log().
26-
// ^^^ reference @types/node 20.10.5 `console.d.ts`/`"node:console"`/global/Console#log().
26+
// ^^^ reference @types/node 20.10.5 `console.d.ts`/`node:console`/global/Console#log().
2727
// ^^^ reference pure-js 1.0.0 src/`main.js`/fib().
2828
// ^ reference pure-js 1.0.0 src/`main.js`/print_fib().(a)
2929
}
@@ -42,12 +42,12 @@ const capture_lambda = () => {
4242
}
4343

4444
for (var i = 0; i <= 10; i++) {}
45-
// ^ definition local 2
46-
// ^ reference local 2
47-
// ^ reference local 2
45+
// ^ definition local 4
46+
// ^ reference local 4
47+
// ^ reference local 4
4848

4949
for (const x of [1, 2, 3]) {
50-
// ^ definition local 5
50+
// ^ definition local 7
5151
}
5252

5353
var a = 0
@@ -68,32 +68,32 @@ function use_before_def() {
6868
// ^^^^^^^^^^^^^^ definition pure-js 1.0.0 src/`main.js`/use_before_def().
6969
print_fib(n)
7070
//^^^^^^^^^ reference pure-js 1.0.0 src/`main.js`/print_fib().
71-
// ^ reference local 8
71+
// ^ reference local 10
7272
var n = 10
73-
// ^ definition local 8
73+
// ^ definition local 10
7474

7575
if (forever()) {
7676
// ^^^^^^^ reference pure-js 1.0.0 src/`main.js`/forever().
7777
var m = 10
78-
// ^ definition local 11
78+
// ^ definition local 13
7979
}
8080
print_fib(m)
8181
//^^^^^^^^^ reference pure-js 1.0.0 src/`main.js`/print_fib().
82-
// ^ reference local 11
82+
// ^ reference local 13
8383
}
8484

8585
function var_function_scope() {
8686
// ^^^^^^^^^^^^^^^^^^ definition pure-js 1.0.0 src/`main.js`/var_function_scope().
8787
var k = 0
88-
// ^ definition local 14
88+
// ^ definition local 16
8989
if (forever()) {
9090
// ^^^^^^^ reference pure-js 1.0.0 src/`main.js`/forever().
9191
var k = 1
92-
// ^ definition local 17
92+
// ^ definition local 19
9393
}
9494
print_fib(k)
9595
//^^^^^^^^^ reference pure-js 1.0.0 src/`main.js`/print_fib().
96-
// ^ reference local 14
97-
// ^ reference local 17
96+
// ^ reference local 16
97+
// ^ reference local 19
9898
}
9999

snapshots/output/react/src/LoaderInput.tsx

+19-19
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import React from 'react'
88
interface Props {
99
// ^^^^^ definition react-example 1.0.0 src/`LoaderInput.tsx`/Props#
1010
loading: boolean
11-
//^^^^^^^ definition react-example 1.0.0 src/`LoaderInput.tsx`/Props#loading.
11+
//^^^^^^^ definition react-example 1.0.0 src/`LoaderInput.tsx`/loading0:
1212
children: React.ReactNode
13-
//^^^^^^^^ definition react-example 1.0.0 src/`LoaderInput.tsx`/Props#children.
13+
//^^^^^^^^ definition react-example 1.0.0 src/`LoaderInput.tsx`/children0:
1414
// ^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/
1515
// ^^^^^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/ReactNode#
1616
}
@@ -21,37 +21,37 @@ export const LoaderInput: React.FunctionComponent<Props> = ({
2121
// ^^^^^^^^^^^^^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/FunctionComponent#
2222
// ^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#
2323
loading,
24-
//^^^^^^^ definition local 3
25-
//^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#loading.
24+
//^^^^^^^ definition local 4
25+
//^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/loading0:
2626
children,
27-
//^^^^^^^^ definition local 4
28-
//^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#children.
27+
//^^^^^^^^ definition local 5
28+
//^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/children0:
2929
}) => (
3030
<div className="hello">
31-
// ^^^ reference @types/react 18.2.39 `index.d.ts`/global/JSX/IntrinsicElements#div.
32-
// ^^^^^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/HTMLAttributes#className.
31+
// ^^^ reference @types/react 18.2.39 `index.d.ts`/div0:
32+
// ^^^^^^^^^ reference @types/react 18.2.39 `index.d.ts`/className0:
3333
{children}
34-
// ^^^^^^^^ reference local 4
34+
// ^^^^^^^^ reference local 5
3535
{loading && <p>spinner</p>}
36-
// ^^^^^^^ reference local 3
37-
// ^ reference @types/react 18.2.39 `index.d.ts`/global/JSX/IntrinsicElements#p.
38-
// ^ reference @types/react 18.2.39 `index.d.ts`/global/JSX/IntrinsicElements#p.
36+
// ^^^^^^^ reference local 4
37+
// ^ reference @types/react 18.2.39 `index.d.ts`/p0:
38+
// ^ reference @types/react 18.2.39 `index.d.ts`/p0:
3939
</div>
40-
// ^^^ reference @types/react 18.2.39 `index.d.ts`/global/JSX/IntrinsicElements#div.
40+
// ^^^ reference @types/react 18.2.39 `index.d.ts`/div0:
4141
)
4242

4343
export const LoaderInput2: React.FunctionComponent<Props> = props => {
4444
// ^^^^^^^^^^^^ definition react-example 1.0.0 src/`LoaderInput.tsx`/LoaderInput2.
4545
// ^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/
4646
// ^^^^^^^^^^^^^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/FunctionComponent#
4747
// ^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#
48-
// ^^^^^ definition local 6
48+
// ^^^^^ definition local 705
4949
return <LoaderInput loading={true} key="key" children={props.children} />
5050
// ^^^^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/LoaderInput.
51-
// ^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#loading.
52-
// ^^^ reference local 10
53-
// ^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#children.
54-
// ^^^^^ reference local 6
55-
// ^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#children.
51+
// ^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/loading0:
52+
// ^^^ reference local 709
53+
// ^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/children0:
54+
// ^^^^^ reference local 705
55+
// ^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/children0:
5656
}
5757

snapshots/output/react/src/MyTSXElement.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ export const MyTSXElement: React.FunctionComponent<MyProps> = ({}) => (<p></p>)
1212
// ^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/
1313
// ^^^^^^^^^^^^^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/FunctionComponent#
1414
// ^^^^^^^ reference react-example 1.0.0 src/`MyTSXElement.tsx`/MyProps#
15-
// ^ reference @types/react 18.2.39 `index.d.ts`/global/JSX/IntrinsicElements#p.
16-
// ^ reference @types/react 18.2.39 `index.d.ts`/global/JSX/IntrinsicElements#p.
15+
// ^ reference @types/react 18.2.39 `index.d.ts`/p0:
16+
// ^ reference @types/react 18.2.39 `index.d.ts`/p0:

snapshots/output/syntax/src/accessors.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,6 @@ function f() {
115115
g(D.length)
116116
//^ reference syntax 1.0.0 src/`accessors.ts`/g().
117117
// ^ reference syntax 1.0.0 src/`accessors.ts`/D#
118-
// ^^^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Function#length.
118+
// ^^^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/length0:
119119
}
120120

0 commit comments

Comments
 (0)