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 97ce0d9
Show file tree
Hide file tree
Showing 40 changed files with 7,361 additions and 495 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 }
51 changes: 0 additions & 51 deletions snapshots/output/enclosing-ranges-ts/index.ts

This file was deleted.

79 changes: 0 additions & 79 deletions snapshots/output/enclosing-ranges/range.js

This file was deleted.

7 changes: 0 additions & 7 deletions snapshots/output/invalid-package-json/packages/a/src/a.ts

This file was deleted.

15 changes: 0 additions & 15 deletions snapshots/output/multi-project/packages/a/src/index.ts

This file was deleted.

12 changes: 0 additions & 12 deletions snapshots/output/multi-project/packages/b/src/b.ts

This file was deleted.

7 changes: 0 additions & 7 deletions snapshots/output/pnpm-workspaces/packages/a/src/a.ts

This file was deleted.

12 changes: 0 additions & 12 deletions snapshots/output/pnpm-workspaces/packages/b/src/b.ts

This file was deleted.

Loading

0 comments on commit 97ce0d9

Please sign in to comment.