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

Commit 954d11f

Browse files
committed
feat: remove unused middleware feature
BREAKING CHANGE: Middleware for client features was removed.
1 parent 91ecd8a commit 954d11f

13 files changed

+12
-108
lines changed

src/client/client.ts

-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
InitializationFailedHandler,
3030
} from './errorHandler'
3131
import { DynamicFeature, RegistrationData, StaticFeature } from './features/common'
32-
import { Middleware } from './middleware'
3332

3433
/** Options for creating a new client. */
3534
export interface ClientOptions {
@@ -41,8 +40,6 @@ export interface ClientOptions {
4140
/** Called when an error or close occurs to determine how to proceed. */
4241
errorHandler?: ErrorHandler
4342

44-
middleware?: Readonly<Middleware>
45-
4643
/** Called to create the connection to the server. */
4744
createMessageTransports: () => MessageTransports | Promise<MessageTransports>
4845

@@ -64,7 +61,6 @@ export interface ClientOptions {
6461
interface ResolvedClientOptions extends Pick<ClientOptions, Exclude<keyof ClientOptions, 'trace'>> {
6562
initializationFailedHandler: InitializationFailedHandler
6663
errorHandler: ErrorHandler
67-
middleware: Readonly<Middleware>
6864
tracer: Tracer
6965
experimentalClientCapabilities: any
7066
}
@@ -123,7 +119,6 @@ export class Client implements Unsubscribable {
123119
...options,
124120
initializationFailedHandler: options.initializationFailedHandler || (() => Promise.resolve(false)),
125121
errorHandler: options.errorHandler || new DefaultErrorHandler(),
126-
middleware: options.middleware || {},
127122
tracer: options.tracer || noopTracer,
128123
experimentalClientCapabilities: options.experimentalClientCapabilities || {},
129124
}

src/client/features/configuration.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const create = (): {
99
configurationCascade: Subject<ConfigurationCascade>
1010
feature: ConfigurationChangeNotificationFeature<ConfigurationCascade>
1111
} => {
12-
const client = { options: { middleware: {} } } as Client
12+
const client = { options: {} } as Client
1313
const configurationCascade = new Subject<ConfigurationCascade>()
1414
const feature = new ConfigurationChangeNotificationFeature(client, configurationCascade)
1515
return { client, configurationCascade, feature }

src/client/features/context.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('ContextFeature', () => {
1212
client: Client
1313
feature: ContextFeature
1414
} => {
15-
const client = { options: { middleware: {} } } as Client
15+
const client = { options: {} } as Client
1616
const feature = new ContextFeature(
1717
client,
1818
setContext ||

src/client/features/decoration.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('TextDocumentDecorationFeature', () => {
1616
registry: TextDocumentDecorationProviderRegistry
1717
feature: TextDocumentDecorationFeature
1818
} => {
19-
const client = { options: { middleware: {} } } as Client
19+
const client = { options: {} } as Client
2020
const registry = new TextDocumentDecorationProviderRegistry()
2121
const feature = new TextDocumentDecorationFeature(client, registry)
2222
return { client, registry, feature }

src/client/features/decoration.ts

+1-13
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,9 @@ import { ProvideTextDocumentDecorationSignature } from '../../environment/provid
55
import { FeatureProviderRegistry } from '../../environment/providers/registry'
66
import { ClientCapabilities, ServerCapabilities } from '../../protocol'
77
import { TextDocumentDecoration, TextDocumentPublishDecorationsNotification } from '../../protocol/decoration'
8-
import { NextSignature } from '../../types/middleware'
98
import { Client } from '../client'
109
import { ensure, Feature } from './common'
1110

12-
export type ProvideTextDocumentDecorationMiddleware = NextSignature<
13-
TextDocumentIdentifier,
14-
Observable<TextDocumentDecoration[] | null>
15-
>
16-
1711
/**
1812
* Support for text document decorations published by the server (textDocument/publishDecorations notifications
1913
* from the server).
@@ -47,16 +41,10 @@ export class TextDocumentDecorationFeature extends Feature<undefined> {
4741
}
4842

4943
protected registerProvider(): Unsubscribable {
50-
const client = this.client
51-
const provideTextDocumentDecoration: ProvideTextDocumentDecorationSignature = textDocument =>
52-
this.getDecorationsSubject(textDocument)
53-
const middleware = client.options.middleware.provideTextDocumentDecoration
5444
return this.registry.registerProvider(
5545
undefined,
5646
(textDocument: TextDocumentIdentifier): Observable<TextDocumentDecoration[] | null> =>
57-
middleware
58-
? middleware(textDocument, provideTextDocumentDecoration)
59-
: provideTextDocumentDecoration(textDocument)
47+
this.getDecorationsSubject(textDocument)
6048
)
6149
}
6250

src/client/features/hover.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const create = (): {
1010
registry: TextDocumentHoverProviderRegistry
1111
feature: TextDocumentHoverFeature
1212
} => {
13-
const client = { options: { middleware: {} } } as Client
13+
const client = { options: {} } as Client
1414
const registry = new TextDocumentHoverProviderRegistry()
1515
const feature = new TextDocumentHoverFeature(client, registry)
1616
return { client, registry, feature }

src/client/features/hover.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@ import {
1111
TextDocumentRegistrationOptions,
1212
} from '../../protocol'
1313
import { DocumentSelector } from '../../types/document'
14-
import { NextSignature } from '../../types/middleware'
1514
import { Client } from '../client'
1615
import { ensure, Feature } from './common'
1716

18-
export type ProvideTextDocumentHoverMiddleware = NextSignature<TextDocumentPositionParams, Observable<Hover | null>>
19-
2017
/**
2118
* Support for hover messages (textDocument/hover requests to the server).
2219
*/
@@ -47,14 +44,10 @@ export class TextDocumentHoverFeature extends Feature<TextDocumentRegistrationOp
4744
}
4845

4946
protected registerProvider(options: TextDocumentRegistrationOptions): Unsubscribable {
50-
const client = this.client
51-
const provideTextDocumentHover: ProvideTextDocumentHoverSignature = params =>
52-
from(client.sendRequest(HoverRequest.type, params))
53-
const middleware = client.options.middleware.provideTextDocumentHover
5447
return this.registry.registerProvider(
5548
options,
5649
(params: TextDocumentPositionParams): Observable<Hover | null> =>
57-
middleware ? middleware(params, provideTextDocumentHover) : provideTextDocumentHover(params)
50+
from(this.client.sendRequest(HoverRequest.type, params))
5851
)
5952
}
6053
}

src/client/features/location.test.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
} from '../../protocol'
1010
import { Client } from '../client'
1111
import {
12-
ProvideTextDocumentLocationMiddleware,
1312
TextDocumentDefinitionFeature,
1413
TextDocumentImplementationFeature,
1514
TextDocumentLocationFeature,
@@ -25,7 +24,7 @@ const create = <P extends TextDocumentPositionParams, F extends TextDocumentLoca
2524
registry: TextDocumentLocationProviderRegistry<P>
2625
feature: F
2726
} => {
28-
const client = { options: { middleware: {} } } as Client
27+
const client = { options: {} } as Client
2928
const registry = new RegistryClass()
3029
const feature = new FeatureClass(client, registry)
3130
return { client, registry, feature }
@@ -43,9 +42,6 @@ describe('TextDocumentLocationFeature', () => {
4342
public isSupported(): boolean {
4443
return true
4544
}
46-
public getMiddleware(): ProvideTextDocumentLocationMiddleware | undefined {
47-
return undefined
48-
}
4945
},
5046
TextDocumentLocationProviderRegistry
5147
)
@@ -63,9 +59,6 @@ describe('TextDocumentLocationFeature', () => {
6359
public isSupported(): boolean {
6460
return false
6561
}
66-
public getMiddleware(): ProvideTextDocumentLocationMiddleware | undefined {
67-
return undefined
68-
}
6962
},
7063
TextDocumentLocationProviderRegistry
7164
)

src/client/features/location.ts

+1-40
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,9 @@ import {
1515
TypeDefinitionRequest,
1616
} from '../../protocol'
1717
import { DocumentSelector } from '../../types/document'
18-
import { NextSignature } from '../../types/middleware'
1918
import { Client } from '../client'
20-
import { Middleware } from '../middleware'
2119
import { ensure, Feature } from './common'
2220

23-
export type ProvideTextDocumentLocationMiddleware<
24-
P extends TextDocumentPositionParams = TextDocumentPositionParams,
25-
L extends Location = Location
26-
> = NextSignature<P, Observable<L | L[] | null>>
27-
2821
/**
2922
* Support for requests that retrieve a list of locations (e.g., textDocument/definition,
3023
* textDocument/implementation, and textDocument/typeDefinition).
@@ -49,9 +42,6 @@ export abstract class TextDocumentLocationFeature<
4942
/** Override to compute whether the server capabilities report support for this feature. */
5043
protected abstract isSupported(capabilities: ServerCapabilities): boolean
5144

52-
/** Override to return the middleware for this feature. */
53-
protected abstract getMiddleware?(midleware: Middleware): ProvideTextDocumentLocationMiddleware<P, L> | undefined
54-
5545
public initialize(capabilities: ServerCapabilities, documentSelector: DocumentSelector): void {
5646
if (!this.isSupported(capabilities) || !documentSelector) {
5747
return
@@ -63,14 +53,9 @@ export abstract class TextDocumentLocationFeature<
6353
}
6454

6555
protected registerProvider(options: TextDocumentRegistrationOptions): Unsubscribable {
66-
const client = this.client
67-
const provideTextDocumentLocation: ProvideTextDocumentLocationSignature<P, L> = params =>
68-
from(client.sendRequest(this.messages, params))
69-
const middleware = this.getMiddleware ? this.getMiddleware(client.options.middleware) : undefined
7056
return this.registry.registerProvider(
7157
options,
72-
(params: P): Observable<L | L[] | null> =>
73-
middleware ? middleware(params, provideTextDocumentLocation) : provideTextDocumentLocation(params)
58+
(params: P): Observable<L | L[] | null> => from(this.client.sendRequest(this.messages, params))
7459
)
7560
}
7661
}
@@ -89,12 +74,6 @@ export class TextDocumentDefinitionFeature extends TextDocumentLocationFeature {
8974
protected isSupported(capabilities: ServerCapabilities): boolean {
9075
return !!capabilities.definitionProvider
9176
}
92-
93-
protected getMiddleware(
94-
middleware: Middleware
95-
): ProvideTextDocumentLocationMiddleware<TextDocumentPositionParams, Location> | undefined {
96-
return middleware.provideTextDocumentDefinition
97-
}
9877
}
9978

10079
/**
@@ -111,12 +90,6 @@ export class TextDocumentImplementationFeature extends TextDocumentLocationFeatu
11190
protected isSupported(capabilities: ServerCapabilities): boolean {
11291
return !!capabilities.implementationProvider
11392
}
114-
115-
protected getMiddleware(
116-
middleware: Middleware
117-
): ProvideTextDocumentLocationMiddleware<TextDocumentPositionParams, Location> | undefined {
118-
return middleware.provideTextDocumentImplementation
119-
}
12093
}
12194

12295
/**
@@ -133,12 +106,6 @@ export class TextDocumentTypeDefinitionFeature extends TextDocumentLocationFeatu
133106
protected isSupported(capabilities: ServerCapabilities): boolean {
134107
return !!capabilities.typeDefinitionProvider
135108
}
136-
137-
protected getMiddleware(
138-
middleware: Middleware
139-
): ProvideTextDocumentLocationMiddleware<TextDocumentPositionParams, Location> | undefined {
140-
return middleware.provideTextDocumentTypeDefinition
141-
}
142109
}
143110

144111
/**
@@ -155,10 +122,4 @@ export class TextDocumentReferencesFeature extends TextDocumentLocationFeature<R
155122
protected isSupported(capabilities: ServerCapabilities): boolean {
156123
return !!capabilities.referencesProvider
157124
}
158-
159-
protected getMiddleware(
160-
middleware: Middleware
161-
): ProvideTextDocumentLocationMiddleware<ReferenceParams> | undefined {
162-
return middleware.provideTextDocumentReferences
163-
}
164125
}

src/client/features/textDocument.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('TextDocumentNotificationFeature', () => {
3333

3434
class TextDocumentNotificationFeature extends AbstractTextDocumentNotificationFeature<any, any> {
3535
constructor(client: Client) {
36-
super(client, new Subject<any>(), DidOpenTextDocumentNotification.type, undefined, () => void 0)
36+
super(client, new Subject<any>(), DidOpenTextDocumentNotification.type, () => void 0)
3737
}
3838
public readonly messages = { method: 'm' }
3939
public fillClientCapabilities(): void {
@@ -83,7 +83,7 @@ describe('TextDocumentDidOpenFeature', () => {
8383
feature: TextDocumentDidOpenFeature & { readonly selectors: Map<string, DocumentSelector> }
8484
} => {
8585
const environment = new BehaviorSubject<Environment>(EMPTY_ENVIRONMENT)
86-
const client = { options: { middleware: {} } } as Client
86+
const client = { options: {} } as Client
8787
const feature = new class extends TextDocumentDidOpenFeature {
8888
public readonly selectors!: Map<string, DocumentSelector>
8989
}(client, createObservableEnvironment(environment).textDocument)
@@ -163,7 +163,7 @@ describe('TextDocumentDidCloseFeature', () => {
163163
feature: TextDocumentDidCloseFeature & { readonly selectors: Map<string, DocumentSelector> }
164164
} => {
165165
const environment = new BehaviorSubject<Environment>(EMPTY_ENVIRONMENT)
166-
const client = { options: { middleware: {} } } as Client
166+
const client = { options: {} } as Client
167167
const feature = new class extends TextDocumentDidCloseFeature {
168168
public readonly selectors!: Map<string, DocumentSelector>
169169
}(client, createObservableEnvironment(environment).textDocument)

src/client/features/textDocument.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
TextDocumentRegistrationOptions,
1414
} from '../../protocol'
1515
import { DocumentSelector } from '../../types/document'
16-
import { NextSignature } from '../../types/middleware'
1716
import { match } from '../../types/textDocument'
1817
import { Client } from '../client'
1918
import { DynamicFeature, ensure, RegistrationData } from './common'
@@ -29,7 +28,6 @@ export abstract class TextDocumentNotificationFeature<P, E> implements DynamicFe
2928
protected client: Client,
3029
protected observable: Observable<E>,
3130
protected type: NotificationType<P, TextDocumentRegistrationOptions>,
32-
protected middleware: NextSignature<E, void> | undefined,
3331
protected createParams: CreateParamsSignature<E, P>,
3432
protected selectorFilter?: (selectors: IterableIterator<DocumentSelector>, data: E) => boolean
3533
) {}
@@ -55,11 +53,7 @@ export abstract class TextDocumentNotificationFeature<P, E> implements DynamicFe
5553

5654
private callback(data: E): void {
5755
if (!this.selectorFilter || this.selectorFilter(this.selectors.values(), data)) {
58-
if (this.middleware) {
59-
this.middleware(data, data => this.client.sendNotification(this.type, this.createParams(data)))
60-
} else {
61-
this.client.sendNotification(this.type, this.createParams(data))
62-
}
56+
this.client.sendNotification(this.type, this.createParams(data))
6357
this.notificationSent(data)
6458
}
6559
}
@@ -101,7 +95,6 @@ export class TextDocumentDidOpenFeature extends TextDocumentNotificationFeature<
10195
client,
10296
environmentTextDocument.pipe(filter((v): v is TextDocumentItem => v !== null)),
10397
DidOpenTextDocumentNotification.type,
104-
client.options.middleware.didOpen,
10598
textDocument =>
10699
({
107100
textDocument,
@@ -147,7 +140,6 @@ export class TextDocumentDidCloseFeature extends TextDocumentNotificationFeature
147140
map(([closedDocument]) => closedDocument)
148141
),
149142
DidCloseTextDocumentNotification.type,
150-
client.options.middleware.didClose,
151143
textDocument =>
152144
({
153145
textDocument: { uri: textDocument.uri },

src/client/middleware.ts

-17
This file was deleted.

src/environment/controller.ts

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ export interface ControllerOptions<X extends Extension, C extends ConfigurationC
7474
extension: X
7575
) => Pick<
7676
ClientOptions,
77-
| 'middleware'
7877
| 'createMessageTransports'
7978
| 'errorHandler'
8079
| 'initializationFailedHandler'

0 commit comments

Comments
 (0)