Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline Hints controller and API proposal #113285

Merged
merged 40 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
8476ff1
WIP
Kingwl Dec 22, 2020
741a568
Avoid generated files
Kingwl Dec 22, 2020
52c1cce
Add controller
Kingwl Dec 22, 2020
434f631
Revert "Avoid generated files"
Kingwl Dec 23, 2020
9f5cfc2
Add dummy support
Kingwl Dec 23, 2020
3de96fd
Simplify code
Kingwl Dec 23, 2020
a6fd2cc
Use utils type converter
Kingwl Dec 24, 2020
bf4e237
Avoid generated file
Kingwl Dec 24, 2020
ff8ae0b
Avoid changes
Kingwl Dec 24, 2020
d24ab0a
Improve comments and code style
Kingwl Dec 24, 2020
1954e93
Adjust hint label styles
Kingwl Dec 24, 2020
2db89c7
rename to inline hints
Kingwl Dec 24, 2020
2697a42
add range WIP
Kingwl Dec 24, 2020
d26dbae
Adjust request schedule
Kingwl Dec 25, 2020
7222b35
Fix cr issues
Kingwl Dec 25, 2020
4b3d54c
Avoid changes
Kingwl Dec 25, 2020
d20f8ed
Add style controls
Kingwl Dec 25, 2020
2b380bf
Support whitespace options
Kingwl Dec 25, 2020
b4789ec
Fix typo
Kingwl Dec 25, 2020
413b5d4
Avoid ts changes
Kingwl Dec 25, 2020
f93a2b6
fix cr issues
Kingwl Jan 4, 2021
4331023
Merge branch 'master' into signaure_arguments_label
Kingwl Jan 11, 2021
73b4dab
Make lint happy
Kingwl Jan 11, 2021
9853c8f
Fix cr issues
Kingwl Jan 13, 2021
9af036b
Fix comments
Kingwl Jan 13, 2021
fcc00b2
Avoid ts changes (#2)
Kingwl Jan 18, 2021
3c2c937
Merge branch 'master' into signaure_arguments_label
Kingwl Jan 18, 2021
ebac10e
Avoid conflict error
Kingwl Jan 18, 2021
1c131cf
Avoid extra fields
Kingwl Jan 18, 2021
756337d
Merge branch 'master' into signaure_arguments_label
jrieken Jan 18, 2021
ae67879
don't propose new API on ThemableDecorationAttachmentRenderOptions
jrieken Jan 18, 2021
0d4bf78
remove hover (should come via decoration) and action/menu (should be …
jrieken Jan 18, 2021
1981776
less state inside InlineHintsController-type, only have one type of d…
jrieken Jan 18, 2021
5087b08
:lipstick:
jrieken Jan 18, 2021
4651f66
simpler decoration type management (rely on internal ref counting)
jrieken Jan 18, 2021
1d3b03b
padding should depend on font size too
jrieken Jan 18, 2021
d65ab8d
use all of context decoration as decoration type key
jrieken Jan 18, 2021
7a93867
clamp font size at editor font size, don't go bigger
jrieken Jan 18, 2021
a40b4e7
add API command `vscode.executeInlineHintProvider` and some end-to-en…
jrieken Jan 18, 2021
30f17c9
Merge branch 'master' into signaure_arguments_label
Kingwl Jan 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/vs/editor/browser/services/codeEditorServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ const _CSS_MAP: { [prop: string]: string; } = {

fontStyle: 'font-style:{0};',
fontWeight: 'font-weight:{0};',
fontSize: 'font-size:{0};',
fontFamily: 'font-family:{0};',
textDecoration: 'text-decoration:{0};',
cursor: 'cursor:{0};',
letterSpacing: 'letter-spacing:{0};',
Expand All @@ -357,6 +359,7 @@ const _CSS_MAP: { [prop: string]: string; } = {
contentText: 'content:\'{0}\';',
contentIconPath: 'content:{0};',
margin: 'margin:{0};',
padding: 'padding:{0};',
width: 'width:{0};',
height: 'height:{0};'
};
Expand Down Expand Up @@ -529,7 +532,7 @@ class DecorationCSSRules {

cssTextArr.push(strings.format(_CSS_MAP.contentText, escaped));
}
this.collectCSSText(opts, ['fontStyle', 'fontWeight', 'textDecoration', 'color', 'opacity', 'backgroundColor', 'margin'], cssTextArr);
this.collectCSSText(opts, ['fontStyle', 'fontWeight', 'fontSize', 'fontFamily', 'textDecoration', 'color', 'opacity', 'backgroundColor', 'margin', 'padding'], cssTextArr);
if (this.collectCSSText(opts, ['width', 'height'], cssTextArr)) {
cssTextArr.push('display:inline-block;');
}
Expand Down
4 changes: 4 additions & 0 deletions src/vs/editor/browser/widget/codeEditorWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,7 @@ export class EditorModeContext extends Disposable {
private readonly _hasMultipleDocumentFormattingProvider: IContextKey<boolean>;
private readonly _hasMultipleDocumentSelectionFormattingProvider: IContextKey<boolean>;
private readonly _hasSignatureHelpProvider: IContextKey<boolean>;
private readonly _hasInlineHintsProvider: IContextKey<boolean>;
private readonly _isInWalkThrough: IContextKey<boolean>;

constructor(
Expand All @@ -1857,6 +1858,7 @@ export class EditorModeContext extends Disposable {
this._hasReferenceProvider = EditorContextKeys.hasReferenceProvider.bindTo(_contextKeyService);
this._hasRenameProvider = EditorContextKeys.hasRenameProvider.bindTo(_contextKeyService);
this._hasSignatureHelpProvider = EditorContextKeys.hasSignatureHelpProvider.bindTo(_contextKeyService);
this._hasInlineHintsProvider = EditorContextKeys.hasInlineHintsProvider.bindTo(_contextKeyService);
this._hasDocumentFormattingProvider = EditorContextKeys.hasDocumentFormattingProvider.bindTo(_contextKeyService);
this._hasDocumentSelectionFormattingProvider = EditorContextKeys.hasDocumentSelectionFormattingProvider.bindTo(_contextKeyService);
this._hasMultipleDocumentFormattingProvider = EditorContextKeys.hasMultipleDocumentFormattingProvider.bindTo(_contextKeyService);
Expand Down Expand Up @@ -1885,6 +1887,7 @@ export class EditorModeContext extends Disposable {
this._register(modes.DocumentFormattingEditProviderRegistry.onDidChange(update));
this._register(modes.DocumentRangeFormattingEditProviderRegistry.onDidChange(update));
this._register(modes.SignatureHelpProviderRegistry.onDidChange(update));
this._register(modes.InlineHintsProviderRegistry.onDidChange(update));

update();
}
Expand Down Expand Up @@ -1936,6 +1939,7 @@ export class EditorModeContext extends Disposable {
this._hasReferenceProvider.set(modes.ReferenceProviderRegistry.has(model));
this._hasRenameProvider.set(modes.RenameProviderRegistry.has(model));
this._hasSignatureHelpProvider.set(modes.SignatureHelpProviderRegistry.has(model));
this._hasInlineHintsProvider.set(modes.InlineHintsProviderRegistry.has(model));
this._hasDocumentFormattingProvider.set(modes.DocumentFormattingEditProviderRegistry.has(model) || modes.DocumentRangeFormattingEditProviderRegistry.has(model));
this._hasDocumentSelectionFormattingProvider.set(modes.DocumentRangeFormattingEditProviderRegistry.has(model));
this._hasMultipleDocumentFormattingProvider.set(modes.DocumentFormattingEditProviderRegistry.all(model).length + modes.DocumentRangeFormattingEditProviderRegistry.all(model).length > 1);
Expand Down
75 changes: 74 additions & 1 deletion src/vs/editor/common/config/editorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,10 @@ export interface IEditorOptions {
* Controls strikethrough deprecated variables.
*/
showDeprecated?: boolean;
/**
* Control the behavior and rendering of the inline hints.
*/
inlineHints?: IEditorInlineHintsOptions;
}

/**
Expand Down Expand Up @@ -2369,6 +2373,74 @@ class EditorLightbulb extends BaseEditorOption<EditorOption.lightbulb, EditorLig

//#endregion

//#region inlineHints

/**
* Configuration options for editor inlineHints
*/
export interface IEditorInlineHintsOptions {
/**
* Enable the inline hints.
* Defaults to true.
*/
enabled?: boolean;

/**
* Font size of inline hints.
* Default to 90% of the editor font size.
*/
fontSize?: number;

/**
* Font family of inline hints.
* Defaults to editor font family.
*/
fontFamily?: string;
}

export type EditorInlineHintsOptions = Readonly<Required<IEditorInlineHintsOptions>>;

class EditorInlineHints extends BaseEditorOption<EditorOption.inlineHints, EditorInlineHintsOptions> {

constructor() {
const defaults: EditorInlineHintsOptions = { enabled: true, fontSize: 0, fontFamily: EDITOR_FONT_DEFAULTS.fontFamily };
super(
EditorOption.inlineHints, 'inlineHints', defaults,
{
'editor.inlineHints.enabled': {
type: 'boolean',
default: defaults.enabled,
description: nls.localize('inlineHints.enable', "Enables the inline hints in the editor.")
},
'editor.inlineHints.fontSize': {
type: 'number',
default: defaults.fontSize,
description: nls.localize('inlineHints.fontSize', "Controls font size of inline hints in the editor. When set to `0`, the 90% of `#editor.fontSize#` is used.")
},
'editor.inlineHints.fontFamily': {
type: 'string',
default: defaults.fontFamily,
description: nls.localize('inlineHints.fontFamily', "Controls font family of inline hints in the editor.")
},
}
);
}

public validate(_input: any): EditorInlineHintsOptions {
if (!_input || typeof _input !== 'object') {
return this.defaultValue;
}
const input = _input as IEditorInlineHintsOptions;
return {
enabled: boolean(input.enabled, this.defaultValue.enabled),
fontSize: EditorIntOption.clampedInt(input.fontSize, this.defaultValue.fontSize, 0, 100),
fontFamily: EditorStringOption.string(input.fontFamily, this.defaultValue.fontFamily)
};
}
}

//#endregion

//#region lineHeight

class EditorLineHeight extends EditorIntOption<EditorOption.lineHeight> {
Expand Down Expand Up @@ -3759,7 +3831,7 @@ export const enum EditorOption {
wrappingIndent,
wrappingStrategy,
showDeprecated,

inlineHints,
// Leave these at the end (because they have dependencies!)
editorClassName,
pixelRatio,
Expand Down Expand Up @@ -4263,6 +4335,7 @@ export const EditorOptions = {
EditorOption.showDeprecated, 'showDeprecated', true,
{ description: nls.localize('showDeprecated', "Controls strikethrough deprecated variables.") }
)),
inlineHints: register(new EditorInlineHints()),
snippetSuggestions: register(new EditorStringEnumOption(
EditorOption.snippetSuggestions, 'snippetSuggestions',
'inline' as 'top' | 'bottom' | 'inline' | 'none',
Expand Down
4 changes: 4 additions & 0 deletions src/vs/editor/common/editorCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ export interface IThemeDecorationRenderOptions {

fontStyle?: string;
fontWeight?: string;
fontSize?: string;
textDecoration?: string;
cursor?: string;
color?: string | ThemeColor;
Expand All @@ -632,11 +633,14 @@ export interface IContentDecorationRenderOptions {
borderColor?: string | ThemeColor;
fontStyle?: string;
fontWeight?: string;
fontSize?: string;
fontFamily?: string;
textDecoration?: string;
color?: string | ThemeColor;
backgroundColor?: string | ThemeColor;

margin?: string;
padding?: string;
width?: string;
height?: string;
}
Expand Down
1 change: 1 addition & 0 deletions src/vs/editor/common/editorContextKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export namespace EditorContextKeys {
export const hasReferenceProvider = new RawContextKey<boolean>('editorHasReferenceProvider', false);
export const hasRenameProvider = new RawContextKey<boolean>('editorHasRenameProvider', false);
export const hasSignatureHelpProvider = new RawContextKey<boolean>('editorHasSignatureHelpProvider', false);
export const hasInlineHintsProvider = new RawContextKey<boolean>('editorHasInlineHintsProvider', false);

// -- mode context keys: formatting
export const hasDocumentFormattingProvider = new RawContextKey<boolean>('editorHasDocumentFormattingProvider', false);
Expand Down
18 changes: 18 additions & 0 deletions src/vs/editor/common/modes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,19 @@ export interface CodeLensProvider {
resolveCodeLens?(model: model.ITextModel, codeLens: CodeLens, token: CancellationToken): ProviderResult<CodeLens>;
}

export interface InlineHint {
text: string;
range: IRange;
hoverMessage?: string;
whitespaceBefore?: boolean;
whitespaceAfter?: boolean;
}

export interface InlineHintsProvider {
onDidChangeInlineHints?: Event<void> | undefined;
provideInlineHints(model: model.ITextModel, range: Range, token: CancellationToken): ProviderResult<InlineHint[]>;
}

export interface SemanticTokensLegend {
readonly tokenTypes: string[];
readonly tokenModifiers: string[];
Expand Down Expand Up @@ -1764,6 +1777,11 @@ export const TypeDefinitionProviderRegistry = new LanguageFeatureRegistry<TypeDe
*/
export const CodeLensProviderRegistry = new LanguageFeatureRegistry<CodeLensProvider>();

/**
* @internal
*/
export const InlineHintsProviderRegistry = new LanguageFeatureRegistry<InlineHintsProvider>();

/**
* @internal
*/
Expand Down
11 changes: 6 additions & 5 deletions src/vs/editor/common/standalone/standaloneEnums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,12 @@ export enum EditorOption {
wrappingIndent = 117,
wrappingStrategy = 118,
showDeprecated = 119,
editorClassName = 120,
pixelRatio = 121,
tabFocusMode = 122,
layoutInfo = 123,
wrappingInfo = 124
inlineHints = 120,
editorClassName = 121,
pixelRatio = 122,
tabFocusMode = 123,
layoutInfo = 124,
wrappingInfo = 125
Kingwl marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
Loading