Skip to content
This repository was archived by the owner on Nov 25, 2021. It is now read-only.

Commit 6e746cf

Browse files
committed
refactor: use @sourcegraph/extension-api-types instead of vscode types
1 parent 0151c73 commit 6e746cf

File tree

10 files changed

+36
-18
lines changed

10 files changed

+36
-18
lines changed

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
"author": "Felix Becker <[email protected]>",
3131
"dependencies": {
3232
"@sourcegraph/event-positions": "^1.0.0",
33+
"@sourcegraph/extension-api-types": "^1.0.1",
3334
"@sourcegraph/react-loading-spinner": "0.0.7",
3435
"lodash": "^4.17.10",
3536
"mdi-react": "^5.1.0",
3637
"rxjs": "^6.3.3",
37-
"ts-key-enum": "^2.0.0",
38-
"vscode-languageserver-types": "^3.8.2"
38+
"ts-key-enum": "^2.0.0"
3939
},
4040
"peerDependencies": {
4141
"react": "^16.0.0"

src/hoverifier.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import { Range } from '@sourcegraph/extension-api-types'
12
import { isEqual } from 'lodash'
23
import { EMPTY, NEVER, Observable, of, Subject, Subscription } from 'rxjs'
34
import { distinctUntilChanged, filter, map } from 'rxjs/operators'
45
import { TestScheduler } from 'rxjs/testing'
5-
import { Range } from 'vscode-languageserver-types'
66

77
import { noop } from 'lodash'
88
import { propertyIsDefined } from './helpers'
@@ -205,7 +205,6 @@ describe('Hoverifier', () => {
205205
fetchJumpURL: position =>
206206
position.line === 24 ? createStubJumpURLFetcher('def url', delayTime)(position) : of(null),
207207
pushHistory: noop,
208-
getReferencesURL: () => null,
209208
})
210209

211210
const positionJumps = new Subject<PositionJump>()
@@ -278,7 +277,6 @@ describe('Hoverifier', () => {
278277
fetchJumpURL: position =>
279278
position.line === 24 ? createStubJumpURLFetcher('def url')(position) : of(null),
280279
pushHistory: noop,
281-
getReferencesURL: () => null,
282280
})
283281

284282
const positionJumps = new Subject<PositionJump>()

src/hoverifier.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Position, Range } from '@sourcegraph/extension-api-types'
12
import { isEqual } from 'lodash'
23
import {
34
combineLatest,
@@ -27,7 +28,6 @@ import {
2728
withLatestFrom,
2829
} from 'rxjs/operators'
2930
import { Key } from 'ts-key-enum'
30-
import { Position, Range } from 'vscode-languageserver-types'
3131
import { asError, ErrorLike, isErrorLike } from './errors'
3232
import { scrollIntoCenterIfNeeded } from './helpers'
3333
import { HoverOverlayProps, isJumpURL } from './HoverOverlay'
@@ -42,7 +42,7 @@ import {
4242
getTokenAtPosition,
4343
HoveredToken,
4444
} from './token_position'
45-
import { HoverAttachment, isHoverAttachmentWithRange, LineOrPositionOrRange, LOADING } from './types'
45+
import { HoverAttachment, isHoverAttachmentWithRange, isPosition, LineOrPositionOrRange, LOADING } from './types'
4646

4747
export { HoveredToken }
4848

@@ -437,7 +437,7 @@ export function createHoverifier<C extends object>({
437437
let cell: HTMLElement | null
438438
let target: HTMLElement | undefined
439439
let part: DiffPart | undefined
440-
if (Position.is(position)) {
440+
if (isPosition(position)) {
441441
cell = dom.getCodeElementFromLineNumber(codeView, position.line, position.part)
442442
if (cell) {
443443
target = findElementWithOffset(cell, position.character)
@@ -479,7 +479,7 @@ export function createHoverifier<C extends object>({
479479
})
480480
),
481481
switchMap(({ position, codeView, adjustPosition, resolveContext, ...rest }) => {
482-
if (!position || !Position.is(position) || !adjustPosition) {
482+
if (!position || !isPosition(position) || !adjustPosition) {
483483
return of({ position, codeView, ...rest })
484484
}
485485

@@ -502,7 +502,7 @@ export function createHoverifier<C extends object>({
502502
// that tokens span multiple elements meaning that it's possible for the hover overlay to be
503503
// placed in the middle of a token.
504504
target:
505-
position && Position.is(position)
505+
position && isPosition(position)
506506
? getTokenAtPosition(codeView, position, dom, position.part)
507507
: target,
508508
...rest,
@@ -522,7 +522,7 @@ export function createHoverifier<C extends object>({
522522
map(({ position, resolveContext, eventType, ...rest }) => ({
523523
...rest,
524524
eventType,
525-
position: Position.is(position) ? { ...position, ...resolveContext(position) } : undefined,
525+
position: isPosition(position) ? { ...position, ...resolveContext(position) } : undefined,
526526
})),
527527
share()
528528
)

src/positions.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { Position } from '@sourcegraph/extension-api-types'
12
import { of } from 'rxjs'
23
import { filter, map } from 'rxjs/operators'
34
import { TestScheduler } from 'rxjs/testing'
4-
import { Position } from 'vscode-languageserver-types'
55

66
import { CodeViewProps, DOM } from './testutils/dom'
77
import { dispatchMouseEventAtPositionImpure } from './testutils/mouse'

src/positions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { from, fromEvent, merge, Observable, Subscribable } from 'rxjs'
22
import { filter, map, switchMap, tap } from 'rxjs/operators'
3-
import { Position } from 'vscode-languageserver-types'
43
import { convertCodeElementIdempotent, DiffPart, DOMFunctions, HoveredToken, locateTarget } from './token_position'
4+
import { isPosition } from './types'
55

66
export type SupportedMouseEvent = 'click' | 'mousemove' | 'mouseover'
77

@@ -70,7 +70,7 @@ export const findPositionsFromEvents = (options: DOMFunctions) => (
7070
// Find out the position that was hovered over
7171
map(({ target, codeView, ...rest }) => {
7272
const hoveredToken = locateTarget(target, options)
73-
const position = Position.is(hoveredToken) ? hoveredToken : undefined
73+
const position = isPosition(hoveredToken) ? hoveredToken : undefined
7474
return { position, codeView, ...rest }
7575
})
7676
)

src/testutils/mouse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CharacterPositions } from '@sourcegraph/event-positions'
2-
import { Position } from 'vscode-languageserver-types'
2+
import { Position } from '@sourcegraph/extension-api-types'
33
import { convertNode } from '../token_position'
44
import { CodeViewProps } from './dom'
55

src/token_position.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { Position } from '@sourcegraph/extension-api-types'
12
import * as assert from 'assert'
2-
import { Position } from 'vscode-languageserver-types'
33
import { CodeViewProps, DOM } from './testutils/dom'
44
import {
55
convertNode,

src/token_position.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Position } from 'vscode-languageserver-types'
1+
import { Position } from '@sourcegraph/extension-api-types'
22
import { LineOrPositionOrRange } from './types'
33

44
/**

src/types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Range } from 'vscode-languageserver-types'
1+
import { Position, Range } from '@sourcegraph/extension-api-types'
22

33
export const LOADING: 'loading' = 'loading'
44

@@ -28,6 +28,13 @@ export function isHoverAttachmentWithRange(value: any): value is HoverAttachment
2828
)
2929
}
3030

31+
/**
32+
* Reports whether {@link value} is a {@link Position}.
33+
*/
34+
export function isPosition(value: any): value is Position {
35+
return value && typeof value.line === 'number' && typeof value.character === 'number'
36+
}
37+
3138
/**
3239
* Represents a line, a position, a line range, or a position range. It forbids
3340
* just a character, or a range from a line to a position or vice versa (such as

0 commit comments

Comments
 (0)