parameterHintsWidget.ts 16.9 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6 7 8
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';

import 'vs/css!./parameterHints';
9
import * as nls from 'vs/nls';
J
Joao Moreno 已提交
10
import { IDisposable, dispose, Disposable } from 'vs/base/common/lifecycle';
J
Joao Moreno 已提交
11
import { TPromise } from 'vs/base/common/winjs.base';
J
Joao Moreno 已提交
12
import * as dom from 'vs/base/browser/dom';
13
import * as aria from 'vs/base/browser/ui/aria/aria';
J
Joao Moreno 已提交
14
import { SignatureHelp, SignatureInformation, SignatureHelpProviderRegistry } from 'vs/editor/common/modes';
J
Joao Moreno 已提交
15
import { ContentWidgetPositionPreference, ICodeEditor, IContentWidget, IContentWidgetPosition } from 'vs/editor/browser/editorBrowser';
J
Joao Moreno 已提交
16 17
import { RunOnceScheduler } from 'vs/base/common/async';
import { onUnexpectedError } from 'vs/base/common/errors';
M
Matt Bierner 已提交
18
import { Event, Emitter, chain } from 'vs/base/common/event';
J
Johannes Rieken 已提交
19
import { domEvent, stop } from 'vs/base/browser/event';
A
Alex Dima 已提交
20
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
21
import { Context, provideSignatureHelp } from 'vs/editor/contrib/parameterHints/provideSignatureHelp';
J
Johannes Rieken 已提交
22
import { DomScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement';
A
Alex Dima 已提交
23
import { CharacterSet } from 'vs/editor/common/core/characterClassifier';
24 25
import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions';
import { ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
26
import { registerThemingParticipant, HIGH_CONTRAST } from 'vs/platform/theme/common/themeService';
27
import { editorHoverBackground, editorHoverBorder, textLinkForeground, textCodeBlockBackground } from 'vs/platform/theme/common/colorRegistry';
28 29
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { IModeService } from 'vs/editor/common/services/modeService';
30
import { MarkdownRenderer } from 'vs/editor/contrib/markdown/markdownRenderer';
E
Erich Gamma 已提交
31

J
Joao Moreno 已提交
32
const $ = dom.$;
J
Joao Moreno 已提交
33

J
Joao Moreno 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47
export interface IHintEvent {
	hints: SignatureHelp;
}

export class ParameterHintsModel extends Disposable {

	static DELAY = 120; // ms

	private _onHint = this._register(new Emitter<IHintEvent>());
	onHint: Event<IHintEvent> = this._onHint.event;

	private _onCancel = this._register(new Emitter<void>());
	onCancel: Event<void> = this._onCancel.event;

48
	private editor: ICodeEditor;
J
Joao Moreno 已提交
49
	private enabled: boolean;
J
Joao Moreno 已提交
50 51 52
	private triggerCharactersListeners: IDisposable[];
	private active: boolean;
	private throttledDelayer: RunOnceScheduler;
53
	private provideSignatureHelpRequest?: TPromise<boolean, any>;
J
Joao Moreno 已提交
54

55
	constructor(editor: ICodeEditor) {
J
Joao Moreno 已提交
56 57 58
		super();

		this.editor = editor;
J
Joao Moreno 已提交
59
		this.enabled = false;
J
Joao Moreno 已提交
60 61 62 63 64 65
		this.triggerCharactersListeners = [];

		this.throttledDelayer = new RunOnceScheduler(() => this.doTrigger(), ParameterHintsModel.DELAY);

		this.active = false;

J
Joao Moreno 已提交
66
		this._register(this.editor.onDidChangeConfiguration(() => this.onEditorConfigurationChange()));
J
Joao Moreno 已提交
67
		this._register(this.editor.onDidChangeModel(e => this.onModelChanged()));
A
Alex Dima 已提交
68
		this._register(this.editor.onDidChangeModelLanguage(_ => this.onModelChanged()));
J
Joao Moreno 已提交
69
		this._register(this.editor.onDidChangeCursorSelection(e => this.onCursorChange(e)));
J
Johannes Rieken 已提交
70
		this._register(this.editor.onDidChangeModelContent(e => this.onModelContentChange()));
J
Joao Moreno 已提交
71
		this._register(SignatureHelpProviderRegistry.onDidChange(this.onModelChanged, this));
J
Joao Moreno 已提交
72 73

		this.onEditorConfigurationChange();
J
Joao Moreno 已提交
74 75 76 77 78 79 80 81 82 83 84
		this.onModelChanged();
	}

	cancel(silent: boolean = false): void {
		this.active = false;

		this.throttledDelayer.cancel();

		if (!silent) {
			this._onCancel.fire(void 0);
		}
85 86 87 88 89

		if (this.provideSignatureHelpRequest) {
			this.provideSignatureHelpRequest.cancel();
			this.provideSignatureHelpRequest = undefined;
		}
J
Joao Moreno 已提交
90 91 92
	}

	trigger(delay = ParameterHintsModel.DELAY): void {
J
Joao Moreno 已提交
93
		if (!SignatureHelpProviderRegistry.has(this.editor.getModel())) {
J
Joao Moreno 已提交
94 95 96 97 98 99 100 101
			return;
		}

		this.cancel(true);
		return this.throttledDelayer.schedule(delay);
	}

	private doTrigger(): void {
102 103 104 105 106
		if (this.provideSignatureHelpRequest) {
			this.provideSignatureHelpRequest.cancel();
		}

		this.provideSignatureHelpRequest = provideSignatureHelp(this.editor.getModel(), this.editor.getPosition())
R
Ron Buckton 已提交
107
			.then(null, onUnexpectedError)
J
Joao Moreno 已提交
108
			.then(result => {
J
Joao Moreno 已提交
109
				if (!result || !result.signatures || result.signatures.length === 0) {
J
Joao Moreno 已提交
110 111 112 113 114 115 116
					this.cancel();
					this._onCancel.fire(void 0);
					return false;
				}

				this.active = true;

J
Johannes Rieken 已提交
117
				const event: IHintEvent = { hints: result };
J
Joao Moreno 已提交
118 119 120 121 122
				this._onHint.fire(event);
				return true;
			});
	}

J
Johannes Rieken 已提交
123
	isTriggered(): boolean {
J
Joao Moreno 已提交
124 125 126 127
		return this.active || this.throttledDelayer.isScheduled();
	}

	private onModelChanged(): void {
128 129
		this.cancel();

J
Joao Moreno 已提交
130 131 132 133 134 135 136
		this.triggerCharactersListeners = dispose(this.triggerCharactersListeners);

		const model = this.editor.getModel();
		if (!model) {
			return;
		}

A
Alex Dima 已提交
137
		const triggerChars = new CharacterSet();
138 139
		for (const support of SignatureHelpProviderRegistry.ordered(model)) {
			if (Array.isArray(support.signatureHelpTriggerCharacters)) {
A
Alex Dima 已提交
140 141 142
				for (const ch of support.signatureHelpTriggerCharacters) {
					triggerChars.add(ch.charCodeAt(0));
				}
143
			}
J
Joao Moreno 已提交
144 145
		}

A
Alex Dima 已提交
146
		this.triggerCharactersListeners.push(this.editor.onDidType((text: string) => {
J
Joao Moreno 已提交
147 148 149 150 151
			if (!this.enabled) {
				return;
			}

			if (triggerChars.has(text.charCodeAt(text.length - 1))) {
A
Alex Dima 已提交
152
				this.trigger();
153
			}
A
Alex Dima 已提交
154
		}));
J
Joao Moreno 已提交
155 156 157 158 159 160 161 162 163 164
	}

	private onCursorChange(e: ICursorSelectionChangedEvent): void {
		if (e.source === 'mouse') {
			this.cancel();
		} else if (this.isTriggered()) {
			this.trigger();
		}
	}

J
Johannes Rieken 已提交
165 166 167 168 169 170
	private onModelContentChange(): void {
		if (this.isTriggered()) {
			this.trigger();
		}
	}

J
Joao Moreno 已提交
171 172 173 174 175 176 177 178
	private onEditorConfigurationChange(): void {
		this.enabled = this.editor.getConfiguration().contribInfo.parameterHints;

		if (!this.enabled) {
			this.cancel();
		}
	}

J
Joao Moreno 已提交
179 180 181 182 183 184 185 186 187
	dispose(): void {
		this.cancel(true);
		this.triggerCharactersListeners = dispose(this.triggerCharactersListeners);

		super.dispose();
	}
}

export class ParameterHintsWidget implements IContentWidget, IDisposable {
E
Erich Gamma 已提交
188

189
	private static readonly ID = 'editor.widget.parameterHintsWidget';
E
Erich Gamma 已提交
190

191
	private markdownRenderer: MarkdownRenderer;
192
	private renderDisposeables: IDisposable[];
A
Alex Dima 已提交
193
	private model: ParameterHintsModel;
A
Alex Dima 已提交
194 195
	private keyVisible: IContextKey<boolean>;
	private keyMultipleSignatures: IContextKey<boolean>;
J
Joao Moreno 已提交
196
	private element: HTMLElement;
J
Joao Moreno 已提交
197 198
	private signature: HTMLElement;
	private docs: HTMLElement;
J
Joao Moreno 已提交
199
	private overloads: HTMLElement;
E
Erich Gamma 已提交
200
	private currentSignature: number;
J
Joao Moreno 已提交
201
	private visible: boolean;
J
Joao Moreno 已提交
202
	private hints: SignatureHelp;
203
	private announcedLabel: string;
J
Joao Moreno 已提交
204
	private scrollbar: DomScrollableElement;
J
Joao Moreno 已提交
205
	private disposables: IDisposable[];
E
Erich Gamma 已提交
206 207

	// Editor.IContentWidget.allowEditorOverflow
J
Joao Moreno 已提交
208
	allowEditorOverflow = true;
E
Erich Gamma 已提交
209

210 211 212 213 214 215 216
	constructor(
		private editor: ICodeEditor,
		@IContextKeyService contextKeyService: IContextKeyService,
		@IOpenerService openerService: IOpenerService,
		@IModeService modeService: IModeService,
	) {
		this.markdownRenderer = new MarkdownRenderer(editor, modeService, openerService);
J
Joao Moreno 已提交
217
		this.model = new ParameterHintsModel(editor);
218 219
		this.keyVisible = Context.Visible.bindTo(contextKeyService);
		this.keyMultipleSignatures = Context.MultipleSignatures.bindTo(contextKeyService);
J
Joao Moreno 已提交
220 221
		this.visible = false;
		this.disposables = [];
222

J
Joao Moreno 已提交
223
		this.disposables.push(this.model.onHint(e => {
224
			this.show();
J
Joao Moreno 已提交
225
			this.hints = e.hints;
226
			this.currentSignature = e.hints.activeSignature;
J
Joao Moreno 已提交
227
			this.render();
228 229
		}));

J
Joao Moreno 已提交
230 231 232
		this.disposables.push(this.model.onCancel(() => {
			this.hide();
		}));
R
rebornix 已提交
233
	}
E
Erich Gamma 已提交
234

R
rebornix 已提交
235
	private createParamaterHintDOMNodes() {
J
Joao Moreno 已提交
236
		this.element = $('.editor-widget.parameter-hints-widget');
J
Joao Moreno 已提交
237
		const wrapper = dom.append(this.element, $('.wrapper'));
J
Joao Moreno 已提交
238 239 240 241

		const buttons = dom.append(wrapper, $('.buttons'));
		const previous = dom.append(buttons, $('.button.previous'));
		const next = dom.append(buttons, $('.button.next'));
E
Erich Gamma 已提交
242

J
Joao Moreno 已提交
243 244
		const onPreviousClick = stop(domEvent(previous, 'click'));
		onPreviousClick(this.previous, this, this.disposables);
E
Erich Gamma 已提交
245

J
Joao Moreno 已提交
246 247
		const onNextClick = stop(domEvent(next, 'click'));
		onNextClick(this.next, this, this.disposables);
E
Erich Gamma 已提交
248

J
Joao Moreno 已提交
249
		this.overloads = dom.append(wrapper, $('.overloads'));
E
Erich Gamma 已提交
250

J
Joao Moreno 已提交
251
		const body = $('.body');
252
		this.scrollbar = new DomScrollableElement(body, {});
J
Joao Moreno 已提交
253 254
		this.disposables.push(this.scrollbar);
		wrapper.appendChild(this.scrollbar.getDomNode());
J
Joao Moreno 已提交
255 256

		this.signature = dom.append(body, $('.signature'));
J
Joao Moreno 已提交
257

J
Joao Moreno 已提交
258
		this.docs = dom.append(body, $('.docs'));
J
Joao Moreno 已提交
259

E
Erich Gamma 已提交
260 261 262 263 264
		this.currentSignature = 0;

		this.editor.addContentWidget(this);
		this.hide();

J
Joao Moreno 已提交
265
		this.disposables.push(this.editor.onDidChangeCursorSelection(e => {
J
Joao Moreno 已提交
266
			if (this.visible) {
267 268
				this.editor.layoutContentWidget(this);
			}
E
Erich Gamma 已提交
269
		}));
J
Joao Moreno 已提交
270 271 272 273 274 275 276 277

		const updateFont = () => {
			const fontInfo = this.editor.getConfiguration().fontInfo;
			this.element.style.fontSize = `${fontInfo.fontSize}px`;
		};

		updateFont();

J
Joao Moreno 已提交
278 279 280
		chain<IConfigurationChangedEvent>(this.editor.onDidChangeConfiguration.bind(this.editor))
			.filter(e => e.fontInfo)
			.on(updateFont, null, this.disposables);
J
Joao Moreno 已提交
281 282 283

		this.disposables.push(this.editor.onDidLayoutChange(e => this.updateMaxHeight()));
		this.updateMaxHeight();
E
Erich Gamma 已提交
284 285 286
	}

	private show(): void {
J
Joao Moreno 已提交
287
		if (!this.model || this.visible) {
288 289
			return;
		}
E
Erich Gamma 已提交
290

R
rebornix 已提交
291 292 293 294
		if (!this.element) {
			this.createParamaterHintDOMNodes();
		}

295
		this.keyVisible.set(true);
J
Joao Moreno 已提交
296 297
		this.visible = true;
		TPromise.timeout(100).done(() => dom.addClass(this.element, 'visible'));
E
Erich Gamma 已提交
298 299 300 301
		this.editor.layoutContentWidget(this);
	}

	private hide(): void {
J
Joao Moreno 已提交
302
		if (!this.model || !this.visible) {
303 304
			return;
		}
R
rebornix 已提交
305 306 307 308

		if (!this.element) {
			this.createParamaterHintDOMNodes();
		}
E
Erich Gamma 已提交
309

310
		this.keyVisible.reset();
J
Joao Moreno 已提交
311
		this.visible = false;
J
Joao Moreno 已提交
312
		this.hints = null;
313
		this.announcedLabel = null;
J
Joao Moreno 已提交
314
		dom.removeClass(this.element, 'visible');
E
Erich Gamma 已提交
315 316 317
		this.editor.layoutContentWidget(this);
	}

J
Johannes Rieken 已提交
318
	getPosition(): IContentWidgetPosition {
J
Joao Moreno 已提交
319
		if (this.visible) {
E
Erich Gamma 已提交
320 321
			return {
				position: this.editor.getPosition(),
A
Alex Dima 已提交
322
				preference: [ContentWidgetPositionPreference.ABOVE, ContentWidgetPositionPreference.BELOW]
E
Erich Gamma 已提交
323 324 325 326 327
			};
		}
		return null;
	}

J
Joao Moreno 已提交
328 329 330 331
	private render(): void {
		const multiple = this.hints.signatures.length > 1;
		dom.toggleClass(this.element, 'multiple', multiple);
		this.keyMultipleSignatures.set(multiple);
E
Erich Gamma 已提交
332

J
Joao Moreno 已提交
333 334
		this.signature.innerHTML = '';
		this.docs.innerHTML = '';
E
Erich Gamma 已提交
335

J
Joao Moreno 已提交
336
		const signature = this.hints.signatures[this.currentSignature];
E
Erich Gamma 已提交
337

J
Joao Moreno 已提交
338 339 340 341
		if (!signature) {
			return;
		}

J
Joao Moreno 已提交
342 343
		const code = dom.append(this.signature, $('.code'));
		const hasParameters = signature.parameters.length > 0;
E
Erich Gamma 已提交
344

J
Joao Moreno 已提交
345 346 347
		const fontInfo = this.editor.getConfiguration().fontInfo;
		code.style.fontSize = `${fontInfo.fontSize}px`;
		code.style.fontFamily = fontInfo.fontFamily;
E
Erich Gamma 已提交
348

J
Johannes Rieken 已提交
349
		if (!hasParameters) {
J
Joao Moreno 已提交
350 351
			const label = dom.append(code, $('span'));
			label.textContent = signature.label;
E
Erich Gamma 已提交
352

J
Joao Moreno 已提交
353 354
		} else {
			this.renderParameters(code, signature, this.hints.activeParameter);
E
Erich Gamma 已提交
355
		}
356

357 358 359
		dispose(this.renderDisposeables);
		this.renderDisposeables = [];

J
Joao Moreno 已提交
360
		const activeParameter = signature.parameters[this.hints.activeParameter];
E
Erich Gamma 已提交
361

J
Johannes Rieken 已提交
362
		if (activeParameter && activeParameter.documentation) {
J
Joao Moreno 已提交
363
			const documentation = $('span.documentation');
364 365 366
			if (typeof activeParameter.documentation === 'string') {
				documentation.textContent = activeParameter.documentation;
			} else {
367
				const renderedContents = this.markdownRenderer.render(activeParameter.documentation);
368
				dom.addClass(renderedContents.element, 'markdown-docs');
369 370
				this.renderDisposeables.push(renderedContents);
				documentation.appendChild(renderedContents.element);
371
			}
J
Joao Moreno 已提交
372 373
			dom.append(this.docs, $('p', null, documentation));
		}
J
Joao Moreno 已提交
374

J
Joao Moreno 已提交
375
		dom.toggleClass(this.signature, 'has-docs', !!signature.documentation);
E
Erich Gamma 已提交
376

377
		if (typeof signature.documentation === 'string') {
J
Joao Moreno 已提交
378
			dom.append(this.docs, $('p', null, signature.documentation));
379
		} else {
380
			const renderedContents = this.markdownRenderer.render(signature.documentation);
381
			dom.addClass(renderedContents.element, 'markdown-docs');
382 383
			this.renderDisposeables.push(renderedContents);
			dom.append(this.docs, renderedContents.element);
J
Joao Moreno 已提交
384
		}
J
Joao Moreno 已提交
385

J
Joao Moreno 已提交
386
		let currentOverload = String(this.currentSignature + 1);
387

J
Joao Moreno 已提交
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
		if (this.hints.signatures.length < 10) {
			currentOverload += `/${this.hints.signatures.length}`;
		}

		this.overloads.textContent = currentOverload;

		if (activeParameter) {
			const labelToAnnounce = activeParameter.label;
			// Select method gets called on every user type while parameter hints are visible.
			// We do not want to spam the user with same announcements, so we only announce if the current parameter changed.

			if (this.announcedLabel !== labelToAnnounce) {
				aria.alert(nls.localize('hint', "{0}, hint", labelToAnnounce));
				this.announcedLabel = labelToAnnounce;
			}
J
Joao Moreno 已提交
403
		}
E
Erich Gamma 已提交
404

J
Joao Moreno 已提交
405
		this.editor.layoutContentWidget(this);
J
Joao Moreno 已提交
406
		this.scrollbar.scanDomNode();
407 408 409 410
	}

	private renderParameters(parent: HTMLElement, signature: SignatureInformation, currentParameter: number): void {
		let end = signature.label.length;
J
Joao Moreno 已提交
411
		let idx = 0;
412
		let element: HTMLSpanElement;
J
Joao Moreno 已提交
413

414
		for (let i = signature.parameters.length - 1; i >= 0; i--) {
J
Joao Moreno 已提交
415
			const parameter = signature.parameters[i];
O
Oleg Bulatov 已提交
416
			idx = signature.label.lastIndexOf(parameter.label, end - 1);
E
Erich Gamma 已提交
417

J
Joao Moreno 已提交
418 419 420 421 422
			let signatureLabelOffset = 0;
			let signatureLabelEnd = 0;

			if (idx >= 0) {
				signatureLabelOffset = idx;
423
				signatureLabelEnd = idx + parameter.label.length;
E
Erich Gamma 已提交
424 425
			}

426 427 428 429
			// non parameter part
			element = document.createElement('span');
			element.textContent = signature.label.substring(signatureLabelEnd, end);
			dom.prepend(parent, element);
J
Joao Moreno 已提交
430

431 432 433 434 435
			// parameter part
			element = document.createElement('span');
			element.className = `parameter ${i === currentParameter ? 'active' : ''}`;
			element.textContent = signature.label.substring(signatureLabelOffset, signatureLabelEnd);
			dom.prepend(parent, element);
J
Joao Moreno 已提交
436

437
			end = signatureLabelOffset;
E
Erich Gamma 已提交
438
		}
439 440 441 442
		// non parameter part
		element = document.createElement('span');
		element.textContent = signature.label.substring(0, end);
		dom.prepend(parent, element);
J
Joao Moreno 已提交
443 444
	}

J
Joao Moreno 已提交
445 446
	// private select(position: number): void {
	// 	const signature = this.signatureViews[position];
J
Joao Moreno 已提交
447

J
Joao Moreno 已提交
448 449 450
	// 	if (!signature) {
	// 		return;
	// 	}
J
Joao Moreno 已提交
451

J
Joao Moreno 已提交
452 453
	// 	this.signatures.style.height = `${ signature.height }px`;
	// 	this.signatures.scrollTop = signature.top;
E
Erich Gamma 已提交
454

J
Joao Moreno 已提交
455
	// 	let overloads = '' + (position + 1);
456

J
Joao Moreno 已提交
457 458 459
	// 	if (this.signatureViews.length < 10) {
	// 		overloads += '/' + this.signatureViews.length;
	// 	}
E
Erich Gamma 已提交
460

J
Joao Moreno 已提交
461
	// 	this.overloads.textContent = overloads;
E
Erich Gamma 已提交
462

J
Joao Moreno 已提交
463 464 465 466 467 468 469 470 471
	// 	if (this.hints && this.hints.signatures[position].parameters[this.hints.activeParameter]) {
	// 		const labelToAnnounce = this.hints.signatures[position].parameters[this.hints.activeParameter].label;
	// 		// Select method gets called on every user type while parameter hints are visible.
	// 		// We do not want to spam the user with same announcements, so we only announce if the current parameter changed.
	// 		if (this.announcedLabel !== labelToAnnounce) {
	// 			aria.alert(nls.localize('hint', "{0}, hint", labelToAnnounce));
	// 			this.announcedLabel = labelToAnnounce;
	// 		}
	// 	}
E
Erich Gamma 已提交
472

J
Joao Moreno 已提交
473 474
	// 	this.editor.layoutContentWidget(this);
	// }
E
Erich Gamma 已提交
475

476
	next(): boolean {
J
Joao Moreno 已提交
477 478 479
		const length = this.hints.signatures.length;

		if (length < 2) {
E
Erich Gamma 已提交
480 481 482 483
			this.cancel();
			return false;
		}

J
Joao Moreno 已提交
484 485
		this.currentSignature = (this.currentSignature + 1) % length;
		this.render();
E
Erich Gamma 已提交
486 487 488
		return true;
	}

489
	previous(): boolean {
J
Joao Moreno 已提交
490 491 492
		const length = this.hints.signatures.length;

		if (length < 2) {
E
Erich Gamma 已提交
493 494 495 496
			this.cancel();
			return false;
		}

J
Joao Moreno 已提交
497 498
		this.currentSignature = (this.currentSignature - 1 + length) % length;
		this.render();
E
Erich Gamma 已提交
499 500 501
		return true;
	}

J
Joao Moreno 已提交
502
	cancel(): void {
E
Erich Gamma 已提交
503 504 505
		this.model.cancel();
	}

J
Joao Moreno 已提交
506
	getDomNode(): HTMLElement {
J
Joao Moreno 已提交
507
		return this.element;
E
Erich Gamma 已提交
508 509
	}

J
Joao Moreno 已提交
510
	getId(): string {
E
Erich Gamma 已提交
511 512 513
		return ParameterHintsWidget.ID;
	}

J
Joao Moreno 已提交
514 515 516 517
	trigger(): void {
		this.model.trigger(0);
	}

J
Joao Moreno 已提交
518 519
	private updateMaxHeight(): void {
		const height = Math.max(this.editor.getLayoutInfo().height / 4, 250);
J
Johannes Rieken 已提交
520
		this.element.style.maxHeight = `${height}px`;
J
Joao Moreno 已提交
521 522
	}

J
Joao Moreno 已提交
523
	dispose(): void {
J
Joao Moreno 已提交
524
		this.disposables = dispose(this.disposables);
525
		this.renderDisposeables = dispose(this.renderDisposeables);
J
Joao Moreno 已提交
526 527 528 529 530

		if (this.model) {
			this.model.dispose();
			this.model = null;
		}
E
Erich Gamma 已提交
531
	}
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
}

registerThemingParticipant((theme, collector) => {
	let border = theme.getColor(editorHoverBorder);
	if (border) {
		let borderWidth = theme.type === HIGH_CONTRAST ? 2 : 1;
		collector.addRule(`.monaco-editor .parameter-hints-widget { border: ${borderWidth}px solid ${border}; }`);
		collector.addRule(`.monaco-editor .parameter-hints-widget.multiple .body { border-left: 1px solid ${border.transparent(0.5)}; }`);
		collector.addRule(`.monaco-editor .parameter-hints-widget .signature.has-docs { border-bottom: 1px solid ${border.transparent(0.5)}; }`);

	}
	let background = theme.getColor(editorHoverBackground);
	if (background) {
		collector.addRule(`.monaco-editor .parameter-hints-widget { background-color: ${background}; }`);
	}
547 548 549 550 551

	const link = theme.getColor(textLinkForeground);
	if (link) {
		collector.addRule(`.monaco-editor .parameter-hints-widget a { color: ${link}; }`);
	}
552 553 554 555 556

	let codeBackground = theme.getColor(textCodeBlockBackground);
	if (codeBackground) {
		collector.addRule(`.monaco-editor .parameter-hints-widget code { background-color: ${codeBackground}; }`);
	}
557
});