Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions snapshots/input/enclosing-ranges-ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@ enum SimpleEnum {
type SimpleTypeAlias = SimpleEnum

type ComplexTypeAlias<T> = Single<Single<T>>

type PageLoad = () => Promise<number>

export const load: PageLoad = async () => {
return 42
}

const first = () => 1,
second = () => 2
27 changes: 27 additions & 0 deletions snapshots/output/enclosing-ranges-ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,31 @@ type ComplexTypeAlias<T> = Single<Single<T>>
// ^ reference enclosing-ranges-ts 1.0.0 `index.ts`/ComplexTypeAlias#[T]
// < end enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/ComplexTypeAlias#

// < start enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/PageLoad#
type PageLoad = () => Promise<number>
// ^^^^^^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/PageLoad#
// ^^^^^^^ reference typescript 6.0.3 lib/`lib.es5.d.ts`/Promise#
// ^^^^^^^ reference typescript 6.0.3 lib/`lib.es2015.iterable.d.ts`/Promise#
// ^^^^^^^ reference typescript 6.0.3 lib/`lib.es2015.promise.d.ts`/Promise.
// ^^^^^^^ reference typescript 6.0.3 lib/`lib.es2015.symbol.wellknown.d.ts`/Promise#
// ^^^^^^^ reference typescript 6.0.3 lib/`lib.es2018.promise.d.ts`/Promise#
// < end enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/PageLoad#

// < start enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/load.
export const load: PageLoad = async () => {
// ^^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/load.
// ^^^^^^^^ reference enclosing-ranges-ts 1.0.0 `index.ts`/PageLoad#
return 42
}
// < end enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/load.

// ⌄ start enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/first.
const first = () => 1,
// ^^^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/first.
// ^ end enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/first.
// ⌄ start enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/second.
second = () => 2
//^^^^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/second.
// ^ end enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/second.

// < end enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/
4 changes: 2 additions & 2 deletions snapshots/output/enclosing-ranges/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

// format-options: showRanges

// < start enclosing_range enclosing-ranges 0.0.1 `range.js`/test.
// < start enclosing_range enclosing-ranges 0.0.1 `range.js`/
// ⌄ start enclosing_range enclosing-ranges 0.0.1 `range.js`/test.
const test = () => {
// ^^^^ definition enclosing-ranges 0.0.1 `range.js`/test.
const a = 'a'
Expand All @@ -16,7 +16,7 @@ const test = () => {
// ^ reference local 2
// ^ reference local 5
}
// ^ end enclosing_range enclosing-ranges 0.0.1 `range.js`/test.
// < end enclosing_range enclosing-ranges 0.0.1 `range.js`/test.

// < start enclosing_range enclosing-ranges 0.0.1 `range.js`/test2().
function test2() {
Expand Down
12 changes: 11 additions & 1 deletion src/FileIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,17 @@ export class FileIndexer {
declaration.initializer &&
ts.isFunctionLike(declaration.initializer)
) {
enclosingRange = Range.fromNode(declaration.initializer).toLsif()
// Cover the whole `export const name = ...` statement so the range
// encloses the name. Fall back to the declaration itself when the
// statement has several declarations or there is no statement (e.g.
// a `for` loop initializer).
const statement = declaration.parent.parent
enclosingRange = Range.fromNode(
ts.isVariableStatement(statement) &&
statement.declarationList.declarations.length === 1
? statement
: declaration
).toLsif()
} else if (
ts.isFunctionDeclaration(declaration) ||
ts.isEnumDeclaration(declaration) ||
Expand Down
Loading