function asCompletionItem()

in client/src/common/codeConverter.ts [579:640]


	function asCompletionItem(item: code.CompletionItem, labelDetailsSupport: boolean = false): proto.CompletionItem {
		let label: string;
		let labelDetails: proto.CompletionItemLabelDetails | undefined;
		if (Is.string(item.label)) {
			label = item.label;
		} else {
			label = item.label.label;
			if (labelDetailsSupport && (item.label.detail !== undefined || item.label.description !== undefined)) {
				labelDetails = { detail: item.label.detail, description: item.label.description };
			}
		}
		let result: proto.CompletionItem = { label: label };
		if (labelDetails !== undefined) {
			result.labelDetails = labelDetails;
		}
		let protocolItem = item instanceof ProtocolCompletionItem ? item as ProtocolCompletionItem : undefined;
		if (item.detail) { result.detail = item.detail; }
		// We only send items back we created. So this can't be something else than
		// a string right now.
		if (item.documentation) {
			if (!protocolItem || protocolItem.documentationFormat === '$string') {
				result.documentation = item.documentation as string;
			} else {
				result.documentation = asDocumentation(protocolItem.documentationFormat!, item.documentation);
			}
		}
		if (item.filterText) { result.filterText = item.filterText; }
		fillPrimaryInsertText(result, item as ProtocolCompletionItem);
		if (Is.number(item.kind)) {
			result.kind = asCompletionItemKind(item.kind, protocolItem && protocolItem.originalItemKind);
		}
		if (item.sortText) { result.sortText = item.sortText; }
		if (item.additionalTextEdits) { result.additionalTextEdits = asTextEdits(item.additionalTextEdits); }
		if (item.commitCharacters) { result.commitCharacters = item.commitCharacters.slice(); }
		if (item.command) { result.command = asCommand(item.command); }
		if (item.preselect === true || item.preselect === false) { result.preselect = item.preselect; }
		const tags = asCompletionItemTags(item.tags);
		if (protocolItem) {
			if (protocolItem.data !== undefined) {
				result.data = protocolItem.data;
			}
			if (protocolItem.deprecated === true || protocolItem.deprecated === false) {
				if (protocolItem.deprecated === true && tags !== undefined && tags.length > 0) {
					const index = tags.indexOf(code.CompletionItemTag.Deprecated);
					if (index !== -1) {
						tags.splice(index, 1);
					}
				}
				result.deprecated = protocolItem.deprecated;
			}
			if (protocolItem.insertTextMode !== undefined) {
				result.insertTextMode = protocolItem.insertTextMode;
			}
		}
		if (tags !== undefined && tags.length > 0) {
			result.tags = tags;
		}
		if (result.insertTextMode === undefined && item.keepWhitespace === true) {
			result.insertTextMode = InsertTextMode.adjustIndentation;
		}
		return result;
	}