fix cr issues

This commit is contained in:
kingwl
2021-01-04 21:15:59 +08:00
parent 413b5d4705
commit f93a2b62ef
7 changed files with 129 additions and 67 deletions
+72 -26
View File
@@ -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<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> {
@@ -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',
@@ -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
}
/**
@@ -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 };
}
+32 -21
View File
@@ -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<Required<IEditorLightbulbOptions>>;
/**
* 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>>;
/**
* 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<EditorOption.acceptSuggestionOnCommitCharacter, boolean>;
@@ -4148,9 +4161,7 @@ declare namespace monaco.editor {
showFoldingControls: IEditorOption<EditorOption.showFoldingControls, 'always' | 'mouseover'>;
showUnused: IEditorOption<EditorOption.showUnused, boolean>;
showDeprecated: IEditorOption<EditorOption.showDeprecated, boolean>;
showInlineHints: IEditorOption<EditorOption.showInlineHints, boolean>;
inlineHintsFontSize: IEditorOption<EditorOption.inlineHintsFontSize, number>;
inlineHintsFontFamily: IEditorOption<EditorOption.inlineHintsFontFamily, string>;
inlineHints: IEditorOption<EditorOption.inlineHints, any>;
snippetSuggestions: IEditorOption<EditorOption.snippetSuggestions, 'none' | 'top' | 'bottom' | 'inline'>;
smartSelect: IEditorOption<EditorOption.smartSelect, any>;
smoothScrolling: IEditorOption<EditorOption.smoothScrolling, boolean>;
@@ -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);
}
};
@@ -1063,8 +1063,6 @@ class SignatureHelpAdapter {
}
class InlineHintsAdapter {
private readonly _cache = new Cache<vscode.InlineHint[]>('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<extHostProtocol.IInlineHintsDto | undefined> {
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;
});
}
}
@@ -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 {