suggestWidget.ts 34.3 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 { IVirtualDelegate, 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 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;
113
			const fontWeight = configuration.fontInfo.fontWeight;
J
Johannes Rieken 已提交
114 115
			const fontSizePx = `${fontSize}px`;
			const lineHeightPx = `${lineHeight}px`;
J
Joao Moreno 已提交
116 117

			data.root.style.fontSize = fontSizePx;
118
			data.root.style.fontWeight = fontWeight;
J
Joao Moreno 已提交
119 120 121 122
			main.style.fontFamily = fontFamily;
			main.style.lineHeight = lineHeightPx;
			data.icon.style.height = lineHeightPx;
			data.icon.style.width = lineHeightPx;
123 124
			data.readMore.style.height = lineHeightPx;
			data.readMore.style.width = lineHeightPx;
125 126 127 128
		};

		configureFont();

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

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

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

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

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

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

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

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

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

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

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

class SuggestionDetails {

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

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

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

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

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

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

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

		this.configureFont();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

346 347
	dispose(): void {
		this.disposables = dispose(this.disposables);
348
		this.renderDisposeable = dispose(this.renderDisposeable);
J
Joao Moreno 已提交
349
	}
J
Joao Moreno 已提交
350 351
}

352 353 354 355 356 357
export interface ISelectedSuggestion {
	item: ICompletionItem;
	index: number;
	model: CompletionModel;
}

J
Joao Moreno 已提交
358
export class SuggestWidget implements IContentWidget, IVirtualDelegate<ICompletionItem>, IDisposable {
J
Joao Moreno 已提交
359

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

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

J
Joao Moreno 已提交
365
	// Editor.IContentWidget.allowEditorOverflow
366
	readonly allowEditorOverflow = true;
J
Joao Moreno 已提交
367

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

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

A
Alex Dima 已提交
383 384 385
	private suggestWidgetVisible: IContextKey<boolean>;
	private suggestWidgetMultipleSuggestions: IContextKey<boolean>;
	private suggestionSupportsAutoAccept: IContextKey<boolean>;
J
Joao Moreno 已提交
386

387 388
	private readonly editorBlurTimeout = new TimeoutTimer();
	private readonly showTimeout = new TimeoutTimer();
J
Joao Moreno 已提交
389
	private toDispose: IDisposable[];
J
Joao Moreno 已提交
390

391 392
	private onDidSelectEmitter = new Emitter<ISelectedSuggestion>();
	private onDidFocusEmitter = new Emitter<ISelectedSuggestion>();
393 394 395
	private onDidHideEmitter = new Emitter<this>();
	private onDidShowEmitter = new Emitter<this>();

396

397 398
	readonly onDidSelect: Event<ISelectedSuggestion> = this.onDidSelectEmitter.event;
	readonly onDidFocus: Event<ISelectedSuggestion> = this.onDidFocusEmitter.event;
399 400
	readonly onDidHide: Event<this> = this.onDidHideEmitter.event;
	readonly onDidShow: Event<this> = this.onDidShowEmitter.event;
401

402
	private readonly maxWidgetWidth = 660;
403
	private readonly listWidth = 330;
404
	private storageService: IStorageService;
405 406
	private detailsFocusBorderColor: string;
	private detailsBorderColor: string;
407

408 409 410
	private storageServiceAvailable: boolean = true;
	private expandSuggestionDocs: boolean = false;

411 412
	private firstFocusInCurrentList: boolean = false;

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

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

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

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

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

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

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

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

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

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

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

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

J
Joao Moreno 已提交
483 484
		this.editor.layoutContentWidget(this);
	}
J
Joao Moreno 已提交
485

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

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

J
Joao Moreno 已提交
497
		const item = e.elements[0];
498
		const index = e.indexes[0];
499
		item.resolve(CancellationToken.None).then(() => {
500
			this.onDidSelectEmitter.fire({ item, index, model: this.completionModel });
J
Johannes Rieken 已提交
501 502
			alert(nls.localize('suggestionAriaAccepted', "{0}, accepted", item.suggestion.label));
			this.editor.focus();
503
		});
J
Joao Moreno 已提交
504
	}
E
Erich Gamma 已提交
505

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

	private _lastAriaAlertLabel: string;
J
Johannes Rieken 已提交
515
	private _ariaAlert(newAriaAlertLabel: string): void {
516 517 518 519 520 521 522 523 524
		if (this._lastAriaAlertLabel === newAriaAlertLabel) {
			return;
		}
		this._lastAriaAlertLabel = newAriaAlertLabel;
		if (this._lastAriaAlertLabel) {
			alert(this._lastAriaAlertLabel);
		}
	}

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

J
Joao Moreno 已提交
546
	private onListFocus(e: IListEvent<ICompletionItem>): void {
547 548 549 550
		if (this.ignoreFocusEvents) {
			return;
		}

J
Joao Moreno 已提交
551
		if (!e.elements.length) {
J
Joao Moreno 已提交
552 553 554 555 556
			if (this.currentSuggestionDetails) {
				this.currentSuggestionDetails.cancel();
				this.currentSuggestionDetails = null;
				this.focusedItem = null;
			}
557

J
Joao Moreno 已提交
558
			this._ariaAlert(null);
J
Joao Moreno 已提交
559 560
			return;
		}
E
Erich Gamma 已提交
561

J
Joao Moreno 已提交
562
		const item = e.elements[0];
563
		this._ariaAlert(this._getSuggestionAriaAlertLabel(item));
564

565
		this.firstFocusInCurrentList = !this.focusedItem;
J
Joao Moreno 已提交
566 567 568
		if (item === this.focusedItem) {
			return;
		}
E
Erich Gamma 已提交
569

J
Joao Moreno 已提交
570 571 572 573 574
		if (this.currentSuggestionDetails) {
			this.currentSuggestionDetails.cancel();
			this.currentSuggestionDetails = null;
		}

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

577
		this.suggestionSupportsAutoAccept.set(!item.suggestion.noAutoAccept);
578

J
Joao Moreno 已提交
579
		this.focusedItem = item;
580

J
Joao Moreno 已提交
581
		this.list.reveal(index);
J
Joao Moreno 已提交
582

583 584 585 586 587 588 589 590 591 592 593 594 595 596
		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 已提交
597 598 599 600 601
		}).catch(onUnexpectedError).then(() => {
			if (this.focusedItem === item) {
				this.currentSuggestionDetails = null;
			}
		});
602 603

		// emit an event
604
		this.onDidFocusEmitter.fire({ item, index, model: this.completionModel });
J
Joao Moreno 已提交
605
	}
J
Joao Moreno 已提交
606 607

	private setState(state: State): void {
J
Joao Moreno 已提交
608 609 610 611
		if (!this.element) {
			return;
		}

612
		const stateChanged = this.state !== state;
J
Joao Moreno 已提交
613 614
		this.state = state;

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

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

662
	showTriggered(auto: boolean) {
J
Joao Moreno 已提交
663 664 665
		if (this.state !== State.Hidden) {
			return;
		}
E
Erich Gamma 已提交
666

667
		this.isAuto = !!auto;
J
Joao Moreno 已提交
668 669 670 671 672 673 674

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

677
	showSuggestions(completionModel: CompletionModel, selectionIndex: number, isFrozen: boolean, isAuto: boolean): void {
A
Alex Dima 已提交
678 679 680 681
		if (this.loadingTimeout) {
			clearTimeout(this.loadingTimeout);
			this.loadingTimeout = null;
		}
J
Joao Moreno 已提交
682

683 684 685
		if (this.completionModel !== completionModel) {
			this.completionModel = completionModel;
		}
J
Joao Moreno 已提交
686

R
Ramya Achutha Rao 已提交
687
		if (isFrozen && this.state !== State.Empty && this.state !== State.Hidden) {
688 689
			this.setState(State.Frozen);
			return;
690 691
		}

692 693
		let visibleCount = this.completionModel.items.length;

J
Joao Moreno 已提交
694
		const isEmpty = visibleCount === 0;
695
		this.suggestWidgetMultipleSuggestions.set(visibleCount > 1);
J
Joao Moreno 已提交
696 697

		if (isEmpty) {
698
			if (isAuto) {
J
Joao Moreno 已提交
699 700
				this.setState(State.Hidden);
			} else {
Y
Yuki Ueda 已提交
701
				this.setState(State.Empty);
J
Joao Moreno 已提交
702 703
			}

J
Joao Moreno 已提交
704
			this.completionModel = null;
J
Joao Moreno 已提交
705

J
Joao Moreno 已提交
706
		} else {
J
Joao Moreno 已提交
707
			const { stats } = this.completionModel;
708
			stats['wasAutomaticallyTriggered'] = !!isAuto;
K
kieferrm 已提交
709
			/* __GDPR__
K
kieferrm 已提交
710
				"suggestWidget" : {
K
kieferrm 已提交
711
					"wasAutomaticallyTriggered" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
K
kieferrm 已提交
712 713 714 715 716 717
					"${include}": [
						"${ICompletionStats}",
						"${EditorTelemetryData}"
					]
				}
			*/
718
			this.telemetryService.publicLog('suggestWidget', { ...stats, ...this.editor.getTelemetryData() });
J
Joao Moreno 已提交
719

720 721
			this.list.splice(0, this.list.length, this.completionModel.items);

R
Ramya Achutha Rao 已提交
722 723 724 725 726
			if (isFrozen) {
				this.setState(State.Frozen);
			} else {
				this.setState(State.Open);
			}
R
Ramya Achutha Rao 已提交
727

J
Joao Moreno 已提交
728
			this.list.reveal(selectionIndex, selectionIndex);
J
Joao Moreno 已提交
729 730
			this.list.setFocus([selectionIndex]);

R
Ramya Achutha Rao 已提交
731 732 733 734
			// Reset focus border
			if (this.detailsBorderColor) {
				this.details.element.style.borderColor = this.detailsBorderColor;
			}
J
Joao Moreno 已提交
735
		}
736
	}
E
Erich Gamma 已提交
737

J
Joao Moreno 已提交
738
	selectNextPage(): boolean {
J
Joao Moreno 已提交
739 740 741 742 743 744 745 746 747 748 749 750
		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 已提交
751 752
	}

J
Joao Moreno 已提交
753
	selectNext(): boolean {
J
Joao Moreno 已提交
754 755 756 757 758 759 760 761 762
		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 已提交
763 764
	}

765 766 767 768 769
	selectLast(): boolean {
		switch (this.state) {
			case State.Hidden:
				return false;
			case State.Details:
770
				this.details.scrollBottom();
771 772 773 774 775 776 777 778 779
				return true;
			case State.Loading:
				return !this.isAuto;
			default:
				this.list.focusLast();
				return true;
		}
	}

J
Joao Moreno 已提交
780
	selectPreviousPage(): boolean {
J
Joao Moreno 已提交
781 782 783 784 785 786 787 788 789 790 791 792
		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 已提交
793 794
	}

J
Joao Moreno 已提交
795
	selectPrevious(): boolean {
J
Joao Moreno 已提交
796 797 798 799 800 801 802
		switch (this.state) {
			case State.Hidden:
				return false;
			case State.Loading:
				return !this.isAuto;
			default:
				this.list.focusPrevious(1, true);
J
Joao Moreno 已提交
803
				return false;
J
Joao Moreno 已提交
804
		}
E
Erich Gamma 已提交
805 806
	}

807 808 809 810 811
	selectFirst(): boolean {
		switch (this.state) {
			case State.Hidden:
				return false;
			case State.Details:
812
				this.details.scrollTop();
813 814 815 816 817 818 819 820 821
				return true;
			case State.Loading:
				return !this.isAuto;
			default:
				this.list.focusFirst();
				return true;
		}
	}

822
	getFocusedItem(): ISelectedSuggestion {
823 824 825 826
		if (this.state !== State.Hidden
			&& this.state !== State.Empty
			&& this.state !== State.Loading) {

827 828 829 830 831
			return {
				item: this.list.getFocusedElements()[0],
				index: this.list.getFocus()[0],
				model: this.completionModel
			};
J
Joao Moreno 已提交
832
		}
833
		return undefined;
E
Erich Gamma 已提交
834 835
	}

836
	toggleDetailsFocus(): void {
J
Joao Moreno 已提交
837 838
		if (this.state === State.Details) {
			this.setState(State.Open);
839 840 841
			if (this.detailsBorderColor) {
				this.details.element.style.borderColor = this.detailsBorderColor;
			}
842
		} else if (this.state === State.Open && this.expandDocsSettingFromStorage()) {
843
			this.setState(State.Details);
844 845 846
			if (this.detailsFocusBorderColor) {
				this.details.element.style.borderColor = this.detailsFocusBorderColor;
			}
J
Joao Moreno 已提交
847
		}
K
kieferrm 已提交
848
		/* __GDPR__
K
kieferrm 已提交
849 850 851 852 853 854
			"suggestWidget:toggleDetailsFocus" : {
				"${include}": [
					"${EditorTelemetryData}"
				]
			}
		*/
855
		this.telemetryService.publicLog('suggestWidget:toggleDetailsFocus', this.editor.getTelemetryData());
856
	}
J
Joao Moreno 已提交
857

858
	toggleDetails(): void {
R
Ramya Achutha Rao 已提交
859 860 861
		if (!canExpandCompletionItem(this.list.getFocusedElements()[0])) {
			return;
		}
862

863 864
		if (this.expandDocsSettingFromStorage()) {
			this.updateExpandDocsSetting(false);
865
			hide(this.details.element);
866
			removeClass(this.element, 'docs-side');
867
			removeClass(this.element, 'docs-below');
868
			this.editor.layoutContentWidget(this);
K
kieferrm 已提交
869
			/* __GDPR__
K
kieferrm 已提交
870 871 872 873 874 875
				"suggestWidget:collapseDetails" : {
					"${include}": [
						"${EditorTelemetryData}"
					]
				}
			*/
876
			this.telemetryService.publicLog('suggestWidget:collapseDetails', this.editor.getTelemetryData());
877
		} else {
878
			if (this.state !== State.Open && this.state !== State.Details && this.state !== State.Frozen) {
879 880 881
				return;
			}

882
			this.updateExpandDocsSetting(true);
883
			this.showDetails();
K
kieferrm 已提交
884
			/* __GDPR__
K
kieferrm 已提交
885 886 887 888 889 890
				"suggestWidget:expandDetails" : {
					"${include}": [
						"${EditorTelemetryData}"
					]
				}
			*/
891
			this.telemetryService.publicLog('suggestWidget:expandDetails', this.editor.getTelemetryData());
892
		}
893

894 895
	}

896
	showDetails(): void {
R
Ramya Achutha Rao 已提交
897
		this.expandSideOrBelow();
898 899

		show(this.details.element);
900
		this.details.render(this.list.getFocusedElements()[0]);
901
		this.details.element.style.maxHeight = this.maxWidgetHeight + 'px';
902

R
Ramya Achutha Rao 已提交
903 904
		// Reset margin-top that was set as Fix for #26416
		this.listElement.style.marginTop = '0px';
905 906 907 908 909

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

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

J
Joao Moreno 已提交
911
		this.editor.focus();
R
Ramya Achutha Rao 已提交
912 913

		this._ariaAlert(this.details.getAriaLabel());
J
Joao Moreno 已提交
914 915
	}

916
	private show(): void {
917 918 919 920 921 922
		const newHeight = this.updateListHeight();
		if (newHeight !== this.listHeight) {
			this.editor.layoutContentWidget(this);
			this.listHeight = newHeight;
		}

J
Joao Moreno 已提交
923
		this.suggestWidgetVisible.set(true);
924

925
		this.showTimeout.cancelAndSet(() => {
J
Joao Moreno 已提交
926
			addClass(this.element, 'visible');
927
			this.onDidShowEmitter.fire(this);
928
		}, 100);
E
Erich Gamma 已提交
929 930
	}

931
	private hide(): void {
J
Joao Moreno 已提交
932
		this.suggestWidgetVisible.reset();
S
Sean Kelly 已提交
933
		this.suggestWidgetMultipleSuggestions.reset();
J
Joao Moreno 已提交
934
		removeClass(this.element, 'visible');
E
Erich Gamma 已提交
935 936
	}

937 938 939
	hideWidget(): void {
		clearTimeout(this.loadingTimeout);
		this.setState(State.Hidden);
940
		this.onDidHideEmitter.fire(this);
941 942
	}

J
Joao Moreno 已提交
943
	getPosition(): IContentWidgetPosition {
J
Joao Moreno 已提交
944 945
		if (this.state === State.Hidden) {
			return null;
E
Erich Gamma 已提交
946
		}
J
Joao Moreno 已提交
947 948

		return {
949
			position: this.editor.getPosition(),
A
Alex Dima 已提交
950
			preference: [ContentWidgetPositionPreference.BELOW, ContentWidgetPositionPreference.ABOVE]
J
Joao Moreno 已提交
951
		};
E
Erich Gamma 已提交
952 953
	}

J
Joao Moreno 已提交
954
	getDomNode(): HTMLElement {
E
Erich Gamma 已提交
955 956 957
		return this.element;
	}

J
Joao Moreno 已提交
958
	getId(): string {
E
Erich Gamma 已提交
959 960 961
		return SuggestWidget.ID;
	}

962
	private updateListHeight(): number {
J
Joao Moreno 已提交
963
		let height = 0;
E
Erich Gamma 已提交
964

J
Joao Moreno 已提交
965
		if (this.state === State.Empty || this.state === State.Loading) {
966
			height = this.unfocusedHeight;
J
Joao Moreno 已提交
967
		} else {
968 969
			const suggestionCount = this.list.contentHeight / this.unfocusedHeight;
			height = Math.min(suggestionCount, maxSuggestionsToShow) * this.unfocusedHeight;
J
Joao Moreno 已提交
970
		}
J
Joao Moreno 已提交
971

972
		this.element.style.lineHeight = `${this.unfocusedHeight}px`;
973
		this.listElement.style.height = `${height}px`;
J
Joao Moreno 已提交
974
		this.list.layout(height);
975
		return height;
J
Joao Moreno 已提交
976 977
	}

978
	private adjustDocsPosition() {
R
Ramya Achutha Rao 已提交
979
		const lineHeight = this.editor.getConfiguration().fontInfo.lineHeight;
980 981 982 983
		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;
984 985 986
		const widgetCoords = getDomNodePagePosition(this.element);
		const widgetX = widgetCoords.left;
		const widgetY = widgetCoords.top;
987

988 989 990
		if (widgetX < cursorX - this.listWidth) {
			// Widget is too far to the left of cursor, swap list and docs
			addClass(this.element, 'list-right');
991 992
		} else {
			removeClass(this.element, 'list-right');
993 994
		}

R
Ramya Achutha Rao 已提交
995 996 997
		// 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 已提交
998
		if (hasClass(this.element, 'docs-side')
R
Ramya Achutha Rao 已提交
999
			&& cursorY - lineHeight > widgetY
R
Ramya Achutha Rao 已提交
1000 1001 1002 1003 1004
			&& 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`;
1005
		}
1006 1007
	}

1008
	private expandSideOrBelow() {
1009 1010 1011 1012 1013 1014
		if (!canExpandCompletionItem(this.focusedItem) && this.firstFocusInCurrentList) {
			removeClass(this.element, 'docs-side');
			removeClass(this.element, 'docs-below');
			return;
		}

1015 1016 1017 1018
		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');
1019
		} else if (canExpandCompletionItem(this.focusedItem)) {
1020 1021 1022 1023 1024
			addClass(this.element, 'docs-side');
			removeClass(this.element, 'docs-below');
		}
	}

1025 1026
	// Heights

1027 1028
	private get maxWidgetHeight(): number {
		return this.unfocusedHeight * maxSuggestionsToShow;
1029 1030 1031
	}

	private get unfocusedHeight(): number {
J
Joao Moreno 已提交
1032 1033
		const configuration = this.editor.getConfiguration();
		return configuration.contribInfo.suggestLineHeight || configuration.fontInfo.lineHeight;
1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045
	}

	// IDelegate

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

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

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

1082 1083
		this.editorBlurTimeout.dispose();
		this.showTimeout.dispose();
E
Erich Gamma 已提交
1084
	}
J
Johannes Rieken 已提交
1085
}
1086 1087

registerThemingParticipant((theme, collector) => {
1088
	let matchHighlight = theme.getColor(editorSuggestWidgetHighlightForeground);
1089
	if (matchHighlight) {
J
Johannes Rieken 已提交
1090
		collector.addRule(`.monaco-editor .suggest-widget .monaco-list .monaco-list-row .monaco-highlighted-label .highlight { color: ${matchHighlight}; }`);
1091
	}
1092 1093
	let foreground = theme.getColor(editorSuggestWidgetForeground);
	if (foreground) {
1094
		collector.addRule(`.monaco-editor .suggest-widget { color: ${foreground}; }`);
1095
	}
M
Matt Bierner 已提交
1096 1097 1098 1099 1100

	const link = theme.getColor(textLinkForeground);
	if (link) {
		collector.addRule(`.monaco-editor .suggest-widget a { color: ${link}; }`);
	}
1101 1102 1103 1104 1105

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