提交 235c1b32 编写于 作者: M Matt Bierner

Use const enums for state and move state into namespace

上级 6ac9ea2a
......@@ -18,18 +18,25 @@ export interface TriggerContext {
readonly triggerCharacter?: string;
}
const DefaultState = new class { readonly type = 'default'; };
const PendingState = new class { readonly type = 'pending'; };
namespace ParameterHintState {
export const enum Type {
Default,
Active,
Pending,
}
export const Default = new class { readonly type = Type.Default; };
export const Pending = new class { readonly type = Type.Pending; };
class ActiveState {
static readonly type = 'active';
readonly type = ActiveState.type;
export class Active {
readonly type = Type.Active;
constructor(
readonly hints: modes.SignatureHelp
) { }
}
}
type ParameterHintState = typeof DefaultState | typeof PendingState | ActiveState;
export type State = typeof Default | typeof Pending | Active;
}
export class ParameterHintsModel extends Disposable {
......@@ -40,7 +47,7 @@ export class ParameterHintsModel extends Disposable {
private editor: ICodeEditor;
private enabled: boolean;
private state: ParameterHintState = DefaultState;
private state: ParameterHintState.State = ParameterHintState.Default;
private triggerChars = new CharacterSet();
private retriggerChars = new CharacterSet();
......@@ -72,7 +79,7 @@ export class ParameterHintsModel extends Disposable {
}
cancel(silent: boolean = false): void {
this.state = DefaultState;
this.state = ParameterHintState.Default;
this.throttledDelayer.cancel();
......@@ -97,13 +104,13 @@ export class ParameterHintsModel extends Disposable {
() => this.doTrigger({
triggerKind: context.triggerKind,
triggerCharacter: context.triggerCharacter,
isRetrigger: this.state.type === ActiveState.type || this.state.type === PendingState.type,
activeSignatureHelp: this.state.type === ActiveState.type ? this.state.hints : undefined
isRetrigger: this.state.type === ParameterHintState.Type.Active || this.state.type === ParameterHintState.Type.Pending,
activeSignatureHelp: this.state.type === ParameterHintState.Type.Active ? this.state.hints : undefined
}, triggerId), delay).then(undefined, onUnexpectedError);
}
public next(): void {
if (this.state.type !== ActiveState.type) {
if (this.state.type !== ParameterHintState.Type.Active) {
return;
}
......@@ -122,7 +129,7 @@ export class ParameterHintsModel extends Disposable {
}
public previous(): void {
if (this.state.type !== ActiveState.type) {
if (this.state.type !== ParameterHintState.Type.Active) {
return;
}
......@@ -141,11 +148,11 @@ export class ParameterHintsModel extends Disposable {
}
private updateActiveSignature(activeSignature: number) {
if (this.state.type !== ActiveState.type) {
if (this.state.type !== ParameterHintState.Type.Active) {
return;
}
this.state = new ActiveState({ ...this.state.hints, activeSignature });
this.state = new ParameterHintState.Active({ ...this.state.hints, activeSignature });
this._onChangedHints.fire(this.state.hints);
}
......@@ -159,7 +166,7 @@ export class ParameterHintsModel extends Disposable {
const model = this.editor.getModel();
const position = this.editor.getPosition();
this.state = PendingState;
this.state = ParameterHintState.Pending;
this.provideSignatureHelpRequest = createCancelablePromise(token =>
provideSignatureHelp(model, position, triggerContext, token));
......@@ -174,20 +181,20 @@ export class ParameterHintsModel extends Disposable {
this.cancel();
return false;
} else {
this.state = new ActiveState(result);
this.state = new ParameterHintState.Active(result);
this._onChangedHints.fire(this.state.hints);
return true;
}
}).catch(error => {
this.state = DefaultState;
this.state = ParameterHintState.Default;
onUnexpectedError(error);
return false;
});
}
private get isTriggered(): boolean {
return this.state.type === ActiveState.type
|| this.state.type === PendingState.type
return this.state.type === ParameterHintState.Type.Active
|| this.state.type === ParameterHintState.Type.Pending
|| this.throttledDelayer.isTriggered();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册