Skip to content

Commit

Permalink
tweak UI for deprecated completions, update API proposal #23927
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Aug 22, 2019
1 parent ee2b890 commit 1848b16
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 17 deletions.
9 changes: 9 additions & 0 deletions src/vs/base/common/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ import { URI } from 'vs/base/common/uri';
import { CharCode } from 'vs/base/common/charCode';
import { Iterator, IteratorResult, FIN } from './iterator';


export function fromArray<T>(array: readonly T[]): Set<T> {
const result = new Set<T>();
for (const element of array) {
result.add(element);
}
return result;
}

export function values<V = any>(set: Set<V>): V[];
export function values<K = any, V = any>(map: Map<K, V>): V[];
export function values<V>(forEachable: { forEach(callback: (value: V, ...more: any[]) => any): void }): V[] {
Expand Down
19 changes: 11 additions & 8 deletions src/vs/editor/contrib/suggest/media/suggest.css
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@
font-weight: bold;
}

.monaco-editor .suggest-widget-deprecated span {
text-decoration: line-through;
}

/** Icon styles **/

.monaco-editor .suggest-widget .details > .monaco-scrollable-element > .body > .header > .close,
Expand All @@ -115,8 +111,8 @@
.monaco-editor .suggest-widget .details > .monaco-scrollable-element > .body > .header > .close {
background-image: url('./close-light.svg');
position: absolute;
top: 0px;
right: 0px;
top: 0;
right: 0;
margin-right: 5px;
}

Expand Down Expand Up @@ -159,9 +155,16 @@
}

/** Styles for each row in the list **/

.monaco-editor .suggest-widget .monaco-list .monaco-list-row .monaco-icon-label.deprecated {
opacity: 0.66;
}
.monaco-editor .suggest-widget .monaco-list .monaco-list-row .monaco-icon-label.deprecated > .monaco-icon-label-description-container {
text-decoration: line-through;
}

.monaco-editor .suggest-widget .monaco-list .monaco-list-row .monaco-icon-label::before {
height: 100%;

}

.monaco-editor .suggest-widget .monaco-list .monaco-list-row .icon {
Expand Down Expand Up @@ -257,7 +260,7 @@
text-overflow: ellipsis;
opacity: 0.7;
word-break: break-all;
margin: 0px 24px 0 0;
margin: 0 24px 0 0;
padding: 4px 0 12px 5px;
}

Expand Down
5 changes: 3 additions & 2 deletions src/vs/editor/contrib/suggest/suggestController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import { IdleValue } from 'vs/base/common/async';
import { isObject } from 'vs/base/common/types';
import { CommitCharacterController } from './suggestCommitCharacters';

const _sticky = false; // for development purposes only

export class SuggestController implements IEditorContribution {

private static readonly ID: string = 'editor.contrib.suggestController';
Expand All @@ -47,7 +49,6 @@ export class SuggestController implements IEditorContribution {
private readonly _alternatives: IdleValue<SuggestAlternatives>;
private readonly _toDispose = new DisposableStore();

private readonly _sticky = false; // for development purposes only

constructor(
private _editor: ICodeEditor,
Expand Down Expand Up @@ -127,7 +128,7 @@ export class SuggestController implements IEditorContribution {
}
}));
this._toDispose.add(this._editor.onDidBlurEditorWidget(() => {
if (!this._sticky) {
if (!_sticky) {
this._model.cancel();
this._model.clear();
}
Expand Down
3 changes: 2 additions & 1 deletion src/vs/editor/contrib/suggest/suggestWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ class Renderer implements IListRenderer<CompletionItem, ISuggestionTemplateData>
}

if (suggestion.kindModifier && suggestion.kindModifier.has(CompletionItemKindModifier.Deprecated)) {
labelOptions.extraClasses = (labelOptions.extraClasses || []).concat(['suggest-widget-deprecated']);
labelOptions.extraClasses = (labelOptions.extraClasses || []).concat(['deprecated']);
labelOptions.matches = [];
}

data.iconLabel.setLabel(suggestion.label, undefined, labelOptions);
Expand Down
11 changes: 8 additions & 3 deletions src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1142,13 +1142,18 @@ declare module 'vscode' {

//#endregion

//#region Deprecated support
//#region Joh - CompletionItemKindModifier, https://github.com/microsoft/vscode/issues/23927

export enum CompletionItemKindModifier {
Deprecated = 1
}

export interface CompletionItem {

/**
* Indicates if this item is deprecated.
*
*/
deprecated?: boolean;
kind2?: CompletionItemKind | { base: CompletionItemKind, modifier: ReadonlyArray<CompletionItemKindModifier> };
}

//#endregion
Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { Selection } from 'vs/editor/common/core/selection';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import * as callh from 'vs/workbench/contrib/callHierarchy/common/callHierarchy';
import { mixin } from 'vs/base/common/objects';
import { fromArray } from 'vs/base/common/map';

@extHostNamedCustomer(MainContext.MainThreadLanguageFeatures)
export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesShape {
Expand Down Expand Up @@ -330,7 +331,7 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha
return {
label: data.a,
kind: data.b,
kindModifier: data.n ? new Set<modes.CompletionItemKindModifier>().add(modes.CompletionItemKindModifier.Deprecated) : undefined,
kindModifier: data.n && fromArray(data.n),
detail: data.c,
documentation: data.d,
sortText: data.e,
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
CommentMode: extHostTypes.CommentMode,
CompletionItem: extHostTypes.CompletionItem,
CompletionItemKind: extHostTypes.CompletionItemKind,
CompletionItemKindModifier: extHostTypes.CompletionItemKindModifier,
CompletionList: extHostTypes.CompletionList,
CompletionTriggerKind: extHostTypes.CompletionTriggerKind,
ConfigurationTarget: extHostTypes.ConfigurationTarget,
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ export interface ISuggestDataDto {
k/* commitCharacters */?: string[];
l/* additionalTextEdits */?: ISingleEditOperation[];
m/* command */?: modes.Command;
n/* deprecated */?: boolean;
n/* kindModifier */?: modes.CompletionItemKindModifier[];
// not-standard
x?: ChainedCacheId;
}
Expand Down
7 changes: 6 additions & 1 deletion src/vs/workbench/api/common/extHostLanguageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,9 +736,14 @@ class SuggestAdapter {
k: item.commitCharacters,
l: item.additionalTextEdits && item.additionalTextEdits.map(typeConvert.TextEdit.from),
m: this._commands.toInternal(item.command, disposables),
n: item.deprecated
};

// kind2
if (typeof item.kind2 === 'object') {
result.b = typeConvert.CompletionItemKind.from(item.kind2.base);
result.n = item.kind2.modifier.map(typeConvert.CompletionItemKindModifier.from);
}

// 'insertText'-logic
if (item.textEdit) {
result.h = item.textEdit.newText;
Expand Down
15 changes: 15 additions & 0 deletions src/vs/workbench/api/common/extHostTypeConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,21 @@ export namespace CompletionContext {
}
}

export namespace CompletionItemKindModifier {

export function from(kind: types.CompletionItemKindModifier): modes.CompletionItemKindModifier {
switch (kind) {
case types.CompletionItemKindModifier.Deprecated: return modes.CompletionItemKindModifier.Deprecated;
}
}

export function to(kind: modes.CompletionItemKindModifier): types.CompletionItemKindModifier {
switch (kind) {
case modes.CompletionItemKindModifier.Deprecated: return types.CompletionItemKindModifier.Deprecated;
}
}
}

export namespace CompletionItemKind {

export function from(kind: types.CompletionItemKind | undefined): modes.CompletionItemKind {
Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/api/common/extHostTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1308,11 +1308,16 @@ export enum CompletionItemKind {
TypeParameter = 24
}

export enum CompletionItemKindModifier {
Deprecated = 1,
}

@es5ClassCompat
export class CompletionItem implements vscode.CompletionItem {

label: string;
kind?: CompletionItemKind;
kind2?: CompletionItemKind | { base: CompletionItemKind, modifier: CompletionItemKindModifier[] };
detail?: string;
documentation?: string | MarkdownString;
sortText?: string;
Expand Down

0 comments on commit 1848b16

Please sign in to comment.