suggestWidget.ts 33.8 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';
J
Joao Moreno 已提交
12
import Event, { Emitter, chain } from 'vs/base/common/event';
J
Joao Moreno 已提交
13
import { TPromise } from 'vs/base/common/winjs.base';
J
Johannes Rieken 已提交
14
import { isPromiseCanceledError, onUnexpectedError } from 'vs/base/common/errors';
J
Joao Moreno 已提交
15
import { IDisposable, dispose, toDisposable } from 'vs/base/common/lifecycle';
16
import { addClass, append, $, hide, removeClass, show, toggleClass, getDomNodePagePosition, hasClass } from 'vs/base/browser/dom';
J
Joao Moreno 已提交
17
import { HighlightedLabel } from 'vs/base/browser/ui/highlightedlabel/highlightedLabel';
J
Joao Moreno 已提交
18
import { IDelegate, IListEvent, IRenderer } from 'vs/base/browser/ui/list/list';
J
Joao Moreno 已提交
19 20
import { List } from 'vs/base/browser/ui/list/listWidget';
import { DomScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement';
J
Johannes Rieken 已提交
21 22
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
23
import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions';
J
Joao Moreno 已提交
24
import { ContentWidgetPositionPreference, ICodeEditor, IContentWidget, IContentWidgetPosition } from 'vs/editor/browser/editorBrowser';
25 26
import { Context as SuggestContext } from './suggest';
import { ICompletionItem, CompletionModel } from './completionModel';
J
Johannes Rieken 已提交
27
import { alert } from 'vs/base/browser/ui/aria/aria';
J
Joao Moreno 已提交
28
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
29 30
import { attachListStyler } from 'vs/platform/theme/common/styler';
import { IThemeService, ITheme, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
31
import { registerColor, editorWidgetBackground, listFocusBackground, activeContrastBorder, listHighlightForeground, editorForeground, editorWidgetBorder, focusBorder, textLinkForeground, textCodeBlockBackground } from 'vs/platform/theme/common/colorRegistry';
32
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
33
import { MarkdownRenderer } from 'vs/editor/contrib/markdown/markdownRenderer';
34 35
import { IModeService } from 'vs/editor/common/services/modeService';
import { IOpenerService } from 'vs/platform/opener/common/opener';
E
Erich Gamma 已提交
36

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

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

M
Martin Aeschlimann 已提交
51 52 53
/**
 * Suggest widget colors
 */
54
export const editorSuggestWidgetBackground = registerColor('editorSuggestWidget.background', { dark: editorWidgetBackground, light: editorWidgetBackground, hc: editorWidgetBackground }, nls.localize('editorSuggestWidgetBackground', 'Background color of the suggest widget.'));
55
export const editorSuggestWidgetBorder = registerColor('editorSuggestWidget.border', { dark: editorWidgetBorder, light: editorWidgetBorder, hc: editorWidgetBorder }, nls.localize('editorSuggestWidgetBorder', 'Border color of the suggest widget.'));
56 57 58
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.'));
59

M
Martin Aeschlimann 已提交
60

61
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;
62 63 64
function matchesColor(text: string) {
	return text && text.match(colorRegExp) ? text : null;
}
65

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

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

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

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

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

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

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

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

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

108
		const configureFont = () => {
J
Joao Moreno 已提交
109 110 111 112
			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 已提交
113 114
			const fontSizePx = `${fontSize}px`;
			const lineHeightPx = `${lineHeight}px`;
J
Joao Moreno 已提交
115 116 117 118 119 120

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

		configureFont();

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

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

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

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

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

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

J
Johannes Rieken 已提交
155
		data.highlightedLabel.set(suggestion.label, createMatches(element.matches));
156
		data.typeLabel.textContent = (suggestion.detail || '').replace(/\n.*$/m, '');
J
Joao Moreno 已提交
157

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

E
Erich Gamma 已提交
175 176
	}

J
Joao Moreno 已提交
177 178
	disposeTemplate(templateData: ISuggestionTemplateData): void {
		templateData.highlightedLabel.dispose();
179
		templateData.disposables = dispose(templateData.disposables);
J
Joao Moreno 已提交
180 181
	}
}
E
Erich Gamma 已提交
182

A
Alex Dima 已提交
183
const enum State {
J
Joao Moreno 已提交
184 185 186
	Hidden,
	Loading,
	Empty,
J
Joao Moreno 已提交
187
	Open,
J
Joao Moreno 已提交
188 189 190 191 192 193 194
	Frozen,
	Details
}

class SuggestionDetails {

	private el: HTMLElement;
195
	private close: HTMLElement;
196
	private scrollbar: DomScrollableElement;
197
	private body: HTMLElement;
198
	private header: HTMLElement;
J
Joao Moreno 已提交
199 200
	private type: HTMLElement;
	private docs: HTMLElement;
201 202
	private ariaLabel: string;
	private disposables: IDisposable[];
203
	private borderWidth: number = 1;
204 205 206 207

	constructor(
		container: HTMLElement,
		private widget: SuggestWidget,
208
		private editor: ICodeEditor,
209
		private markdownRenderer: MarkdownRenderer,
210
		private triggerKeybindingLabel: string
211 212
	) {
		this.disposables = [];
J
Joao Moreno 已提交
213 214

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

217
		this.body = $('.body');
218

219
		this.scrollbar = new DomScrollableElement(this.body, {});
220
		append(this.el, this.scrollbar.getDomNode());
221 222
		this.disposables.push(this.scrollbar);

223 224
		this.header = append(this.body, $('.header'));
		this.close = append(this.header, $('span.close'));
225
		this.close.title = nls.localize('readLess', "Read less...{0}", this.triggerKeybindingLabel);
226
		this.type = append(this.header, $('p.type'));
227

228
		this.docs = append(this.body, $('p.docs'));
229
		this.ariaLabel = null;
230 231 232

		this.configureFont();

J
Joao Moreno 已提交
233 234 235
		chain<IConfigurationChangedEvent>(this.editor.onDidChangeConfiguration.bind(this.editor))
			.filter(e => e.fontInfo)
			.on(this.configureFont, this, this.disposables);
J
Joao Moreno 已提交
236 237
	}

J
Joao Moreno 已提交
238 239 240
	get element() {
		return this.el;
	}
J
Joao Moreno 已提交
241

242
	render(item: ICompletionItem): void {
243
		if (!item || !canExpandCompletionItem(item)) {
J
Joao Moreno 已提交
244 245
			this.type.textContent = '';
			this.docs.textContent = '';
246
			addClass(this.el, 'no-docs');
247
			this.ariaLabel = null;
J
Joao Moreno 已提交
248 249
			return;
		}
250
		removeClass(this.el, 'no-docs');
251
		if (typeof item.suggestion.documentation === 'string') {
252
			removeClass(this.docs, 'markdown-docs');
253 254
			this.docs.textContent = item.suggestion.documentation;
		} else {
255
			addClass(this.docs, 'markdown-docs');
M
Matt Bierner 已提交
256 257
			this.docs.innerHTML = '';
			this.docs.appendChild(this.markdownRenderer.render(item.suggestion.documentation));
258
		}
259

R
Ramya Achutha Rao 已提交
260 261 262 263 264 265 266 267
		if (item.suggestion.detail) {
			this.type.innerText = item.suggestion.detail;
			show(this.type);
		} else {
			this.type.innerText = '';
			hide(this.type);
		}

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

270
		this.close.onmousedown = e => {
271 272 273
			e.preventDefault();
			e.stopPropagation();
		};
274
		this.close.onclick = e => {
275 276 277 278
			e.preventDefault();
			e.stopPropagation();
			this.widget.toggleDetails();
		};
279

J
Joao Moreno 已提交
280
		this.body.scrollTop = 0;
281
		this.scrollbar.scanDomNode();
282

283
		this.ariaLabel = strings.format('{0}\n{1}\n{2}', item.suggestion.label || '', item.suggestion.detail || '', item.suggestion.documentation || '');
284 285 286 287
	}

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

290 291 292 293 294 295 296 297
	scrollDown(much = 8): void {
		this.body.scrollTop += much;
	}

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

298 299 300 301 302 303 304 305
	scrollTop(): void {
		this.body.scrollTop = 0;
	}

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

306 307 308 309 310 311 312 313
	pageDown(): void {
		this.scrollDown(80);
	}

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

314 315 316 317
	setBorderWidth(width: number): void {
		this.borderWidth = width;
	}

318
	private configureFont() {
J
Joao Moreno 已提交
319 320 321
		const configuration = this.editor.getConfiguration();
		const fontFamily = configuration.fontInfo.fontFamily;
		const fontSize = configuration.contribInfo.suggestFontSize || configuration.fontInfo.fontSize;
322
		const lineHeight = configuration.contribInfo.suggestLineHeight || configuration.fontInfo.lineHeight;
J
Johannes Rieken 已提交
323
		const fontSizePx = `${fontSize}px`;
324
		const lineHeightPx = `${lineHeight}px`;
J
Joao Moreno 已提交
325

J
Joao Moreno 已提交
326 327
		this.el.style.fontSize = fontSizePx;
		this.type.style.fontFamily = fontFamily;
328 329
		this.close.style.height = lineHeightPx;
		this.close.style.width = lineHeightPx;
330
	}
331

332 333
	dispose(): void {
		this.disposables = dispose(this.disposables);
J
Joao Moreno 已提交
334
	}
J
Joao Moreno 已提交
335 336
}

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

339
	private static ID: string = 'editor.widget.suggestWidget';
E
Erich Gamma 已提交
340

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

J
Joao Moreno 已提交
344
	// Editor.IContentWidget.allowEditorOverflow
345
	readonly allowEditorOverflow = true;
J
Joao Moreno 已提交
346

J
Joao Moreno 已提交
347
	private state: State;
E
Erich Gamma 已提交
348
	private isAuto: boolean;
349
	private loadingTimeout: number;
J
Joao Moreno 已提交
350
	private currentSuggestionDetails: TPromise<void>;
351
	private focusedItemIndex: number;
352
	private focusedItem: ICompletionItem;
353
	private ignoreFocusEvents = false;
J
Joao Moreno 已提交
354
	private completionModel: CompletionModel;
J
Joao Moreno 已提交
355

E
Erich Gamma 已提交
356
	private element: HTMLElement;
J
Joao Moreno 已提交
357
	private messageElement: HTMLElement;
J
Joao Moreno 已提交
358
	private listElement: HTMLElement;
J
Joao Moreno 已提交
359
	private details: SuggestionDetails;
360
	private list: List<ICompletionItem>;
E
Erich Gamma 已提交
361

A
Alex Dima 已提交
362 363 364
	private suggestWidgetVisible: IContextKey<boolean>;
	private suggestWidgetMultipleSuggestions: IContextKey<boolean>;
	private suggestionSupportsAutoAccept: IContextKey<boolean>;
J
Joao Moreno 已提交
365

J
Joao Moreno 已提交
366 367
	private editorBlurTimeout: TPromise<void>;
	private showTimeout: TPromise<void>;
J
Joao Moreno 已提交
368
	private toDispose: IDisposable[];
J
Joao Moreno 已提交
369

370 371
	private onDidSelectEmitter = new Emitter<ICompletionItem>();
	private onDidFocusEmitter = new Emitter<ICompletionItem>();
372 373 374
	private onDidHideEmitter = new Emitter<this>();
	private onDidShowEmitter = new Emitter<this>();

375 376 377

	readonly onDidSelect: Event<ICompletionItem> = this.onDidSelectEmitter.event;
	readonly onDidFocus: Event<ICompletionItem> = this.onDidFocusEmitter.event;
378 379
	readonly onDidHide: Event<this> = this.onDidHideEmitter.event;
	readonly onDidShow: Event<this> = this.onDidShowEmitter.event;
380

381
	private readonly maxWidgetWidth = 660;
382
	private readonly listWidth = 330;
383
	private storageService: IStorageService;
384 385
	private detailsFocusBorderColor: string;
	private detailsBorderColor: string;
386

387 388 389
	private storageServiceAvailable: boolean = true;
	private expandSuggestionDocs: boolean = false;

390
	constructor(
A
Alex Dima 已提交
391
		private editor: ICodeEditor,
J
Joao Moreno 已提交
392
		@ITelemetryService private telemetryService: ITelemetryService,
393
		@IContextKeyService contextKeyService: IContextKeyService,
394 395
		@IThemeService themeService: IThemeService,
		@IStorageService storageService: IStorageService,
396 397 398
		@IKeybindingService keybindingService: IKeybindingService,
		@IModeService modeService: IModeService,
		@IOpenerService openerService: IOpenerService
399
	) {
400 401
		const kb = keybindingService.lookupKeybinding('editor.action.triggerSuggest');
		const triggerKeybindingLabel = !kb ? '' : ` (${kb.getLabel()})`;
402
		const markdownRenderer = new MarkdownRenderer(editor, modeService, openerService);
403

E
Erich Gamma 已提交
404
		this.isAuto = false;
J
Joao Moreno 已提交
405
		this.focusedItem = null;
406
		this.storageService = storageService;
407 408 409 410 411 412

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

415
		this.element = $('.editor-widget.suggest-widget');
A
Alex Dima 已提交
416
		if (!this.editor.getConfiguration().contribInfo.iconsInSuggestions) {
J
Joao Moreno 已提交
417
			addClass(this.element, 'no-icons');
E
Erich Gamma 已提交
418 419
		}

J
Joao Moreno 已提交
420
		this.messageElement = append(this.element, $('.message'));
J
Joao Moreno 已提交
421
		this.listElement = append(this.element, $('.tree'));
422
		this.details = new SuggestionDetails(this.element, this, this.editor, markdownRenderer, triggerKeybindingLabel);
J
Joao Moreno 已提交
423

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

426 427
		this.list = new List(this.listElement, this, [renderer], {
			useShadows: false,
J
Joao Moreno 已提交
428 429
			selectOnMouseDown: true,
			focusOnMouseDown: false
430
		});
J
Joao Moreno 已提交
431 432

		this.toDispose = [
433 434 435 436
			attachListStyler(this.list, themeService, {
				listInactiveFocusBackground: editorSuggestWidgetSelectedBackground,
				listInactiveFocusOutline: activeContrastBorder
			}),
M
Martin Aeschlimann 已提交
437
			themeService.onThemeChange(t => this.onThemeChange(t)),
A
Alex Dima 已提交
438
			editor.onDidBlurEditorText(() => this.onEditorBlur()),
439
			editor.onDidLayoutChange(() => this.onEditorLayoutChange()),
J
Joao Moreno 已提交
440
			this.list.onSelectionChange(e => this.onListSelection(e)),
J
Joao Moreno 已提交
441
			this.list.onFocusChange(e => this.onListFocus(e)),
442
			this.editor.onDidChangeCursorSelection(() => this.onCursorSelectionChanged())
J
Joao Moreno 已提交
443 444
		];

445 446 447
		this.suggestWidgetVisible = SuggestContext.Visible.bindTo(contextKeyService);
		this.suggestWidgetMultipleSuggestions = SuggestContext.MultipleSuggestions.bindTo(contextKeyService);
		this.suggestionSupportsAutoAccept = SuggestContext.AcceptOnKey.bindTo(contextKeyService);
J
Joao Moreno 已提交
448

J
Joao Moreno 已提交
449 450
		this.editor.addContentWidget(this);
		this.setState(State.Hidden);
451

M
Martin Aeschlimann 已提交
452 453
		this.onThemeChange(themeService.getTheme());

454 455 456 457 458 459 460 461 462 463 464 465 466
		// TODO@Alex: this is useful, but spammy
		// var isVisible = false;
		// this.onDidVisibilityChange((newIsVisible) => {
		// 	if (isVisible === newIsVisible) {
		// 		return;
		// 	}
		// 	isVisible = newIsVisible;
		// 	if (isVisible) {
		// 		alert(nls.localize('suggestWidgetAriaVisible', "Suggestions opened"));
		// 	} else {
		// 		alert(nls.localize('suggestWidgetAriaInvisible', "Suggestions closed"));
		// 	}
		// });
J
Joao Moreno 已提交
467
	}
E
Erich Gamma 已提交
468

J
Joao Moreno 已提交
469 470 471 472
	private onCursorSelectionChanged(): void {
		if (this.state === State.Hidden) {
			return;
		}
E
Erich Gamma 已提交
473

J
Joao Moreno 已提交
474 475
		this.editor.layoutContentWidget(this);
	}
J
Joao Moreno 已提交
476

J
Joao Moreno 已提交
477
	private onEditorBlur(): void {
J
Joao Moreno 已提交
478 479 480 481
		if (sticky) {
			return;
		}

J
Joao Moreno 已提交
482
		this.editorBlurTimeout = TPromise.timeout(150).then(() => {
J
Joao Moreno 已提交
483
			if (!this.editor.isFocused()) {
J
Joao Moreno 已提交
484 485 486 487 488
				this.setState(State.Hidden);
			}
		});
	}

489 490 491 492 493 494
	private onEditorLayoutChange(): void {
		if ((this.state === State.Open || this.state === State.Details) && this.expandDocsSettingFromStorage()) {
			this.expandSideOrBelow();
		}
	}

J
Joao Moreno 已提交
495
	private onListSelection(e: IListEvent<ICompletionItem>): void {
J
Joao Moreno 已提交
496 497 498
		if (!e.elements.length) {
			return;
		}
E
Erich Gamma 已提交
499

J
Joao Moreno 已提交
500
		const item = e.elements[0];
501 502 503
		item.resolve().then(() => {
			this.onDidSelectEmitter.fire(item);
		});
J
Joao Moreno 已提交
504 505

		alert(nls.localize('suggestionAriaAccepted', "{0}, accepted", item.suggestion.label));
J
Johannes Rieken 已提交
506 507

		this.editor.focus();
J
Joao Moreno 已提交
508
	}
E
Erich Gamma 已提交
509

J
Johannes Rieken 已提交
510
	private _getSuggestionAriaAlertLabel(item: ICompletionItem): string {
511
		if (canExpandCompletionItem(item)) {
J
Johannes Rieken 已提交
512
			return nls.localize('ariaCurrentSuggestionWithDetails', "{0}, suggestion, has details", item.suggestion.label);
513
		} else {
J
Johannes Rieken 已提交
514
			return nls.localize('ariaCurrentSuggestion', "{0}, suggestion", item.suggestion.label);
515 516 517 518
		}
	}

	private _lastAriaAlertLabel: string;
J
Johannes Rieken 已提交
519
	private _ariaAlert(newAriaAlertLabel: string): void {
520 521 522 523 524 525 526 527 528
		if (this._lastAriaAlertLabel === newAriaAlertLabel) {
			return;
		}
		this._lastAriaAlertLabel = newAriaAlertLabel;
		if (this._lastAriaAlertLabel) {
			alert(this._lastAriaAlertLabel);
		}
	}

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

J
Joao Moreno 已提交
550
	private onListFocus(e: IListEvent<ICompletionItem>): void {
551 552 553 554
		if (this.ignoreFocusEvents) {
			return;
		}

J
Joao Moreno 已提交
555
		if (!e.elements.length) {
J
Joao Moreno 已提交
556 557 558 559 560
			if (this.currentSuggestionDetails) {
				this.currentSuggestionDetails.cancel();
				this.currentSuggestionDetails = null;
				this.focusedItem = null;
			}
561

J
Joao Moreno 已提交
562
			this._ariaAlert(null);
J
Joao Moreno 已提交
563 564
			return;
		}
E
Erich Gamma 已提交
565

J
Joao Moreno 已提交
566
		const item = e.elements[0];
567
		this._ariaAlert(this._getSuggestionAriaAlertLabel(item));
568

J
Joao Moreno 已提交
569 570 571
		if (item === this.focusedItem) {
			return;
		}
E
Erich Gamma 已提交
572

J
Joao Moreno 已提交
573 574 575 576 577
		if (this.currentSuggestionDetails) {
			this.currentSuggestionDetails.cancel();
			this.currentSuggestionDetails = null;
		}

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

580
		this.suggestionSupportsAutoAccept.set(!item.suggestion.noAutoAccept);
581 582 583 584

		const oldFocus = this.focusedItem;
		const oldFocusIndex = this.focusedItemIndex;
		this.focusedItemIndex = index;
J
Joao Moreno 已提交
585
		this.focusedItem = item;
586 587 588 589 590 591 592

		if (oldFocus) {
			this.ignoreFocusEvents = true;
			this.list.splice(oldFocusIndex, 1, [oldFocus]);
			this.ignoreFocusEvents = false;
		}

593
		this.updateListHeight();
J
Joao Moreno 已提交
594
		this.list.reveal(index);
J
Joao Moreno 已提交
595

596 597
		this.currentSuggestionDetails = item.resolve()
			.then(() => {
598 599 600 601
				this.ignoreFocusEvents = true;
				this.list.splice(index, 1, [item]);
				this.ignoreFocusEvents = false;

J
Joao Moreno 已提交
602
				this.list.setFocus([index]);
J
Joao Moreno 已提交
603
				this.list.reveal(index);
604

605
				if (this.expandDocsSettingFromStorage()) {
606
					this.showDetails();
607
				} else {
608
					removeClass(this.element, 'docs-side');
609
				}
J
Joao Moreno 已提交
610 611 612
			})
			.then(null, err => !isPromiseCanceledError(err) && onUnexpectedError(err))
			.then(() => this.currentSuggestionDetails = null);
613 614 615

		// emit an event
		this.onDidFocusEmitter.fire(item);
J
Joao Moreno 已提交
616
	}
J
Joao Moreno 已提交
617 618

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

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

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

J
Joao Moreno 已提交
628 629
		switch (state) {
			case State.Hidden:
J
Joao Moreno 已提交
630
				hide(this.messageElement, this.details.element);
J
Joao Moreno 已提交
631
				show(this.listElement);
J
Joao Moreno 已提交
632
				this.hide();
A
tslint  
Alex Dima 已提交
633
				if (stateChanged) {
634
					this.list.splice(0, this.list.length);
A
tslint  
Alex Dima 已提交
635
				}
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();
J
Joao Moreno 已提交
643 644
				break;
			case State.Empty:
J
Joao Moreno 已提交
645
				this.messageElement.textContent = SuggestWidget.NO_SUGGESTIONS_MESSAGE;
J
Joao Moreno 已提交
646
				hide(this.listElement, this.details.element);
J
Joao Moreno 已提交
647
				show(this.messageElement);
R
Ramya Achutha Rao 已提交
648
				removeClass(this.element, 'docs-side');
649
				this.show();
J
Joao Moreno 已提交
650 651
				break;
			case State.Open:
652
				hide(this.messageElement);
653
				show(this.listElement);
654
				if (this.expandDocsSettingFromStorage()
R
Ramya Achutha Rao 已提交
655
					&& canExpandCompletionItem(this.list.getFocusedElements()[0])) {
656
					show(this.details.element);
657
					this.expandSideOrBelow();
658 659
				} else {
					hide(this.details.element);
660
				}
661
				this.show();
J
Joao Moreno 已提交
662 663
				break;
			case State.Frozen:
J
Joao Moreno 已提交
664
				hide(this.messageElement, this.details.element);
J
Joao Moreno 已提交
665
				show(this.listElement);
666
				this.show();
J
Joao Moreno 已提交
667 668
				break;
			case State.Details:
669 670
				hide(this.messageElement);
				show(this.details.element, this.listElement);
671
				this.show();
672
				this._ariaAlert(this.details.getAriaLabel());
J
Joao Moreno 已提交
673 674 675
				break;
		}

676
		if (stateChanged) {
677 678
			this.editor.layoutContentWidget(this);
		}
679 680
	}

681
	showTriggered(auto: boolean) {
J
Joao Moreno 已提交
682 683 684
		if (this.state !== State.Hidden) {
			return;
		}
E
Erich Gamma 已提交
685

686
		this.isAuto = !!auto;
J
Joao Moreno 已提交
687 688 689 690 691 692 693

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

696
	showSuggestions(completionModel: CompletionModel, isFrozen: boolean, isAuto: boolean): void {
A
Alex Dima 已提交
697 698 699 700
		if (this.loadingTimeout) {
			clearTimeout(this.loadingTimeout);
			this.loadingTimeout = null;
		}
J
Joao Moreno 已提交
701

702
		this.completionModel = completionModel;
J
Joao Moreno 已提交
703

R
Ramya Achutha Rao 已提交
704
		if (isFrozen && this.state !== State.Empty && this.state !== State.Hidden) {
705 706
			this.setState(State.Frozen);
			return;
707 708
		}

709 710
		let visibleCount = this.completionModel.items.length;

J
Joao Moreno 已提交
711
		const isEmpty = visibleCount === 0;
712
		this.suggestWidgetMultipleSuggestions.set(visibleCount > 1);
J
Joao Moreno 已提交
713 714

		if (isEmpty) {
715
			if (isAuto) {
J
Joao Moreno 已提交
716 717
				this.setState(State.Hidden);
			} else {
Y
Yuki Ueda 已提交
718
				this.setState(State.Empty);
J
Joao Moreno 已提交
719 720
			}

J
Joao Moreno 已提交
721
			this.completionModel = null;
J
Joao Moreno 已提交
722

J
Joao Moreno 已提交
723
		} else {
J
Joao Moreno 已提交
724
			const { stats } = this.completionModel;
725
			stats['wasAutomaticallyTriggered'] = !!isAuto;
K
kieferrm 已提交
726
			/* __GDPR__
K
kieferrm 已提交
727 728 729 730 731 732 733 734
				"suggestWidget" : {
					"wasAutomaticallyTriggered" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
					"${include}": [
						"${ICompletionStats}",
						"${EditorTelemetryData}"
					]
				}
			*/
735
			this.telemetryService.publicLog('suggestWidget', { ...stats, ...this.editor.getTelemetryData() });
J
Joao Moreno 已提交
736

J
Joao Moreno 已提交
737 738
			this.focusedItem = null;
			this.focusedItemIndex = null;
J
Joao Moreno 已提交
739
			this.list.splice(0, this.list.length, this.completionModel.items);
740 741
			this.list.setFocus([0]);
			this.list.reveal(0, 0);
J
Joao Moreno 已提交
742

R
Ramya Achutha Rao 已提交
743 744 745 746 747
			if (isFrozen) {
				this.setState(State.Frozen);
			} else {
				this.setState(State.Open);
			}
R
Ramya Achutha Rao 已提交
748 749 750 751 752

			// Reset focus border
			if (this.detailsBorderColor) {
				this.details.element.style.borderColor = this.detailsBorderColor;
			}
J
Joao Moreno 已提交
753
		}
754
	}
E
Erich Gamma 已提交
755

J
Joao Moreno 已提交
756
	selectNextPage(): boolean {
J
Joao Moreno 已提交
757 758 759 760 761 762 763 764 765 766 767 768
		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 已提交
769 770
	}

J
Joao Moreno 已提交
771
	selectNext(): boolean {
J
Joao Moreno 已提交
772 773 774 775 776 777 778 779 780
		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 已提交
781 782
	}

783 784 785 786 787
	selectLast(): boolean {
		switch (this.state) {
			case State.Hidden:
				return false;
			case State.Details:
788
				this.details.scrollBottom();
789 790 791 792 793 794 795 796 797
				return true;
			case State.Loading:
				return !this.isAuto;
			default:
				this.list.focusLast();
				return true;
		}
	}

J
Joao Moreno 已提交
798
	selectPreviousPage(): boolean {
J
Joao Moreno 已提交
799 800 801 802 803 804 805 806 807 808 809 810
		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 已提交
811 812
	}

J
Joao Moreno 已提交
813
	selectPrevious(): boolean {
J
Joao Moreno 已提交
814 815 816 817 818 819 820
		switch (this.state) {
			case State.Hidden:
				return false;
			case State.Loading:
				return !this.isAuto;
			default:
				this.list.focusPrevious(1, true);
J
Joao Moreno 已提交
821
				return false;
J
Joao Moreno 已提交
822
		}
E
Erich Gamma 已提交
823 824
	}

825 826 827 828 829
	selectFirst(): boolean {
		switch (this.state) {
			case State.Hidden:
				return false;
			case State.Details:
830
				this.details.scrollTop();
831 832 833 834 835 836 837 838 839
				return true;
			case State.Loading:
				return !this.isAuto;
			default:
				this.list.focusFirst();
				return true;
		}
	}

840
	getFocusedItem(): ICompletionItem {
841 842 843 844 845
		if (this.state !== State.Hidden
			&& this.state !== State.Empty
			&& this.state !== State.Loading) {

			return this.list.getFocusedElements()[0];
J
Joao Moreno 已提交
846
		}
847
		return undefined;
E
Erich Gamma 已提交
848 849
	}

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

872
	toggleDetails(): void {
R
Ramya Achutha Rao 已提交
873 874 875
		if (!canExpandCompletionItem(this.list.getFocusedElements()[0])) {
			return;
		}
876

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

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

908 909
	}

910
	showDetails(): void {
R
Ramya Achutha Rao 已提交
911
		this.expandSideOrBelow();
912 913

		show(this.details.element);
914
		this.details.render(this.list.getFocusedElements()[0]);
915
		this.details.element.style.maxHeight = this.maxWidgetHeight + 'px';
916

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

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

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

J
Joao Moreno 已提交
925
		this.editor.focus();
R
Ramya Achutha Rao 已提交
926 927

		this._ariaAlert(this.details.getAriaLabel());
J
Joao Moreno 已提交
928 929
	}

930
	private show(): void {
931
		this.updateListHeight();
J
Joao Moreno 已提交
932
		this.suggestWidgetVisible.set(true);
933

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

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

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

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

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

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

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

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

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

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

E
Erich Gamma 已提交
985 986
		this.editor.layoutContentWidget(this);

J
Joao Moreno 已提交
987
		return height;
J
Joao Moreno 已提交
988 989
	}

990
	private adjustDocsPosition() {
R
Ramya Achutha Rao 已提交
991
		const lineHeight = this.editor.getConfiguration().fontInfo.lineHeight;
992 993 994 995
		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;
996 997 998
		const widgetCoords = getDomNodePagePosition(this.element);
		const widgetX = widgetCoords.left;
		const widgetY = widgetCoords.top;
999

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

R
Ramya Achutha Rao 已提交
1007 1008 1009
		// 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 已提交
1010
		if (hasClass(this.element, 'docs-side')
R
Ramya Achutha Rao 已提交
1011
			&& cursorY - lineHeight > widgetY
R
Ramya Achutha Rao 已提交
1012 1013 1014 1015 1016
			&& 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`;
1017
		}
1018 1019
	}

1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
	private expandSideOrBelow() {
		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');
		} else {
			addClass(this.element, 'docs-side');
			removeClass(this.element, 'docs-below');
		}
	}

1031 1032
	// Heights

1033 1034
	private get maxWidgetHeight(): number {
		return this.unfocusedHeight * maxSuggestionsToShow;
1035 1036 1037
	}

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

	// IDelegate

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

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

1052 1053 1054
	// Monaco Editor does not have a storage service
	private expandDocsSettingFromStorage(): boolean {
		if (this.storageServiceAvailable) {
1055
			return this.storageService.getBoolean('expandSuggestionDocs', StorageScope.GLOBAL);
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
		} 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 已提交
1070
	dispose(): void {
J
Joao Moreno 已提交
1071 1072 1073
		this.state = null;
		this.suggestionSupportsAutoAccept = null;
		this.currentSuggestionDetails = null;
J
Joao Moreno 已提交
1074
		this.focusedItem = null;
J
Joao Moreno 已提交
1075 1076
		this.element = null;
		this.messageElement = null;
J
Joao Moreno 已提交
1077
		this.listElement = null;
J
Joao Moreno 已提交
1078 1079
		this.details.dispose();
		this.details = null;
J
Joao Moreno 已提交
1080 1081
		this.list.dispose();
		this.list = null;
J
Joao Moreno 已提交
1082
		this.toDispose = dispose(this.toDispose);
A
Alex Dima 已提交
1083 1084 1085 1086
		if (this.loadingTimeout) {
			clearTimeout(this.loadingTimeout);
			this.loadingTimeout = null;
		}
J
Joao Moreno 已提交
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096

		if (this.editorBlurTimeout) {
			this.editorBlurTimeout.cancel();
			this.editorBlurTimeout = null;
		}

		if (this.showTimeout) {
			this.showTimeout.cancel();
			this.showTimeout = null;
		}
E
Erich Gamma 已提交
1097
	}
J
Johannes Rieken 已提交
1098
}
1099 1100

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

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

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