forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdispatcher.ts
More file actions
54 lines (43 loc) · 1.37 KB
/
dispatcher.ts
File metadata and controls
54 lines (43 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import {
CancellationToken,
FormattingOptions,
OnTypeFormattingEditProvider,
Position,
ProviderResult,
TextDocument,
TextEdit
} from 'vscode';
export class OnTypeFormattingDispatcher implements OnTypeFormattingEditProvider {
private readonly providers: Record<string, OnTypeFormattingEditProvider>;
constructor(providers: Record<string, OnTypeFormattingEditProvider>) {
this.providers = providers;
}
public provideOnTypeFormattingEdits(
document: TextDocument,
position: Position,
ch: string,
options: FormattingOptions,
cancellationToken: CancellationToken
): ProviderResult<TextEdit[]> {
const provider = this.providers[ch];
if (provider) {
return provider.provideOnTypeFormattingEdits(document, position, ch, options, cancellationToken);
}
return [];
}
public getTriggerCharacters(): { first: string; more: string[] } | undefined {
const keys = Object.keys(this.providers);
keys.sort(); // Make output deterministic
const first = keys.shift();
if (first) {
return {
first: first,
more: keys
};
}
return undefined;
}
}