Skip to content

Commit db9cd63

Browse files
committed
fix: remove deprecated API
BREAKING CHANGE: Extensions that still use these APIs can not be tested anymore with this version of the stubs.
1 parent b671c17 commit db9cd63

File tree

3 files changed

+12
-40
lines changed

3 files changed

+12
-40
lines changed

src/api.ts

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,7 @@ import { BehaviorSubject, Subject, Subscription } from 'rxjs'
33
import { mapTo } from 'rxjs/operators'
44
import * as sinon from 'sinon'
55
import * as sourcegraph from 'sourcegraph'
6-
import { deprecate } from 'util'
7-
import { assertTypeIsCompatible, notImplemented } from './util'
8-
9-
interface DeprecatedTypeDefinitionProvider {
10-
provideTypeDefinition(
11-
document: sourcegraph.TextDocument,
12-
position: Position
13-
): sourcegraph.ProviderResult<sourcegraph.Definition>
14-
}
15-
16-
interface DeprecatedImplementationProvider {
17-
provideImplementation(
18-
document: sourcegraph.TextDocument,
19-
position: Position
20-
): sourcegraph.ProviderResult<sourcegraph.Definition>
21-
}
6+
import { notImplemented, subTypeOf } from './util'
227

238
let decorationTypeCounter = 0
249

@@ -30,7 +15,7 @@ export const createStubSourcegraphAPI = () => {
3015
const configSubject = new BehaviorSubject<any>({})
3116
const rootChanges = new Subject<void>()
3217
const openedTextDocuments = new Subject<sourcegraph.TextDocument>()
33-
const stubs /* : typeof import('sourcegraph') */ = {
18+
const stubs = subTypeOf<typeof import('sourcegraph')>()({
3419
// Classes
3520
URI: URL,
3621
Position,
@@ -75,20 +60,6 @@ export const createStubSourcegraphAPI = () => {
7560
(selector: sourcegraph.DocumentSelector, provider: sourcegraph.CompletionItemProvider) =>
7661
new Subscription()
7762
),
78-
registerTypeDefinitionProvider: sinon.spy(
79-
deprecate(
80-
(selector: sourcegraph.DocumentSelector, provider: DeprecatedTypeDefinitionProvider) =>
81-
new Subscription(),
82-
'sourcegraph.languages.registerTypeDefinitionProvider() is deprecated. Use sourcegraph.languages.registerLocationProvider() instead.'
83-
)
84-
),
85-
registerImplementationProvider: sinon.spy(
86-
deprecate(
87-
(selector: sourcegraph.DocumentSelector, provider: DeprecatedImplementationProvider) =>
88-
new Subscription(),
89-
'sourcegraph.languages.registerImplementationProvider() is deprecated. Use sourcegraph.languages.registerLocationProvider() instead.'
90-
)
91-
),
9263
},
9364
app: {
9465
windows: [] as sourcegraph.Window[],
@@ -98,7 +69,7 @@ export const createStubSourcegraphAPI = () => {
9869
activeWindowChanges: new BehaviorSubject<sourcegraph.Window | undefined>(undefined),
9970

10071
createDecorationType: () => ({ key: 'decorationType' + decorationTypeCounter++ }),
101-
createPanelView: notImplemented as ((id: string) => sourcegraph.PanelView),
72+
createPanelView: notImplemented as (id: string) => sourcegraph.PanelView,
10273
},
10374
configuration: Object.assign(configSubject.pipe(mapTo(undefined)), {
10475
get: <C extends object = { [key: string]: any }>(): sourcegraph.Configuration<C> => ({
@@ -123,7 +94,6 @@ export const createStubSourcegraphAPI = () => {
12394
registerCommand: sinon.spy((command: string, callback: (...args: any[]) => any) => new Subscription()),
12495
executeCommand: sinon.spy<(command: string, ...args: any[]) => Promise<any>>(notImplemented),
12596
},
126-
}
127-
assertTypeIsCompatible<typeof sourcegraph>(stubs)
97+
})
12898
return stubs
12999
}

src/context.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import { Subscription } from 'rxjs'
22
import * as sinon from 'sinon'
33
import { ExtensionContext } from 'sourcegraph'
4-
import { assertTypeIsCompatible } from './util'
4+
import { subTypeOf } from './util'
55

66
export const createStubExtensionContext = () => {
77
const subscriptions = sinon.stub(new Subscription())
88
subscriptions.add.callThrough()
99
subscriptions.remove.callThrough()
1010
subscriptions.unsubscribe.callThrough()
11-
const context = {
11+
const context = subTypeOf<ExtensionContext>()({
1212
subscriptions,
13-
}
14-
assertTypeIsCompatible<ExtensionContext>(context)
13+
})
1514
return context
1615
}

src/util.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
/**
2-
* Compile-time helper to assert a given type.
2+
* Identity-function helper to ensure a value `T` is a subtype of `U`.
3+
*
4+
* @template U The type to check for (explicitly specify this)
5+
* @template T The actual type (inferred, don't specify this)
36
*/
4-
export const assertTypeIsCompatible = <T>(val: T): void => undefined
7+
export const subTypeOf = <U>() => <T extends U>(value: T): T => value
58

69
export function notImplemented(): never {
710
throw new Error('Stub functionality not implemented')

0 commit comments

Comments
 (0)