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

'use strict';

8
import 'vs/css!./media/suggest';
J
Johannes Rieken 已提交
9
import * as nls from 'vs/nls';
J
Johannes Rieken 已提交
10
import { createMatches } from 'vs/base/common/filters';
11
import * as strings from 'vs/base/common/strings';
M
Matt Bierner 已提交
12
import { Event, Emitter, chain } from 'vs/base/common/event';
13
import { onUnexpectedError } from 'vs/base/common/errors';
J
Joao Moreno 已提交
14
import { IDisposable, dispose, toDisposable } from 'vs/base/common/lifecycle';
15
import { addClass, append, $, hide, removeClass, show, toggleClass, getDomNodePagePosition, hasClass } from 'vs/base/browser/dom';
J
Joao Moreno 已提交
16
import { HighlightedLabel } from 'vs/base/browser/ui/highlightedlabel/highlightedLabel';
J
Joao Moreno 已提交
17
import { IDelegate, IListEvent, IRenderer } from 'vs/base/browser/ui/list/list';
J
Joao Moreno 已提交
18 19
import { List } from 'vs/base/browser/ui/list/listWidget';
import { DomScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement';
J
Johannes Rieken 已提交
20 21
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
22
import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions';
J
Joao Moreno 已提交
23
import { ContentWidgetPositionPreference, ICodeEditor, IContentWidget, IContentWidgetPosition } from 'vs/editor/browser/editorBrowser';
24 25
import { Context as SuggestContext } from './suggest';
import { ICompletionItem, CompletionModel } from './completionModel';
J
Johannes Rieken 已提交
26
import { alert } from 'vs/base/browser/ui/aria/aria';
J
Joao Moreno 已提交
27
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
28 29
import { attachListStyler } from 'vs/platform/theme/common/styler';
import { IThemeService, ITheme, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
30
import { registerColor, editorWidgetBackground, listFocusBackground, activeContrastBorder, listHighlightForeground, editorForeground, editorWidgetBorder, focusBorder, textLinkForeground, textCodeBlockBackground } from 'vs/platform/theme/common/colorRegistry';
31
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
32
import { MarkdownRenderer } from 'vs/editor/contrib/markdown/markdownRenderer';
33 34
import { IModeService } from 'vs/editor/common/services/modeService';
import { IOpenerService } from 'vs/platform/opener/common/opener';
35 36
import { TimeoutTimer, CancelablePromise, createCancelablePromise } from 'vs/base/common/async';
import { CancellationToken } from 'vs/base/common/cancellation';
E
Erich Gamma 已提交
37

38
const sticky = false; // for development purposes
39
const expandSuggestionDocsByDefault = false;
40
const maxSuggestionsToShow = 12;
J
Joao Moreno 已提交
41

E
Erich Gamma 已提交
42 43 44 45
interface ISuggestionTemplateData {
	root: HTMLElement;
	icon: HTMLElement;
	colorspan: HTMLElement;
A
Alex Dima 已提交
46
	highlightedLabel: HighlightedLabel;
47
	typeLabel: HTMLElement;
48
	readMore: HTMLElement;
49
	disposables: IDisposable[];
E
Erich Gamma 已提交
50 51
}

M
Martin Aeschlimann 已提交
52 53 54
/**
 * Suggest widget colors
 */
55
export const editorSuggestWidgetBackground = registerColor('editorSuggestWidget.background', { dark: editorWidgetBackground, light: editorWidgetBackground, hc: editorWidgetBackground }, nls.localize('editorSuggestWidgetBackground', 'Background color of the suggest widget.'));
56
export const editorSuggestWidgetBorder = registerColor('editorSuggestWidget.border', { dark: editorWidgetBorder, light: editorWidgetBorder, hc: editorWidgetBorder }, nls.localize('editorSuggestWidgetBorder', 'Border color of the suggest widget.'));
57 58 59
export const editorSuggestWidgetForeground = registerColor('editorSuggestWidget.foreground', { dark: editorForeground, light: editorForeground, hc: editorForeground }, nls.localize('editorSuggestWidgetForeground', 'Foreground color of the suggest widget.'));
export const editorSuggestWidgetSelectedBackground = registerColor('editorSuggestWidget.selectedBackground', { dark: listFocusBackground, light: listFocusBackground, hc: listFocusBackground }, nls.localize('editorSuggestWidgetSelectedBackground', 'Background color of the selected entry in the suggest widget.'));
export const editorSuggestWidgetHighlightForeground = registerColor('editorSuggestWidget.highlightForeground', { dark: listHighlightForeground, light: listHighlightForeground, hc: listHighlightForeground }, nls.localize('editorSuggestWidgetHighlightForeground', 'Color of the match highlights in the suggest widget.'));
60

M
Martin Aeschlimann 已提交
61

62
const colorRegExp = /^(#([\da-f]{3}){1,2}|(rgb|hsl)a\(\s*(\d{1,3}%?\s*,\s*){3}(1|0?\.\d+)\)|(rgb|hsl)\(\s*\d{1,3}%?(\s*,\s*\d{1,3}%?){2}\s*\))$/i;
63 64 65
function matchesColor(text: string) {
	return text && text.match(colorRegExp) ? text : null;
}
66

67
function canExpandCompletionItem(item: ICompletionItem) {
R
Ramya Achutha Rao 已提交
68 69 70
	if (!item) {
		return false;
	}
71 72 73 74
	const suggestion = item.suggestion;
	if (suggestion.documentation) {
		return true;
	}
75
	return (suggestion.detail && suggestion.detail !== suggestion.label);
76 77
}

78
class Renderer implements IRenderer<ICompletionItem, ISuggestionTemplateData> {
E
Erich Gamma 已提交
79

J
Joao Moreno 已提交
80 81
	constructor(
		private widget: SuggestWidget,
82
		private editor: ICodeEditor,
83
		private triggerKeybindingLabel: string
J
Joao Moreno 已提交
84
	) {
85

J
Joao Moreno 已提交
86
	}
J
Joao Moreno 已提交
87

J
Joao Moreno 已提交
88 89 90
	get templateId(): string {
		return 'suggestion';
	}
E
Erich Gamma 已提交
91

J
Joao Moreno 已提交
92
	renderTemplate(container: HTMLElement): ISuggestionTemplateData {
J
Johannes Rieken 已提交
93
		const data = <ISuggestionTemplateData>Object.create(null);
94
		data.disposables = [];
E
Erich Gamma 已提交
95
		data.root = container;
J
Joao Moreno 已提交
96

J
Joao Moreno 已提交
97 98
		data.icon = append(container, $('.icon'));
		data.colorspan = append(data.icon, $('span.colorspan'));
E
Erich Gamma 已提交
99

J
Joao Moreno 已提交
100
		const text = append(container, $('.contents'));
J
Joao Moreno 已提交
101
		const main = append(text, $('.main'));
A
Alex Dima 已提交
102
		data.highlightedLabel = new HighlightedLabel(main);
103
		data.disposables.push(data.highlightedLabel);
104 105
		data.typeLabel = append(main, $('span.type-label'));

106 107
		data.readMore = append(main, $('span.readMore'));
		data.readMore.title = nls.localize('readMore', "Read More...{0}", this.triggerKeybindingLabel);
108

109
		const configureFont = () => {
J
Joao Moreno 已提交
110 111 112 113
			const configuration = this.editor.getConfiguration();
			const fontFamily = configuration.fontInfo.fontFamily;
			const fontSize = configuration.contribInfo.suggestFontSize || configuration.fontInfo.fontSize;
			const lineHeight = configuration.contribInfo.suggestLineHeight || configuration.fontInfo.lineHeight;
J
Johannes Rieken 已提交
114 115
			const fontSizePx = `${fontSize}px`;
			const lineHeightPx = `${lineHeight}px`;
J
Joao Moreno 已提交
116 117 118 119 120 121

			data.root.style.fontSize = fontSizePx;
			main.style.fontFamily = fontFamily;
			main.style.lineHeight = lineHeightPx;
			data.icon.style.height = lineHeightPx;
			data.icon.style.width = lineHeightPx;
122 123
			data.readMore.style.height = lineHeightPx;
			data.readMore.style.width = lineHeightPx;
124 125 126 127
		};

		configureFont();

J
Joao Moreno 已提交
128
		chain<IConfigurationChangedEvent>(this.editor.onDidChangeConfiguration.bind(this.editor))
J
Joao Moreno 已提交
129
			.filter(e => e.fontInfo || e.contribInfo)
J
Joao Moreno 已提交
130
			.on(configureFont, null, data.disposables);
131

E
Erich Gamma 已提交
132 133 134
		return data;
	}

135
	renderElement(element: ICompletionItem, index: number, templateData: ISuggestionTemplateData): void {
J
Johannes Rieken 已提交
136
		const data = <ISuggestionTemplateData>templateData;
137
		const suggestion = (<ICompletionItem>element).suggestion;
E
Erich Gamma 已提交
138

139
		if (canExpandCompletionItem(element)) {
140
			data.root.setAttribute('aria-label', nls.localize('suggestionWithDetailsAriaLabel', "{0}, suggestion, has details", suggestion.label));
141 142 143 144
		} else {
			data.root.setAttribute('aria-label', nls.localize('suggestionAriaLabel', "{0}, suggestion", suggestion.label));
		}

145 146 147 148
		data.icon.className = 'icon ' + suggestion.type;
		data.colorspan.style.backgroundColor = '';

		if (suggestion.type === 'color') {
149
			let color = matchesColor(suggestion.label) || typeof suggestion.documentation === 'string' && matchesColor(suggestion.documentation);
150 151 152 153
			if (color) {
				data.icon.className = 'icon customcolor';
				data.colorspan.style.backgroundColor = color;
			}
E
Erich Gamma 已提交
154 155
		}

J
Johannes Rieken 已提交
156
		data.highlightedLabel.set(suggestion.label, createMatches(element.matches), '', true);
J
Johannes Rieken 已提交
157
		// data.highlightedLabel.set(`${suggestion.label} <${element.score}=score(${element.word}, ${suggestion.filterText || suggestion.label})>`, createMatches(element.matches));
158
		data.typeLabel.textContent = (suggestion.detail || '').replace(/\n.*$/m, '');
J
Joao Moreno 已提交
159

160
		if (canExpandCompletionItem(element)) {
161 162
			show(data.readMore);
			data.readMore.onmousedown = e => {
163 164 165
				e.stopPropagation();
				e.preventDefault();
			};
166
			data.readMore.onclick = e => {
167 168 169 170 171
				e.stopPropagation();
				e.preventDefault();
				this.widget.toggleDetails();
			};
		} else {
172 173 174
			hide(data.readMore);
			data.readMore.onmousedown = null;
			data.readMore.onclick = null;
175
		}
J
Joao Moreno 已提交
176
	}
J
Joao Moreno 已提交
177

J
Joao Moreno 已提交
178 179
	disposeElement(): void {
		// noop
E
Erich Gamma 已提交
180 181
	}

J
Joao Moreno 已提交
182
	disposeTemplate(templateData: ISuggestionTemplateData): void {
183
		templateData.disposables = dispose(templateData.disposables);
J
Joao Moreno 已提交
184 185
	}
}
E
Erich Gamma 已提交
186

A
Alex Dima 已提交
187
const enum State {
J
Joao Moreno 已提交
188 189 190
	Hidden,
	Loading,
	Empty,
J
Joao Moreno 已提交
191
	Open,
J
Joao Moreno 已提交
192 193 194 195 196 197 198
	Frozen,
	Details
}

class SuggestionDetails {

	private el: HTMLElement;
199
	private close: HTMLElement;
200
	private scrollbar: DomScrollableElement;
201
	private body: HTMLElement;
202
	private header: HTMLElement;
J
Joao Moreno 已提交
203 204
	private type: HTMLElement;
	private docs: HTMLElement;
205 206
	private ariaLabel: string;
	private disposables: IDisposable[];
207
	private renderDisposeable: IDisposable;
208
	private borderWidth: number = 1;
209 210 211 212

	constructor(
		container: HTMLElement,
		private widget: SuggestWidget,
213
		private editor: ICodeEditor,
214
		private markdownRenderer: MarkdownRenderer,
215
		private triggerKeybindingLabel: string
216 217
	) {
		this.disposables = [];
J
Joao Moreno 已提交
218 219

		this.el = append(container, $('.details'));
220 221
		this.disposables.push(toDisposable(() => container.removeChild(this.el)));

222
		this.body = $('.body');
223

224
		this.scrollbar = new DomScrollableElement(this.body, {});
225
		append(this.el, this.scrollbar.getDomNode());
226 227
		this.disposables.push(this.scrollbar);

228 229
		this.header = append(this.body, $('.header'));
		this.close = append(this.header, $('span.close'));
230
		this.close.title = nls.localize('readLess', "Read less...{0}", this.triggerKeybindingLabel);
231
		this.type = append(this.header, $('p.type'));
232

233
		this.docs = append(this.body, $('p.docs'));
234
		this.ariaLabel = null;
235 236 237

		this.configureFont();

J
Joao Moreno 已提交
238 239 240
		chain<IConfigurationChangedEvent>(this.editor.onDidChangeConfiguration.bind(this.editor))
			.filter(e => e.fontInfo)
			.on(this.configureFont, this, this.disposables);
241 242

		markdownRenderer.onDidRenderCodeBlock(() => this.scrollbar.scanDomNode(), this, this.disposables);
J
Joao Moreno 已提交
243 244
	}

J
Joao Moreno 已提交
245 246 247
	get element() {
		return this.el;
	}
J
Joao Moreno 已提交
248

249
	render(item: ICompletionItem): void {
250 251
		this.renderDisposeable = dispose(this.renderDisposeable);

252
		if (!item || !canExpandCompletionItem(item)) {
J
Joao Moreno 已提交
253 254
			this.type.textContent = '';
			this.docs.textContent = '';
255
			addClass(this.el, 'no-docs');
256
			this.ariaLabel = null;
J
Joao Moreno 已提交
257 258
			return;
		}
259
		removeClass(this.el, 'no-docs');
260
		if (typeof item.suggestion.documentation === 'string') {
261
			removeClass(this.docs, 'markdown-docs');
262 263
			this.docs.textContent = item.suggestion.documentation;
		} else {
264
			addClass(this.docs, 'markdown-docs');
M
Matt Bierner 已提交
265
			this.docs.innerHTML = '';
266 267 268
			const renderedContents = this.markdownRenderer.render(item.suggestion.documentation);
			this.renderDisposeable = renderedContents;
			this.docs.appendChild(renderedContents.element);
269
		}
270

R
Ramya Achutha Rao 已提交
271 272 273 274 275 276 277 278
		if (item.suggestion.detail) {
			this.type.innerText = item.suggestion.detail;
			show(this.type);
		} else {
			this.type.innerText = '';
			hide(this.type);
		}

279
		this.el.style.height = this.header.offsetHeight + this.docs.offsetHeight + (this.borderWidth * 2) + 'px';
280

281
		this.close.onmousedown = e => {
282 283 284
			e.preventDefault();
			e.stopPropagation();
		};
285
		this.close.onclick = e => {
286 287 288 289
			e.preventDefault();
			e.stopPropagation();
			this.widget.toggleDetails();
		};
290

J
Joao Moreno 已提交
291
		this.body.scrollTop = 0;
292
		this.scrollbar.scanDomNode();
293

294
		this.ariaLabel = strings.format('{0}\n{1}\n{2}', item.suggestion.label || '', item.suggestion.detail || '', item.suggestion.documentation || '');
295 296 297 298
	}

	getAriaLabel(): string {
		return this.ariaLabel;
J
Joao Moreno 已提交
299 300
	}

301 302 303 304 305 306 307 308
	scrollDown(much = 8): void {
		this.body.scrollTop += much;
	}

	scrollUp(much = 8): void {
		this.body.scrollTop -= much;
	}

309 310 311 312 313 314 315 316
	scrollTop(): void {
		this.body.scrollTop = 0;
	}

	scrollBottom(): void {
		this.body.scrollTop = this.body.scrollHeight;
	}

317 318 319 320 321 322 323 324
	pageDown(): void {
		this.scrollDown(80);
	}

	pageUp(): void {
		this.scrollUp(80);
	}

325 326 327 328
	setBorderWidth(width: number): void {
		this.borderWidth = width;
	}

329
	private configureFont() {
J
Joao Moreno 已提交
330 331 332
		const configuration = this.editor.getConfiguration();
		const fontFamily = configuration.fontInfo.fontFamily;
		const fontSize = configuration.contribInfo.suggestFontSize || configuration.fontInfo.fontSize;
333
		const lineHeight = configuration.contribInfo.suggestLineHeight || configuration.fontInfo.lineHeight;
J
Johannes Rieken 已提交
334
		const fontSizePx = `${fontSize}px`;
335
		const lineHeightPx = `${lineHeight}px`;
J
Joao Moreno 已提交
336

J
Joao Moreno 已提交
337 338
		this.el.style.fontSize = fontSizePx;
		this.type.style.fontFamily = fontFamily;
339 340
		this.close.style.height = lineHeightPx;
		this.close.style.width = lineHeightPx;
341
	}
342

343 344
	dispose(): void {
		this.disposables = dispose(this.disposables);
345
		this.renderDisposeable = dispose(this.renderDisposeable);
J
Joao Moreno 已提交
346
	}
J
Joao Moreno 已提交
347 348
}

349 350 351 352 353 354
export interface ISelectedSuggestion {
	item: ICompletionItem;
	index: number;
	model: CompletionModel;
}

355
export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>, IDisposable {
J
Joao Moreno 已提交
356

M
Matt Bierner 已提交
357
	private static readonly ID: string = 'editor.widget.suggestWidget';
E
Erich Gamma 已提交
358

J
Johannes Rieken 已提交
359 360
	static LOADING_MESSAGE: string = nls.localize('suggestWidget.loading', "Loading...");
	static NO_SUGGESTIONS_MESSAGE: string = nls.localize('suggestWidget.noSuggestions', "No suggestions.");
E
Erich Gamma 已提交
361

J
Joao Moreno 已提交
362
	// Editor.IContentWidget.allowEditorOverflow
363
	readonly allowEditorOverflow = true;
J
Joao Moreno 已提交
364

J
Joao Moreno 已提交
365
	private state: State;
E
Erich Gamma 已提交
366
	private isAuto: boolean;
367
	private loadingTimeout: number;
368
	private currentSuggestionDetails: CancelablePromise<void>;
369
	private focusedItem: ICompletionItem;
370
	private ignoreFocusEvents = false;
J
Joao Moreno 已提交
371
	private completionModel: CompletionModel;
J
Joao Moreno 已提交
372

E
Erich Gamma 已提交
373
	private element: HTMLElement;
J
Joao Moreno 已提交
374
	private messageElement: HTMLElement;
J
Joao Moreno 已提交
375
	private listElement: HTMLElement;
J
Joao Moreno 已提交
376
	private details: SuggestionDetails;
377
	private list: List<ICompletionItem>;
378
	private listHeight: number;
E
Erich Gamma 已提交
379

A
Alex Dima 已提交
380 381 382
	private suggestWidgetVisible: IContextKey<boolean>;
	private suggestWidgetMultipleSuggestions: IContextKey<boolean>;
	private suggestionSupportsAutoAccept: IContextKey<boolean>;
J
Joao Moreno 已提交
383

384 385
	private readonly editorBlurTimeout = new TimeoutTimer();
	private readonly showTimeout = new TimeoutTimer();
J
Joao Moreno 已提交
386
	private toDispose: IDisposable[];
J
Joao Moreno 已提交
387

388 389
	private onDidSelectEmitter = new Emitter<ISelectedSuggestion>();
	private onDidFocusEmitter = new Emitter<ISelectedSuggestion>();
390 391 392
	private onDidHideEmitter = new Emitter<this>();
	private onDidShowEmitter = new Emitter<this>();

393

394 395
	readonly onDidSelect: Event<ISelectedSuggestion> = this.onDidSelectEmitter.event;
	readonly onDidFocus: Event<ISelectedSuggestion> = this.onDidFocusEmitter.event;
396 397
	readonly onDidHide: Event<this> = this.onDidHideEmitter.event;
	readonly onDidShow: Event<this> = this.onDidShowEmitter.event;
398

399
	private readonly maxWidgetWidth = 660;
400
	private readonly listWidth = 330;
401
	private storageService: IStorageService;
402 403
	private detailsFocusBorderColor: string;
	private detailsBorderColor: string;
404

405 406 407
	private storageServiceAvailable: boolean = true;
	private expandSuggestionDocs: boolean = false;

408 409
	private firstFocusInCurrentList: boolean = false;

410
	constructor(
A
Alex Dima 已提交
411
		private editor: ICodeEditor,
J
Joao Moreno 已提交
412
		@ITelemetryService private telemetryService: ITelemetryService,
413
		@IContextKeyService contextKeyService: IContextKeyService,
414 415
		@IThemeService themeService: IThemeService,
		@IStorageService storageService: IStorageService,
416 417 418
		@IKeybindingService keybindingService: IKeybindingService,
		@IModeService modeService: IModeService,
		@IOpenerService openerService: IOpenerService
419
	) {
420 421
		const kb = keybindingService.lookupKeybinding('editor.action.triggerSuggest');
		const triggerKeybindingLabel = !kb ? '' : ` (${kb.getLabel()})`;
422
		const markdownRenderer = new MarkdownRenderer(editor, modeService, openerService);
423

E
Erich Gamma 已提交
424
		this.isAuto = false;
J
Joao Moreno 已提交
425
		this.focusedItem = null;
426
		this.storageService = storageService;
427 428 429 430 431 432

		if (this.expandDocsSettingFromStorage() === undefined) {
			this.storageService.store('expandSuggestionDocs', expandSuggestionDocsByDefault, StorageScope.GLOBAL);
			if (this.expandDocsSettingFromStorage() === undefined) {
				this.storageServiceAvailable = false;
			}
433
		}
E
Erich Gamma 已提交
434

435
		this.element = $('.editor-widget.suggest-widget');
A
Alex Dima 已提交
436
		if (!this.editor.getConfiguration().contribInfo.iconsInSuggestions) {
J
Joao Moreno 已提交
437
			addClass(this.element, 'no-icons');
E
Erich Gamma 已提交
438 439
		}

J
Joao Moreno 已提交
440
		this.messageElement = append(this.element, $('.message'));
J
Joao Moreno 已提交
441
		this.listElement = append(this.element, $('.tree'));
442
		this.details = new SuggestionDetails(this.element, this, this.editor, markdownRenderer, triggerKeybindingLabel);
J
Joao Moreno 已提交
443

444
		let renderer = new Renderer(this, this.editor, triggerKeybindingLabel);
J
Joao Moreno 已提交
445

446 447
		this.list = new List(this.listElement, this, [renderer], {
			useShadows: false,
J
Joao Moreno 已提交
448
			selectOnMouseDown: true,
J
Joao Moreno 已提交
449 450
			focusOnMouseDown: false,
			openController: { shouldOpen: () => false }
451
		});
J
Joao Moreno 已提交
452 453

		this.toDispose = [
454
			attachListStyler(this.list, themeService, {
455
				listInactiveFocusBackground: editorSuggestWidgetSelectedBackground,
456 457
				listInactiveFocusOutline: activeContrastBorder
			}),
M
Martin Aeschlimann 已提交
458
			themeService.onThemeChange(t => this.onThemeChange(t)),
A
Alex Dima 已提交
459
			editor.onDidBlurEditorText(() => this.onEditorBlur()),
460
			editor.onDidLayoutChange(() => this.onEditorLayoutChange()),
J
Joao Moreno 已提交
461
			this.list.onSelectionChange(e => this.onListSelection(e)),
J
Joao Moreno 已提交
462
			this.list.onFocusChange(e => this.onListFocus(e)),
463
			this.editor.onDidChangeCursorSelection(() => this.onCursorSelectionChanged())
J
Joao Moreno 已提交
464 465
		];

466 467 468
		this.suggestWidgetVisible = SuggestContext.Visible.bindTo(contextKeyService);
		this.suggestWidgetMultipleSuggestions = SuggestContext.MultipleSuggestions.bindTo(contextKeyService);
		this.suggestionSupportsAutoAccept = SuggestContext.AcceptOnKey.bindTo(contextKeyService);
J
Joao Moreno 已提交
469

J
Joao Moreno 已提交
470 471
		this.editor.addContentWidget(this);
		this.setState(State.Hidden);
472

M
Martin Aeschlimann 已提交
473
		this.onThemeChange(themeService.getTheme());
J
Joao Moreno 已提交
474
	}
E
Erich Gamma 已提交
475

J
Joao Moreno 已提交
476 477 478 479
	private onCursorSelectionChanged(): void {
		if (this.state === State.Hidden) {
			return;
		}
E
Erich Gamma 已提交
480

J
Joao Moreno 已提交
481 482
		this.editor.layoutContentWidget(this);
	}
J
Joao Moreno 已提交
483

J
Joao Moreno 已提交
484
	private onEditorBlur(): void {
J
Joao Moreno 已提交
485 486 487 488
		if (sticky) {
			return;
		}

489
		this.editorBlurTimeout.cancelAndSet(() => {
A
Alex Dima 已提交
490
			if (!this.editor.hasTextFocus()) {
J
Joao Moreno 已提交
491 492
				this.setState(State.Hidden);
			}
493
		}, 150);
J
Joao Moreno 已提交
494 495
	}

496 497 498 499 500 501
	private onEditorLayoutChange(): void {
		if ((this.state === State.Open || this.state === State.Details) && this.expandDocsSettingFromStorage()) {
			this.expandSideOrBelow();
		}
	}

J
Joao Moreno 已提交
502
	private onListSelection(e: IListEvent<ICompletionItem>): void {
J
Joao Moreno 已提交
503 504 505
		if (!e.elements.length) {
			return;
		}
E
Erich Gamma 已提交
506

J
Joao Moreno 已提交
507
		const item = e.elements[0];
508
		const index = e.indexes[0];
509
		item.resolve(CancellationToken.None).then(() => {
510
			this.onDidSelectEmitter.fire({ item, index, model: this.completionModel });
J
Johannes Rieken 已提交
511 512
			alert(nls.localize('suggestionAriaAccepted', "{0}, accepted", item.suggestion.label));
			this.editor.focus();
513
		});
J
Joao Moreno 已提交
514
	}
E
Erich Gamma 已提交
515

J
Johannes Rieken 已提交
516
	private _getSuggestionAriaAlertLabel(item: ICompletionItem): string {
517
		if (canExpandCompletionItem(item)) {
J
Johannes Rieken 已提交
518
			return nls.localize('ariaCurrentSuggestionWithDetails', "{0}, suggestion, has details", item.suggestion.label);
519
		} else {
J
Johannes Rieken 已提交
520
			return nls.localize('ariaCurrentSuggestion', "{0}, suggestion", item.suggestion.label);
521 522 523 524
		}
	}

	private _lastAriaAlertLabel: string;
J
Johannes Rieken 已提交
525
	private _ariaAlert(newAriaAlertLabel: string): void {
526 527 528 529 530 531 532 533 534
		if (this._lastAriaAlertLabel === newAriaAlertLabel) {
			return;
		}
		this._lastAriaAlertLabel = newAriaAlertLabel;
		if (this._lastAriaAlertLabel) {
			alert(this._lastAriaAlertLabel);
		}
	}

M
Martin Aeschlimann 已提交
535 536 537
	private onThemeChange(theme: ITheme) {
		let backgroundColor = theme.getColor(editorSuggestWidgetBackground);
		if (backgroundColor) {
538 539
			this.listElement.style.backgroundColor = backgroundColor.toString();
			this.details.element.style.backgroundColor = backgroundColor.toString();
R
Ramya Achutha Rao 已提交
540
			this.messageElement.style.backgroundColor = backgroundColor.toString();
M
Martin Aeschlimann 已提交
541 542 543
		}
		let borderColor = theme.getColor(editorSuggestWidgetBorder);
		if (borderColor) {
544 545 546
			this.listElement.style.borderColor = borderColor.toString();
			this.details.element.style.borderColor = borderColor.toString();
			this.messageElement.style.borderColor = borderColor.toString();
547
			this.detailsBorderColor = borderColor.toString();
M
Martin Aeschlimann 已提交
548
		}
549 550 551 552
		let focusBorderColor = theme.getColor(focusBorder);
		if (focusBorderColor) {
			this.detailsFocusBorderColor = focusBorderColor.toString();
		}
553
		this.details.setBorderWidth(theme.type === 'hc' ? 2 : 1);
M
Martin Aeschlimann 已提交
554 555
	}

J
Joao Moreno 已提交
556
	private onListFocus(e: IListEvent<ICompletionItem>): void {
557 558 559 560
		if (this.ignoreFocusEvents) {
			return;
		}

J
Joao Moreno 已提交
561
		if (!e.elements.length) {
J
Joao Moreno 已提交
562 563 564 565 566
			if (this.currentSuggestionDetails) {
				this.currentSuggestionDetails.cancel();
				this.currentSuggestionDetails = null;
				this.focusedItem = null;
			}
567

J
Joao Moreno 已提交
568
			this._ariaAlert(null);
J
Joao Moreno 已提交
569 570
			return;
		}
E
Erich Gamma 已提交
571

J
Joao Moreno 已提交
572
		const item = e.elements[0];
573
		this._ariaAlert(this._getSuggestionAriaAlertLabel(item));
574

575
		this.firstFocusInCurrentList = !this.focusedItem;
J
Joao Moreno 已提交
576 577 578
		if (item === this.focusedItem) {
			return;
		}
E
Erich Gamma 已提交
579

J
Joao Moreno 已提交
580 581 582 583 584
		if (this.currentSuggestionDetails) {
			this.currentSuggestionDetails.cancel();
			this.currentSuggestionDetails = null;
		}

J
Joao Moreno 已提交
585
		const index = e.indexes[0];
E
Erich Gamma 已提交
586

587
		this.suggestionSupportsAutoAccept.set(!item.suggestion.noAutoAccept);
588

J
Joao Moreno 已提交
589
		this.focusedItem = item;
590

J
Joao Moreno 已提交
591
		this.list.reveal(index);
J
Joao Moreno 已提交
592

593 594 595 596 597 598 599 600 601 602 603 604 605 606
		this.currentSuggestionDetails = createCancelablePromise(token => item.resolve(token));

		this.currentSuggestionDetails.then(() => {
			// item can have extra information, so re-render
			this.ignoreFocusEvents = true;
			this.list.splice(index, 1, [item]);
			this.list.setFocus([index]);
			this.ignoreFocusEvents = false;

			if (this.expandDocsSettingFromStorage()) {
				this.showDetails();
			} else {
				removeClass(this.element, 'docs-side');
			}
J
Joao Moreno 已提交
607 608 609 610 611
		}).catch(onUnexpectedError).then(() => {
			if (this.focusedItem === item) {
				this.currentSuggestionDetails = null;
			}
		});
612 613

		// emit an event
614
		this.onDidFocusEmitter.fire({ item, index, model: this.completionModel });
J
Joao Moreno 已提交
615
	}
J
Joao Moreno 已提交
616 617

	private setState(state: State): void {
J
Joao Moreno 已提交
618 619 620 621
		if (!this.element) {
			return;
		}

622
		const stateChanged = this.state !== state;
J
Joao Moreno 已提交
623 624
		this.state = state;

J
Joao Moreno 已提交
625 626
		toggleClass(this.element, 'frozen', state === State.Frozen);

J
Joao Moreno 已提交
627 628
		switch (state) {
			case State.Hidden:
629
				hide(this.messageElement, this.details.element, this.listElement);
J
Joao Moreno 已提交
630
				this.hide();
631
				this.listHeight = 0;
A
tslint  
Alex Dima 已提交
632
				if (stateChanged) {
633
					this.list.splice(0, this.list.length);
A
tslint  
Alex Dima 已提交
634
				}
635
				this.focusedItem = null;
636
				break;
J
Joao Moreno 已提交
637
			case State.Loading:
J
Joao Moreno 已提交
638
				this.messageElement.textContent = SuggestWidget.LOADING_MESSAGE;
J
Joao Moreno 已提交
639
				hide(this.listElement, this.details.element);
J
Joao Moreno 已提交
640
				show(this.messageElement);
R
Ramya Achutha Rao 已提交
641
				removeClass(this.element, 'docs-side');
642
				this.show();
643
				this.focusedItem = null;
J
Joao Moreno 已提交
644 645
				break;
			case State.Empty:
J
Joao Moreno 已提交
646
				this.messageElement.textContent = SuggestWidget.NO_SUGGESTIONS_MESSAGE;
J
Joao Moreno 已提交
647
				hide(this.listElement, this.details.element);
J
Joao Moreno 已提交
648
				show(this.messageElement);
R
Ramya Achutha Rao 已提交
649
				removeClass(this.element, 'docs-side');
650
				this.show();
651
				this.focusedItem = null;
J
Joao Moreno 已提交
652 653
				break;
			case State.Open:
654
				hide(this.messageElement);
655
				show(this.listElement);
656
				this.show();
J
Joao Moreno 已提交
657 658
				break;
			case State.Frozen:
659
				hide(this.messageElement);
J
Joao Moreno 已提交
660
				show(this.listElement);
661
				this.show();
J
Joao Moreno 已提交
662 663
				break;
			case State.Details:
664 665
				hide(this.messageElement);
				show(this.details.element, this.listElement);
666
				this.show();
667
				this._ariaAlert(this.details.getAriaLabel());
J
Joao Moreno 已提交
668 669
				break;
		}
670 671
	}

672
	showTriggered(auto: boolean) {
J
Joao Moreno 已提交
673 674 675
		if (this.state !== State.Hidden) {
			return;
		}
E
Erich Gamma 已提交
676

677
		this.isAuto = !!auto;
J
Joao Moreno 已提交
678 679 680 681 682 683 684

		if (!this.isAuto) {
			this.loadingTimeout = setTimeout(() => {
				this.loadingTimeout = null;
				this.setState(State.Loading);
			}, 50);
		}
685
	}
E
Erich Gamma 已提交
686

687
	showSuggestions(completionModel: CompletionModel, selectionIndex: number, isFrozen: boolean, isAuto: boolean): void {
A
Alex Dima 已提交
688 689 690 691
		if (this.loadingTimeout) {
			clearTimeout(this.loadingTimeout);
			this.loadingTimeout = null;
		}
J
Joao Moreno 已提交
692

693 694 695
		if (this.completionModel !== completionModel) {
			this.completionModel = completionModel;
		}
J
Joao Moreno 已提交
696

R
Ramya Achutha Rao 已提交
697
		if (isFrozen && this.state !== State.Empty && this.state !== State.Hidden) {
698 699
			this.setState(State.Frozen);
			return;
700 701
		}

702 703
		let visibleCount = this.completionModel.items.length;

J
Joao Moreno 已提交
704
		const isEmpty = visibleCount === 0;
705
		this.suggestWidgetMultipleSuggestions.set(visibleCount > 1);
J
Joao Moreno 已提交
706 707

		if (isEmpty) {
708
			if (isAuto) {
J
Joao Moreno 已提交
709 710
				this.setState(State.Hidden);
			} else {
Y
Yuki Ueda 已提交
711
				this.setState(State.Empty);
J
Joao Moreno 已提交
712 713
			}

J
Joao Moreno 已提交
714
			this.completionModel = null;
J
Joao Moreno 已提交
715

J
Joao Moreno 已提交
716
		} else {
J
Joao Moreno 已提交
717
			const { stats } = this.completionModel;
718
			stats['wasAutomaticallyTriggered'] = !!isAuto;
K
kieferrm 已提交
719
			/* __GDPR__
K
kieferrm 已提交
720
				"suggestWidget" : {
K
kieferrm 已提交
721
					"wasAutomaticallyTriggered" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
K
kieferrm 已提交
722 723 724 725 726 727
					"${include}": [
						"${ICompletionStats}",
						"${EditorTelemetryData}"
					]
				}
			*/
728
			this.telemetryService.publicLog('suggestWidget', { ...stats, ...this.editor.getTelemetryData() });
J
Joao Moreno 已提交
729

730 731
			this.list.splice(0, this.list.length, this.completionModel.items);

R
Ramya Achutha Rao 已提交
732 733 734 735 736
			if (isFrozen) {
				this.setState(State.Frozen);
			} else {
				this.setState(State.Open);
			}
R
Ramya Achutha Rao 已提交
737

J
Joao Moreno 已提交
738
			this.list.reveal(selectionIndex, selectionIndex);
J
Joao Moreno 已提交
739 740
			this.list.setFocus([selectionIndex]);

R
Ramya Achutha Rao 已提交
741 742 743 744
			// Reset focus border
			if (this.detailsBorderColor) {
				this.details.element.style.borderColor = this.detailsBorderColor;
			}
J
Joao Moreno 已提交
745
		}
746
	}
E
Erich Gamma 已提交
747

J
Joao Moreno 已提交
748
	selectNextPage(): boolean {
J
Joao Moreno 已提交
749 750 751 752 753 754 755 756 757 758 759 760
		switch (this.state) {
			case State.Hidden:
				return false;
			case State.Details:
				this.details.pageDown();
				return true;
			case State.Loading:
				return !this.isAuto;
			default:
				this.list.focusNextPage();
				return true;
		}
E
Erich Gamma 已提交
761 762
	}

J
Joao Moreno 已提交
763
	selectNext(): boolean {
J
Joao Moreno 已提交
764 765 766 767 768 769 770 771 772
		switch (this.state) {
			case State.Hidden:
				return false;
			case State.Loading:
				return !this.isAuto;
			default:
				this.list.focusNext(1, true);
				return true;
		}
E
Erich Gamma 已提交
773 774
	}

775 776 777 778 779
	selectLast(): boolean {
		switch (this.state) {
			case State.Hidden:
				return false;
			case State.Details:
780
				this.details.scrollBottom();
781 782 783 784 785 786 787 788 789
				return true;
			case State.Loading:
				return !this.isAuto;
			default:
				this.list.focusLast();
				return true;
		}
	}

J
Joao Moreno 已提交
790
	selectPreviousPage(): boolean {
J
Joao Moreno 已提交
791 792 793 794 795 796 797 798 799 800 801 802
		switch (this.state) {
			case State.Hidden:
				return false;
			case State.Details:
				this.details.pageUp();
				return true;
			case State.Loading:
				return !this.isAuto;
			default:
				this.list.focusPreviousPage();
				return true;
		}
E
Erich Gamma 已提交
803 804
	}

J
Joao Moreno 已提交
805
	selectPrevious(): boolean {
J
Joao Moreno 已提交
806 807 808 809 810 811 812
		switch (this.state) {
			case State.Hidden:
				return false;
			case State.Loading:
				return !this.isAuto;
			default:
				this.list.focusPrevious(1, true);
J
Joao Moreno 已提交
813
				return false;
J
Joao Moreno 已提交
814
		}
E
Erich Gamma 已提交
815 816
	}

817 818 819 820 821
	selectFirst(): boolean {
		switch (this.state) {
			case State.Hidden:
				return false;
			case State.Details:
822
				this.details.scrollTop();
823 824 825 826 827 828 829 830 831
				return true;
			case State.Loading:
				return !this.isAuto;
			default:
				this.list.focusFirst();
				return true;
		}
	}

832
	getFocusedItem(): ISelectedSuggestion {
833 834 835 836
		if (this.state !== State.Hidden
			&& this.state !== State.Empty
			&& this.state !== State.Loading) {

837 838 839 840 841
			return {
				item: this.list.getFocusedElements()[0],
				index: this.list.getFocus()[0],
				model: this.completionModel
			};
J
Joao Moreno 已提交
842
		}
843
		return undefined;
E
Erich Gamma 已提交
844 845
	}

846
	toggleDetailsFocus(): void {
J
Joao Moreno 已提交
847 848
		if (this.state === State.Details) {
			this.setState(State.Open);
849 850 851
			if (this.detailsBorderColor) {
				this.details.element.style.borderColor = this.detailsBorderColor;
			}
852
		} else if (this.state === State.Open && this.expandDocsSettingFromStorage()) {
853
			this.setState(State.Details);
854 855 856
			if (this.detailsFocusBorderColor) {
				this.details.element.style.borderColor = this.detailsFocusBorderColor;
			}
J
Joao Moreno 已提交
857
		}
K
kieferrm 已提交
858
		/* __GDPR__
K
kieferrm 已提交
859 860 861 862 863 864
			"suggestWidget:toggleDetailsFocus" : {
				"${include}": [
					"${EditorTelemetryData}"
				]
			}
		*/
865
		this.telemetryService.publicLog('suggestWidget:toggleDetailsFocus', this.editor.getTelemetryData());
866
	}
J
Joao Moreno 已提交
867

868
	toggleDetails(): void {
R
Ramya Achutha Rao 已提交
869 870 871
		if (!canExpandCompletionItem(this.list.getFocusedElements()[0])) {
			return;
		}
872

873 874
		if (this.expandDocsSettingFromStorage()) {
			this.updateExpandDocsSetting(false);
875
			hide(this.details.element);
876
			removeClass(this.element, 'docs-side');
877
			removeClass(this.element, 'docs-below');
878
			this.editor.layoutContentWidget(this);
K
kieferrm 已提交
879
			/* __GDPR__
K
kieferrm 已提交
880 881 882 883 884 885
				"suggestWidget:collapseDetails" : {
					"${include}": [
						"${EditorTelemetryData}"
					]
				}
			*/
886
			this.telemetryService.publicLog('suggestWidget:collapseDetails', this.editor.getTelemetryData());
887
		} else {
888
			if (this.state !== State.Open && this.state !== State.Details && this.state !== State.Frozen) {
889 890 891
				return;
			}

892
			this.updateExpandDocsSetting(true);
893
			this.showDetails();
K
kieferrm 已提交
894
			/* __GDPR__
K
kieferrm 已提交
895 896 897 898 899 900
				"suggestWidget:expandDetails" : {
					"${include}": [
						"${EditorTelemetryData}"
					]
				}
			*/
901
			this.telemetryService.publicLog('suggestWidget:expandDetails', this.editor.getTelemetryData());
902
		}
903

904 905
	}

906
	showDetails(): void {
R
Ramya Achutha Rao 已提交
907
		this.expandSideOrBelow();
908 909

		show(this.details.element);
910
		this.details.render(this.list.getFocusedElements()[0]);
911
		this.details.element.style.maxHeight = this.maxWidgetHeight + 'px';
912

R
Ramya Achutha Rao 已提交
913 914
		// Reset margin-top that was set as Fix for #26416
		this.listElement.style.marginTop = '0px';
915 916 917 918 919

		// with docs showing up widget width/height may change, so reposition the widget
		this.editor.layoutContentWidget(this);

		this.adjustDocsPosition();
J
Joao Moreno 已提交
920

J
Joao Moreno 已提交
921
		this.editor.focus();
R
Ramya Achutha Rao 已提交
922 923

		this._ariaAlert(this.details.getAriaLabel());
J
Joao Moreno 已提交
924 925
	}

926
	private show(): void {
927 928 929 930 931 932
		const newHeight = this.updateListHeight();
		if (newHeight !== this.listHeight) {
			this.editor.layoutContentWidget(this);
			this.listHeight = newHeight;
		}

J
Joao Moreno 已提交
933
		this.suggestWidgetVisible.set(true);
934

935
		this.showTimeout.cancelAndSet(() => {
J
Joao Moreno 已提交
936
			addClass(this.element, 'visible');
937
			this.onDidShowEmitter.fire(this);
938
		}, 100);
E
Erich Gamma 已提交
939 940
	}

941
	private hide(): void {
J
Joao Moreno 已提交
942
		this.suggestWidgetVisible.reset();
S
Sean Kelly 已提交
943
		this.suggestWidgetMultipleSuggestions.reset();
J
Joao Moreno 已提交
944
		removeClass(this.element, 'visible');
E
Erich Gamma 已提交
945 946
	}

947 948 949
	hideWidget(): void {
		clearTimeout(this.loadingTimeout);
		this.setState(State.Hidden);
950
		this.onDidHideEmitter.fire(this);
951 952
	}

J
Joao Moreno 已提交
953
	getPosition(): IContentWidgetPosition {
J
Joao Moreno 已提交
954 955
		if (this.state === State.Hidden) {
			return null;
E
Erich Gamma 已提交
956
		}
J
Joao Moreno 已提交
957 958

		return {
959
			position: this.editor.getPosition(),
A
Alex Dima 已提交
960
			preference: [ContentWidgetPositionPreference.BELOW, ContentWidgetPositionPreference.ABOVE]
J
Joao Moreno 已提交
961
		};
E
Erich Gamma 已提交
962 963
	}

J
Joao Moreno 已提交
964
	getDomNode(): HTMLElement {
E
Erich Gamma 已提交
965 966 967
		return this.element;
	}

J
Joao Moreno 已提交
968
	getId(): string {
E
Erich Gamma 已提交
969 970 971
		return SuggestWidget.ID;
	}

972
	private updateListHeight(): number {
J
Joao Moreno 已提交
973
		let height = 0;
E
Erich Gamma 已提交
974

J
Joao Moreno 已提交
975
		if (this.state === State.Empty || this.state === State.Loading) {
976
			height = this.unfocusedHeight;
J
Joao Moreno 已提交
977
		} else {
978 979
			const suggestionCount = this.list.contentHeight / this.unfocusedHeight;
			height = Math.min(suggestionCount, maxSuggestionsToShow) * this.unfocusedHeight;
J
Joao Moreno 已提交
980
		}
J
Joao Moreno 已提交
981

982
		this.element.style.lineHeight = `${this.unfocusedHeight}px`;
983
		this.listElement.style.height = `${height}px`;
J
Joao Moreno 已提交
984
		this.list.layout(height);
985
		return height;
J
Joao Moreno 已提交
986 987
	}

988
	private adjustDocsPosition() {
R
Ramya Achutha Rao 已提交
989
		const lineHeight = this.editor.getConfiguration().fontInfo.lineHeight;
990 991 992 993
		const cursorCoords = this.editor.getScrolledVisiblePosition(this.editor.getPosition());
		const editorCoords = getDomNodePagePosition(this.editor.getDomNode());
		const cursorX = editorCoords.left + cursorCoords.left;
		const cursorY = editorCoords.top + cursorCoords.top + cursorCoords.height;
994 995 996
		const widgetCoords = getDomNodePagePosition(this.element);
		const widgetX = widgetCoords.left;
		const widgetY = widgetCoords.top;
997

998 999 1000
		if (widgetX < cursorX - this.listWidth) {
			// Widget is too far to the left of cursor, swap list and docs
			addClass(this.element, 'list-right');
1001 1002
		} else {
			removeClass(this.element, 'list-right');
1003 1004
		}

R
Ramya Achutha Rao 已提交
1005 1006 1007
		// Compare top of the cursor (cursorY - lineheight) with widgetTop to determine if
		// margin-top needs to be applied on list to make it appear right above the cursor
		// Cannot compare cursorY directly as it may be a few decimals off due to zoooming
R
Ramya Achutha Rao 已提交
1008
		if (hasClass(this.element, 'docs-side')
R
Ramya Achutha Rao 已提交
1009
			&& cursorY - lineHeight > widgetY
R
Ramya Achutha Rao 已提交
1010 1011 1012 1013 1014
			&& this.details.element.offsetHeight > this.listElement.offsetHeight) {

			// Fix for #26416
			// Docs is bigger than list and widget is above cursor, apply margin-top so that list appears right above cursor
			this.listElement.style.marginTop = `${this.details.element.offsetHeight - this.listElement.offsetHeight}px`;
1015
		}
1016 1017
	}

1018
	private expandSideOrBelow() {
1019 1020 1021 1022 1023 1024
		if (!canExpandCompletionItem(this.focusedItem) && this.firstFocusInCurrentList) {
			removeClass(this.element, 'docs-side');
			removeClass(this.element, 'docs-below');
			return;
		}

1025 1026 1027 1028
		let matches = this.element.style.maxWidth.match(/(\d+)px/);
		if (!matches || Number(matches[1]) < this.maxWidgetWidth) {
			addClass(this.element, 'docs-below');
			removeClass(this.element, 'docs-side');
1029
		} else if (canExpandCompletionItem(this.focusedItem)) {
1030 1031 1032 1033 1034
			addClass(this.element, 'docs-side');
			removeClass(this.element, 'docs-below');
		}
	}

1035 1036
	// Heights

1037 1038
	private get maxWidgetHeight(): number {
		return this.unfocusedHeight * maxSuggestionsToShow;
1039 1040 1041
	}

	private get unfocusedHeight(): number {
J
Joao Moreno 已提交
1042 1043
		const configuration = this.editor.getConfiguration();
		return configuration.contribInfo.suggestLineHeight || configuration.fontInfo.lineHeight;
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055
	}

	// IDelegate

	getHeight(element: ICompletionItem): number {
		return this.unfocusedHeight;
	}

	getTemplateId(element: ICompletionItem): string {
		return 'suggestion';
	}

1056 1057 1058
	// Monaco Editor does not have a storage service
	private expandDocsSettingFromStorage(): boolean {
		if (this.storageServiceAvailable) {
1059
			return this.storageService.getBoolean('expandSuggestionDocs', StorageScope.GLOBAL);
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
		} else {
			return this.expandSuggestionDocs;
		}
	}

	// Monaco Editor does not have a storage service
	private updateExpandDocsSetting(value: boolean) {
		if (this.storageServiceAvailable) {
			this.storageService.store('expandSuggestionDocs', value, StorageScope.GLOBAL);
		} else {
			this.expandSuggestionDocs = value;
		}
	}

J
Joao Moreno 已提交
1074
	dispose(): void {
J
Joao Moreno 已提交
1075 1076 1077
		this.state = null;
		this.suggestionSupportsAutoAccept = null;
		this.currentSuggestionDetails = null;
J
Joao Moreno 已提交
1078
		this.focusedItem = null;
J
Joao Moreno 已提交
1079 1080
		this.element = null;
		this.messageElement = null;
J
Joao Moreno 已提交
1081
		this.listElement = null;
J
Joao Moreno 已提交
1082 1083
		this.details.dispose();
		this.details = null;
J
Joao Moreno 已提交
1084 1085
		this.list.dispose();
		this.list = null;
J
Joao Moreno 已提交
1086
		this.toDispose = dispose(this.toDispose);
A
Alex Dima 已提交
1087 1088 1089 1090
		if (this.loadingTimeout) {
			clearTimeout(this.loadingTimeout);
			this.loadingTimeout = null;
		}
J
Joao Moreno 已提交
1091

1092 1093
		this.editorBlurTimeout.dispose();
		this.showTimeout.dispose();
E
Erich Gamma 已提交
1094
	}
J
Johannes Rieken 已提交
1095
}
1096 1097

registerThemingParticipant((theme, collector) => {
1098
	let matchHighlight = theme.getColor(editorSuggestWidgetHighlightForeground);
1099
	if (matchHighlight) {
J
Johannes Rieken 已提交
1100
		collector.addRule(`.monaco-editor .suggest-widget .monaco-list .monaco-list-row .monaco-highlighted-label .highlight { color: ${matchHighlight}; }`);
1101
	}
1102 1103
	let foreground = theme.getColor(editorSuggestWidgetForeground);
	if (foreground) {
1104
		collector.addRule(`.monaco-editor .suggest-widget { color: ${foreground}; }`);
1105
	}
M
Matt Bierner 已提交
1106 1107 1108 1109 1110

	const link = theme.getColor(textLinkForeground);
	if (link) {
		collector.addRule(`.monaco-editor .suggest-widget a { color: ${link}; }`);
	}
1111 1112 1113 1114 1115

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