Skip to content

Commit d9e969c

Browse files
authored
Emit occurrences for string literals (#184)
* Emit occurrences for string literals Previously, scip-typescript only emitted occurrences for identifiers. Now, we additionally emit occurrences for string literals so that features like "Go to definition" work with `import` statements and other locations where string literals reference actual symbols. * Prettier * Remove cwd from documentation signatures for stable SCIP output * Use replace instead of replaceAll for Node v14 compatibility * Include the file extension in the module name
1 parent 92b952c commit d9e969c

28 files changed

+165
-11
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"editor.formatOnSave": true
3+
}

snapshots/input/syntax/src/import.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ export function useEverything(): string {
1111
newFunction()
1212
)
1313
}
14+
15+
export function dynamicImport(): Promise<void> {
16+
return import('./function').then(c => c.newFunction())
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
interface SomeInterface {
2+
a: number
3+
b: number
4+
c: number
5+
}
6+
// "Go to definition" does not work for the 'a', 'b' and 'c' string literals
7+
// below when using tsserver so it's fine that scip-typescript does not emit
8+
// occurrences here either.
9+
export type OmitInterface = Omit<SomeInterface, 'a' | 'b'>
10+
export type PickInterface = Pick<SomeInterface, 'b' | 'c'>

snapshots/output/multi-project/packages/a/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export function a(): string {
2+
// definition @example/a 1.0.0 src/`index.ts`/
3+
//documentation ```ts\nmodule "index.ts"\n```
24
// ^ definition @example/a 1.0.0 src/`index.ts`/a().
35
// documentation ```ts\nfunction a(): string\n```
46
return ''

snapshots/output/multi-project/packages/b/src/b.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { a } from '@example/a/src'
2+
// definition @example/b 1.0.0 src/`b.ts`/
3+
//documentation ```ts\nmodule "b.ts"\n```
24
// ^ reference @example/a 1.0.0 src/`index.ts`/a().
5+
// ^^^^^^^^^^^^^^^^ reference @example/a 1.0.0 src/`index.ts`/
36

47
export function b() {
58
// ^ definition @example/b 1.0.0 src/`b.ts`/b().

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
function fib(n) {
2+
// definition pure-js 1.0.0 src/`main.js`/
3+
//documentation ```ts\nmodule "main.js"\n```
24
// ^^^ definition pure-js 1.0.0 src/`main.js`/fib().
35
// documentation ```ts\nfunction fib(n: any): any\n```
46
// ^ definition pure-js 1.0.0 src/`main.js`/fib().(n)

snapshots/output/react/src/LoaderInput.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import React from 'react'
2+
// definition react-example 1.0.0 src/`LoaderInput.tsx`/
3+
//documentation ```ts\nmodule "LoaderInput.tsx"\n```
24
// ^^^^^ reference @types/react 17.0.0 `index.d.ts`/React/
5+
// ^^^^^^^ reference @types/react 17.0.0 `index.d.ts`/
36

47
/** Takes loading prop, input component as child */
58
interface Props {

snapshots/output/react/src/MyTSXElement.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import React from 'react'
2+
// definition react-example 1.0.0 src/`MyTSXElement.tsx`/
3+
//documentation ```ts\nmodule "MyTSXElement.tsx"\n```
24
// ^^^^^ reference @types/react 17.0.0 `index.d.ts`/React/
5+
// ^^^^^^^ reference @types/react 17.0.0 `index.d.ts`/
36

47
export interface MyProps {}
58
// ^^^^^^^ definition react-example 1.0.0 src/`MyTSXElement.tsx`/MyProps#

snapshots/output/react/src/UseMyTSXElement.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import React from "react";
2+
// definition react-example 1.0.0 src/`UseMyTSXElement.tsx`/
3+
//documentation ```ts\nmodule "UseMyTSXElement.tsx"\n```
24
// ^^^^^ reference @types/react 17.0.0 `index.d.ts`/React/
5+
// ^^^^^^^ reference @types/react 17.0.0 `index.d.ts`/
36

47
import { MyProps, MyTSXElement } from "./MyTSXElement";
58
// ^^^^^^^ reference react-example 1.0.0 src/`MyTSXElement.tsx`/MyProps#
69
// ^^^^^^^^^^^^ reference react-example 1.0.0 src/`MyTSXElement.tsx`/MyTSXElement.
10+
// ^^^^^^^^^^^^^^^^ reference react-example 1.0.0 src/`MyTSXElement.tsx`/
711

812
export const _: React.FunctionComponent<MyProps> =
913
// ^ definition react-example 1.0.0 src/`UseMyTSXElement.tsx`/_.

snapshots/output/syntax/src/accessors.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class C {
2+
// definition syntax 1.0.0 src/`accessors.ts`/
3+
//documentation ```ts\nmodule "accessors.ts"\n```
24
// ^ definition syntax 1.0.0 src/`accessors.ts`/C#
35
// documentation ```ts\nclass C\n```
46
_length: number = 0

0 commit comments

Comments
 (0)