diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index c244fb4c45a..bce85536162 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -626,17 +626,9 @@ export interface IEditorOptions { */ showDeprecated?: boolean; /** - * Controls show inline hints. + * Control the behavior and rendering of the inline hints. */ - showInlineHints?: boolean; - /** - * Inline hints font size. Default to 90% of the editor font size. - */ - inlineHintsFontSize?: number; - /** - * Inline hints font family. Defaults to editor font family. - */ - inlineHintsFontFamily?: string + inlineHints?: IEditorInlineHintsOptions; } /** @@ -2381,6 +2373,74 @@ class EditorLightbulb extends BaseEditorOption>; + +class EditorInlineHints extends BaseEditorOption { + + 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 { @@ -3771,9 +3831,7 @@ export const enum EditorOption { wrappingIndent, wrappingStrategy, showDeprecated, - showInlineHints, - inlineHintsFontSize, - inlineHintsFontFamily, + inlineHints, // Leave these at the end (because they have dependencies!) editorClassName, pixelRatio, @@ -4277,19 +4335,7 @@ export const EditorOptions = { EditorOption.showDeprecated, 'showDeprecated', true, { description: nls.localize('showDeprecated', "Controls strikethrough deprecated variables.") } )), - showInlineHints: register(new EditorBooleanOption( - EditorOption.showInlineHints, 'showInlineHints', true, - { description: nls.localize('showInlineHints', "Controls show inline hints.") } - )), - inlineHintsFontSize: register(new EditorIntOption( - EditorOption.inlineHintsFontSize, 'inlineHintsFontSize', - 0, 0, 1000, - { markdownDescription: nls.localize('inlineHintsFontSize', "Font size for the inline hints. When set to `0`, the value of `#editor.fontSize#` is used.") } - )), - inlineHintsFontFamily: register(new EditorStringOption( - EditorOption.inlineHintsFontFamily, 'inlineHintsFontFamily', EDITOR_FONT_DEFAULTS.fontFamily, - { description: nls.localize('inlineHintsFontFamily', "Controls inline hints font family.") } - )), + inlineHints: register(new EditorInlineHints()), snippetSuggestions: register(new EditorStringEnumOption( EditorOption.snippetSuggestions, 'snippetSuggestions', 'inline' as 'top' | 'bottom' | 'inline' | 'none', diff --git a/src/vs/editor/common/standalone/standaloneEnums.ts b/src/vs/editor/common/standalone/standaloneEnums.ts index 431f74b302e..ad85fc86c5b 100644 --- a/src/vs/editor/common/standalone/standaloneEnums.ts +++ b/src/vs/editor/common/standalone/standaloneEnums.ts @@ -287,14 +287,12 @@ export enum EditorOption { wrappingIndent = 117, wrappingStrategy = 118, showDeprecated = 119, - showInlineHints = 120, - inlineHintsFontSize = 121, - inlineHintsFontFamily = 122, - editorClassName = 123, - pixelRatio = 124, - tabFocusMode = 125, - layoutInfo = 126, - wrappingInfo = 127 + inlineHints = 120, + editorClassName = 121, + pixelRatio = 122, + tabFocusMode = 123, + layoutInfo = 124, + wrappingInfo = 125 } /** diff --git a/src/vs/editor/contrib/inlineHints/inlineHintsController.ts b/src/vs/editor/contrib/inlineHints/inlineHintsController.ts index a5e12ea2f04..67bd5470c46 100644 --- a/src/vs/editor/contrib/inlineHints/inlineHintsController.ts +++ b/src/vs/editor/contrib/inlineHints/inlineHintsController.ts @@ -89,7 +89,7 @@ export class InlineHintsDetector extends Disposable implements IEditorContributi return false; } - return this._editor.getOption(EditorOption.showInlineHints); + return this._editor.getOption(EditorOption.inlineHints).enabled; } static get(editor: ICodeEditor): InlineHintsDetector { @@ -180,8 +180,8 @@ export class InlineHintsDetector extends Disposable implements IEditorContributi const hint = hintsData[i].list; for (let j = 0; j < hint.length && decorations.length < MAX_DECORATORS; j++) { const { text, position, whitespaceBefore, whitespaceAfter } = hint[j]; - const marginBefore = whitespaceBefore ? 5 : 0; - const marginAfter = whitespaceAfter ? 5 : 0; + const marginBefore = whitespaceBefore ? fontSize / 3 : 0; + const marginAfter = whitespaceAfter ? fontSize / 3 : 0; const subKey = hash(text).toString(16); let key = 'inlineHints-' + subKey; @@ -223,11 +223,13 @@ export class InlineHintsDetector extends Disposable implements IEditorContributi } private _getLayoutInfo() { - let fontSize = this._editor.getOption(EditorOption.inlineHintsFontSize); + const options = this._editor.getOption(EditorOption.inlineHints); + let fontSize = options.fontSize; if (!fontSize || fontSize < 5) { fontSize = (this._editor.getOption(EditorOption.fontSize) * .9) | 0; } - const fontFamily = this._editor.getOption(EditorOption.inlineHintsFontFamily); + + const fontFamily = options.fontFamily; return { fontSize, fontFamily }; } diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index f8911a522eb..99e17ca6ed0 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -3177,17 +3177,9 @@ declare namespace monaco.editor { */ showDeprecated?: boolean; /** - * Controls show inline hints. + * Control the behavior and rendering of the inline hints. */ - showInlineHints?: boolean; - /** - * Inline hints font size. Default to 90% of the editor font size. - */ - inlineHintsFontSize?: number; - /** - * Inline hints font family. Defaults to editor font family. - */ - inlineHintsFontFamily?: string; + inlineHints?: IEditorInlineHintsOptions; } /** @@ -3539,6 +3531,29 @@ declare namespace monaco.editor { export type EditorLightbulbOptions = Readonly>; + /** + * 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>; + /** * Configuration options for editor minimap */ @@ -4040,14 +4055,12 @@ declare namespace monaco.editor { wrappingIndent = 117, wrappingStrategy = 118, showDeprecated = 119, - showInlineHints = 120, - inlineHintsFontSize = 121, - inlineHintsFontFamily = 122, - editorClassName = 123, - pixelRatio = 124, - tabFocusMode = 125, - layoutInfo = 126, - wrappingInfo = 127 + inlineHints = 120, + editorClassName = 121, + pixelRatio = 122, + tabFocusMode = 123, + layoutInfo = 124, + wrappingInfo = 125 } export const EditorOptions: { acceptSuggestionOnCommitCharacter: IEditorOption; @@ -4148,9 +4161,7 @@ declare namespace monaco.editor { showFoldingControls: IEditorOption; showUnused: IEditorOption; showDeprecated: IEditorOption; - showInlineHints: IEditorOption; - inlineHintsFontSize: IEditorOption; - inlineHintsFontFamily: IEditorOption; + inlineHints: IEditorOption; snippetSuggestions: IEditorOption; smartSelect: IEditorOption; smoothScrolling: IEditorOption; diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 0785de594ab..2af404f8d0f 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -484,6 +484,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I return extHostLanguages.tokenAtPosition(doc, pos); }, registerInlineHintsProvider(selector: vscode.DocumentSelector, provider: vscode.InlineHintsProvider): vscode.Disposable { + checkProposedApiEnabled(extension); return extHostLanguageFeatures.registerInlineHintsProvider(extension, selector, provider); } }; diff --git a/src/vs/workbench/api/common/extHostLanguageFeatures.ts b/src/vs/workbench/api/common/extHostLanguageFeatures.ts index a1f4502b354..861a010f412 100644 --- a/src/vs/workbench/api/common/extHostLanguageFeatures.ts +++ b/src/vs/workbench/api/common/extHostLanguageFeatures.ts @@ -1063,8 +1063,6 @@ class SignatureHelpAdapter { } class InlineHintsAdapter { - private readonly _cache = new Cache('InlineHints'); - constructor( private readonly _documents: ExtHostDocuments, private readonly _provider: vscode.InlineHintsProvider, @@ -1073,11 +1071,7 @@ class InlineHintsAdapter { provideInlineHints(resource: URI, range: IRange, token: CancellationToken): Promise { const doc = this._documents.getDocument(resource); return asPromise(() => this._provider.provideInlineHints(doc, typeConvert.Range.to(range), token)).then(value => { - if (value) { - const id = this._cache.add([value]); - return { hints: value.map(typeConvert.InlineHint.from), id }; - } - return undefined; + return value ? { hints: value.map(typeConvert.InlineHint.from) } : undefined; }); } } diff --git a/src/vs/workbench/api/common/extHostTypeConverters.ts b/src/vs/workbench/api/common/extHostTypeConverters.ts index c6a344891d1..dec42ed93e3 100644 --- a/src/vs/workbench/api/common/extHostTypeConverters.ts +++ b/src/vs/workbench/api/common/extHostTypeConverters.ts @@ -1019,6 +1019,7 @@ export namespace SignatureHelp { } export namespace InlineHint { + export function from(hint: vscode.InlineHint): modes.InlineHint { return { text: hint.text, @@ -1027,6 +1028,15 @@ export namespace InlineHint { whitespaceAfter: hint.whitespaceAfter }; } + + export function to(hint: modes.InlineHint): vscode.InlineHint { + return { + text: hint.text, + position: Position.to(hint.position), + whitespaceBefore: hint.whitespaceBefore, + whitespaceAfter: hint.whitespaceAfter + }; + } } export namespace DocumentLink {