Skip to content

Commit

Permalink
Add support for SymbolInformation.signature
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
olafurpg committed Feb 13, 2024
1 parent 70bab97 commit 198d8e7
Show file tree
Hide file tree
Showing 33 changed files with 7,397 additions and 157 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"editor.formatOnSave": true
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
5 changes: 4 additions & 1 deletion snapshots/input/syntax/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
},
"author": "",
"license": "ISC",
"private": true
"private": true,
"devDependencies": {
"@types/vscode": "1.86.0"
}
}
14 changes: 14 additions & 0 deletions snapshots/input/syntax/src/definition-file-signatures.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// format-options: showSignatures
export namespace minimized {
export enum NumericLiteralEnum {
One = 1,
TwoThousand = 2_000,
}

export const doubleConstant = 3.14

export enum StringLiteralEnum {
Saturday = 'saturday',
Sunday = 'sunday',
}
}
4 changes: 4 additions & 0 deletions snapshots/input/syntax/src/minimized-signatures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// format-options: showSignatures

export type CompletionItemID = string & { _opaque: typeof CompletionItemID }
declare const CompletionItemID: unique symbol
99 changes: 99 additions & 0 deletions snapshots/input/syntax/src/signatures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// format-options: showSignatures

export type Requests = {
'workspace/edit': [WorkspaceEditParams, boolean]
'chat/submitMessage': [WorkspaceEditParams, boolean]
}

export type Notifications = {
'workspace/edit': [WorkspaceEditParams]
}

export type Intersection = { uri: string } & { size: number }
export type Union = { uri: string } | { size: number }
export type Builtin = Pick<WorkspaceEditParams, 'changes'>
export type Builtin2 = Partial<WorkspaceEditParams>
export interface WorkspaceEditParams {
changes: { uri: string }[]
}

export interface ExampleSuperInterface<T> {
a: T
b: string
}
export interface ExampleInterface<T> extends ExampleSuperInterface<T> {
c: number
}
export class ExampleSuperClass<T> {
constructor(
public a: T,
public b: string
) {}
}

export class ExampleClass<T>
extends ExampleSuperClass<T>
implements ExampleSuperInterface<T>, ExampleInterface<T>
{
public d: Record<string, any>

#e = true

constructor(
public a: T,
public b: string,
public c: number,
d: Record<string, any>
) {
super(a, b)
this.d = d
}
public getC(): number {
return this.c
}

get e(): boolean {
return this.#e
}

set setB(b: string) {
this.#e = true
this.b = b
}
}

export function basicFunction<T>(a: T, b: number): string {
return `${a}${b}`
}
export const constant = 42
export const variable: <T>(a: T, b: number) => string = (a, b) => `${a}${b}`

export interface User {
name: string
age: number
customHeaders: Record<string, string>
}

export interface ChatHistory {
chatID: User
[a: number]: User
[_: string]: User
}

export class ModelProvider {
default = true
}

export enum NumericLiteralEnum {
MinusOne = -1,
Expression = 1 + 23 - 2,
One = 1,
TwoThousand = 2_000,
}

export const doubleConstant = 3.14

export enum StringLiteralEnum {
Saturday = 'saturday',
Sunday = 'sunday',
}
3 changes: 3 additions & 0 deletions snapshots/input/syntax/src/structural-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ export function bar2(): Promise<number> {

type OptionsFlags<Type> = { [Property in keyof Type]: boolean }
type FeatureFlags = { darkMode: () => void }
export type PropertySignature = {
'chat/submit': [{ text: { value: string } }]
}
export type FeatureOptions = OptionsFlags<FeatureFlags> // implicitly // type FeatureOptions = { // darkMode: boolean; // } const fo: FeatureOptions = { darkMode: true }; // ^ go to def
export const fo: FeatureOptions = { darkMode: true }
6 changes: 3 additions & 3 deletions snapshots/output/enclosing-ranges-ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
interface Foo {
// ^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/Foo#
bar: string
//^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/Foo#bar.
//^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/bar0:
test: () => void
//^^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/Foo#test.
//^^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/test0:
}
// < end enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/Foo#

Expand All @@ -18,7 +18,7 @@ interface Single<T> {
// ^^^^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/Single#
// ^ definition enclosing-ranges-ts 1.0.0 `index.ts`/Single#[T]
t: T
//^ definition enclosing-ranges-ts 1.0.0 `index.ts`/Single#t.
//^ definition enclosing-ranges-ts 1.0.0 `index.ts`/t0:
// ^ reference enclosing-ranges-ts 1.0.0 `index.ts`/Single#[T]
}
// < end enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/Single#
Expand Down
30 changes: 15 additions & 15 deletions snapshots/output/pure-js/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ function print_fib(a) {
console.log(fib(a))
//^^^^^^^ reference typescript 5.3.3 lib/`lib.dom.d.ts`/console.
//^^^^^^^ reference @types/node 20.10.5 `globals.d.ts`/global/console.
//^^^^^^^ reference @types/node 20.10.5 `console.d.ts`/`"node:console"`/global/console/
//^^^^^^^ reference @types/node 20.10.5 `console.d.ts`/`"node:console"`/global/console.
//^^^^^^^ reference @types/node 20.10.5 `console.d.ts`/`node:console`/global/console/
//^^^^^^^ reference @types/node 20.10.5 `console.d.ts`/`node:console`/global/console.
// ^^^ reference typescript 5.3.3 lib/`lib.dom.d.ts`/Console#log().
// ^^^ reference @types/node 20.10.5 `console.d.ts`/`"node:console"`/global/Console#log().
// ^^^ reference @types/node 20.10.5 `console.d.ts`/`node:console`/global/Console#log().
// ^^^ reference pure-js 1.0.0 src/`main.js`/fib().
// ^ reference pure-js 1.0.0 src/`main.js`/print_fib().(a)
}
Expand All @@ -42,12 +42,12 @@ const capture_lambda = () => {
}

for (var i = 0; i <= 10; i++) {}
// ^ definition local 2
// ^ reference local 2
// ^ reference local 2
// ^ definition local 4
// ^ reference local 4
// ^ reference local 4

for (const x of [1, 2, 3]) {
// ^ definition local 5
// ^ definition local 7
}

var a = 0
Expand All @@ -68,32 +68,32 @@ function use_before_def() {
// ^^^^^^^^^^^^^^ definition pure-js 1.0.0 src/`main.js`/use_before_def().
print_fib(n)
//^^^^^^^^^ reference pure-js 1.0.0 src/`main.js`/print_fib().
// ^ reference local 8
// ^ reference local 10
var n = 10
// ^ definition local 8
// ^ definition local 10

if (forever()) {
// ^^^^^^^ reference pure-js 1.0.0 src/`main.js`/forever().
var m = 10
// ^ definition local 11
// ^ definition local 13
}
print_fib(m)
//^^^^^^^^^ reference pure-js 1.0.0 src/`main.js`/print_fib().
// ^ reference local 11
// ^ reference local 13
}

function var_function_scope() {
// ^^^^^^^^^^^^^^^^^^ definition pure-js 1.0.0 src/`main.js`/var_function_scope().
var k = 0
// ^ definition local 14
// ^ definition local 16
if (forever()) {
// ^^^^^^^ reference pure-js 1.0.0 src/`main.js`/forever().
var k = 1
// ^ definition local 17
// ^ definition local 19
}
print_fib(k)
//^^^^^^^^^ reference pure-js 1.0.0 src/`main.js`/print_fib().
// ^ reference local 14
// ^ reference local 17
// ^ reference local 16
// ^ reference local 19
}

38 changes: 19 additions & 19 deletions snapshots/output/react/src/LoaderInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import React from 'react'
interface Props {
// ^^^^^ definition react-example 1.0.0 src/`LoaderInput.tsx`/Props#
loading: boolean
//^^^^^^^ definition react-example 1.0.0 src/`LoaderInput.tsx`/Props#loading.
//^^^^^^^ definition react-example 1.0.0 src/`LoaderInput.tsx`/loading0:
children: React.ReactNode
//^^^^^^^^ definition react-example 1.0.0 src/`LoaderInput.tsx`/Props#children.
//^^^^^^^^ definition react-example 1.0.0 src/`LoaderInput.tsx`/children0:
// ^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/
// ^^^^^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/ReactNode#
}
Expand All @@ -21,37 +21,37 @@ export const LoaderInput: React.FunctionComponent<Props> = ({
// ^^^^^^^^^^^^^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/FunctionComponent#
// ^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#
loading,
//^^^^^^^ definition local 3
//^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#loading.
//^^^^^^^ definition local 4
//^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/loading0:
children,
//^^^^^^^^ definition local 4
//^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#children.
//^^^^^^^^ definition local 5
//^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/children0:
}) => (
<div className="hello">
// ^^^ reference @types/react 18.2.39 `index.d.ts`/global/JSX/IntrinsicElements#div.
// ^^^^^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/HTMLAttributes#className.
// ^^^ reference @types/react 18.2.39 `index.d.ts`/div0:
// ^^^^^^^^^ reference @types/react 18.2.39 `index.d.ts`/className0:
{children}
// ^^^^^^^^ reference local 4
// ^^^^^^^^ reference local 5
{loading && <p>spinner</p>}
// ^^^^^^^ reference local 3
// ^ reference @types/react 18.2.39 `index.d.ts`/global/JSX/IntrinsicElements#p.
// ^ reference @types/react 18.2.39 `index.d.ts`/global/JSX/IntrinsicElements#p.
// ^^^^^^^ reference local 4
// ^ reference @types/react 18.2.39 `index.d.ts`/p0:
// ^ reference @types/react 18.2.39 `index.d.ts`/p0:
</div>
// ^^^ reference @types/react 18.2.39 `index.d.ts`/global/JSX/IntrinsicElements#div.
// ^^^ reference @types/react 18.2.39 `index.d.ts`/div0:
)

export const LoaderInput2: React.FunctionComponent<Props> = props => {
// ^^^^^^^^^^^^ definition react-example 1.0.0 src/`LoaderInput.tsx`/LoaderInput2.
// ^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/
// ^^^^^^^^^^^^^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/FunctionComponent#
// ^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#
// ^^^^^ definition local 6
// ^^^^^ definition local 705
return <LoaderInput loading={true} key="key" children={props.children} />
// ^^^^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/LoaderInput.
// ^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#loading.
// ^^^ reference local 10
// ^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#children.
// ^^^^^ reference local 6
// ^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#children.
// ^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/loading0:
// ^^^ reference local 709
// ^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/children0:
// ^^^^^ reference local 705
// ^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/children0:
}

4 changes: 2 additions & 2 deletions snapshots/output/react/src/MyTSXElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export const MyTSXElement: React.FunctionComponent<MyProps> = ({}) => (<p></p>)
// ^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/
// ^^^^^^^^^^^^^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/FunctionComponent#
// ^^^^^^^ reference react-example 1.0.0 src/`MyTSXElement.tsx`/MyProps#
// ^ reference @types/react 18.2.39 `index.d.ts`/global/JSX/IntrinsicElements#p.
// ^ reference @types/react 18.2.39 `index.d.ts`/global/JSX/IntrinsicElements#p.
// ^ reference @types/react 18.2.39 `index.d.ts`/p0:
// ^ reference @types/react 18.2.39 `index.d.ts`/p0:
2 changes: 1 addition & 1 deletion snapshots/output/syntax/src/accessors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ function f() {
g(D.length)
//^ reference syntax 1.0.0 src/`accessors.ts`/g().
// ^ reference syntax 1.0.0 src/`accessors.ts`/D#
// ^^^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Function#length.
// ^^^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/length0:
}

Loading

0 comments on commit 198d8e7

Please sign in to comment.