mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-25 17:27:26 +01:00
add setting editor.suggest.filteredTypes, #45039
This commit is contained in:
@@ -691,6 +691,143 @@ const editorConfiguration: IConfigurationNode = {
|
||||
maximum: 12,
|
||||
description: nls.localize('suggest.maxVisibileSuggestions', "Controls how many suggestions IntelliSense will show before showing a scrollbar.")
|
||||
},
|
||||
'editor.suggest.filteredTypes': {
|
||||
type: 'object',
|
||||
default: { keyword: true },
|
||||
markdownDescription: nls.localize('suggest.filtered', "Controls whether some suggestion types should be filtered from IntelliSense. A list of suggestion types can be found here: https://code.visualstudio.com/docs/editor/intellisense#_types-of-completions."),
|
||||
properties: {
|
||||
method: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.method', "When set to `false` IntelliSense never shows `method` suggestions.")
|
||||
},
|
||||
function: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.function', "When set to `false` IntelliSense never shows `function` suggestions.")
|
||||
},
|
||||
constructor: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.constructor', "When set to `false` IntelliSense never shows `constructor` suggestions.")
|
||||
},
|
||||
field: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.field', "When set to `false` IntelliSense never shows `field` suggestions.")
|
||||
},
|
||||
variable: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.variable', "When set to `false` IntelliSense never shows `variable` suggestions.")
|
||||
},
|
||||
class: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.class', "When set to `false` IntelliSense never shows `class` suggestions.")
|
||||
},
|
||||
struct: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.struct', "When set to `false` IntelliSense never shows `struct` suggestions.")
|
||||
},
|
||||
interface: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.interface', "When set to `false` IntelliSense never shows `interface` suggestions.")
|
||||
},
|
||||
module: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.module', "When set to `false` IntelliSense never shows `module` suggestions.")
|
||||
},
|
||||
property: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.property', "When set to `false` IntelliSense never shows `property` suggestions.")
|
||||
},
|
||||
event: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.event', "When set to `false` IntelliSense never shows `event` suggestions.")
|
||||
},
|
||||
operator: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.operator', "When set to `false` IntelliSense never shows `operator` suggestions.")
|
||||
},
|
||||
unit: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.unit', "When set to `false` IntelliSense never shows `unit` suggestions.")
|
||||
},
|
||||
value: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.value', "When set to `false` IntelliSense never shows `value` suggestions.")
|
||||
},
|
||||
constant: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.constant', "When set to `false` IntelliSense never shows `constant` suggestions.")
|
||||
},
|
||||
enum: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.enum', "When set to `false` IntelliSense never shows `enum` suggestions.")
|
||||
},
|
||||
enumMember: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.enumMember', "When set to `false` IntelliSense never shows `enumMember` suggestions.")
|
||||
},
|
||||
keyword: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.keyword', "When set to `false` IntelliSense never shows `keyword` suggestions.")
|
||||
},
|
||||
text: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.text', "When set to `false` IntelliSense never shows `text` suggestions.")
|
||||
},
|
||||
color: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.color', "When set to `false` IntelliSense never shows `color` suggestions.")
|
||||
},
|
||||
file: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.file', "When set to `false` IntelliSense never shows `file` suggestions.")
|
||||
},
|
||||
reference: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.reference', "When set to `false` IntelliSense never shows `reference` suggestions.")
|
||||
},
|
||||
customcolor: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.customcolor', "When set to `false` IntelliSense never shows `customcolor` suggestions.")
|
||||
},
|
||||
folder: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.folder', "When set to `false` IntelliSense never shows `folder` suggestions.")
|
||||
},
|
||||
typeParameter: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.typeParameter', "When set to `false` IntelliSense never shows `typeParameter` suggestions.")
|
||||
},
|
||||
snippet: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
markdownDescription: nls.localize('suggest.filtered.snippet', "When set to `false` IntelliSense never shows `snippet` suggestions.")
|
||||
},
|
||||
}
|
||||
},
|
||||
'editor.selectionHighlight': {
|
||||
'type': 'boolean',
|
||||
'default': EDITOR_DEFAULTS.contribInfo.selectionHighlight,
|
||||
|
||||
@@ -12,6 +12,7 @@ import { FontInfo } from 'vs/editor/common/config/fontInfo';
|
||||
import { Constants } from 'vs/editor/common/core/uint';
|
||||
import { USUAL_WORD_SEPARATORS } from 'vs/editor/common/model/wordHelper';
|
||||
import { AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility';
|
||||
import { isObject } from 'vs/base/common/types';
|
||||
|
||||
/**
|
||||
* Configuration options for editor scrollbars
|
||||
@@ -211,6 +212,10 @@ export interface ISuggestOptions {
|
||||
* Max suggestions to show in suggestions. Defaults to 12.
|
||||
*/
|
||||
maxVisibileSuggestions?: boolean;
|
||||
/**
|
||||
* Names of suggestion types to filter.
|
||||
*/
|
||||
filteredTypes?: Record<string, boolean>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -927,6 +932,7 @@ export interface InternalSuggestOptions {
|
||||
readonly shareSuggestSelections: boolean;
|
||||
readonly showIcons: boolean;
|
||||
readonly maxVisibileSuggestions: number;
|
||||
readonly filteredTypes: Record<string, boolean>;
|
||||
}
|
||||
|
||||
export interface InternalParameterHintOptions {
|
||||
@@ -1913,7 +1919,8 @@ export class EditorOptionsValidator {
|
||||
localityBonus: _boolean(suggestOpts.localityBonus, defaults.localityBonus),
|
||||
shareSuggestSelections: _boolean(suggestOpts.shareSuggestSelections, defaults.shareSuggestSelections),
|
||||
showIcons: _boolean(suggestOpts.showIcons, defaults.showIcons),
|
||||
maxVisibileSuggestions: _clampedInt(suggestOpts.maxVisibileSuggestions, defaults.maxVisibileSuggestions, 1, 12)
|
||||
maxVisibileSuggestions: _clampedInt(suggestOpts.maxVisibileSuggestions, defaults.maxVisibileSuggestions, 1, 12),
|
||||
filteredTypes: isObject(suggestOpts.filteredTypes) ? suggestOpts.filteredTypes : Object.create(null)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2672,7 +2679,8 @@ export const EDITOR_DEFAULTS: IValidatedEditorOptions = {
|
||||
localityBonus: false,
|
||||
shareSuggestSelections: false,
|
||||
showIcons: true,
|
||||
maxVisibileSuggestions: 12
|
||||
maxVisibileSuggestions: 12,
|
||||
filteredTypes: Object.create(null)
|
||||
},
|
||||
selectionHighlight: true,
|
||||
occurrencesHighlight: true,
|
||||
|
||||
@@ -324,7 +324,10 @@ export const completionKindToCssClass = (function () {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export let completionKindFromString = (function () {
|
||||
export let completionKindFromString: {
|
||||
(value: string): CompletionItemKind;
|
||||
(value: string, strict: true): CompletionItemKind | undefined;
|
||||
} = (function () {
|
||||
let data: Record<string, CompletionItemKind> = Object.create(null);
|
||||
data['method'] = CompletionItemKind.Method;
|
||||
data['function'] = CompletionItemKind.Function;
|
||||
@@ -343,6 +346,7 @@ export let completionKindFromString = (function () {
|
||||
data['constant'] = CompletionItemKind.Constant;
|
||||
data['enum'] = CompletionItemKind.Enum;
|
||||
data['enum-member'] = CompletionItemKind.EnumMember;
|
||||
data['enumMember'] = CompletionItemKind.EnumMember;
|
||||
data['keyword'] = CompletionItemKind.Keyword;
|
||||
data['snippet'] = CompletionItemKind.Snippet;
|
||||
data['text'] = CompletionItemKind.Text;
|
||||
@@ -352,9 +356,14 @@ export let completionKindFromString = (function () {
|
||||
data['customcolor'] = CompletionItemKind.Customcolor;
|
||||
data['folder'] = CompletionItemKind.Folder;
|
||||
data['type-parameter'] = CompletionItemKind.TypeParameter;
|
||||
data['typeParameter'] = CompletionItemKind.TypeParameter;
|
||||
|
||||
return function (value: string) {
|
||||
return data[value] || CompletionItemKind.Property;
|
||||
return function (value: string, strict?: true) {
|
||||
let res = data[value];
|
||||
if (typeof res === 'undefined' && !strict) {
|
||||
res = CompletionItemKind.Property;
|
||||
}
|
||||
return res;
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import { CursorChangeReason, ICursorSelectionChangedEvent } from 'vs/editor/comm
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { ITextModel, IWordAtPosition } from 'vs/editor/common/model';
|
||||
import { CompletionItemProvider, StandardTokenType, CompletionContext, CompletionProviderRegistry, CompletionTriggerKind, CompletionItemKind } from 'vs/editor/common/modes';
|
||||
import { CompletionItemProvider, StandardTokenType, CompletionContext, CompletionProviderRegistry, CompletionTriggerKind, CompletionItemKind, completionKindFromString } from 'vs/editor/common/modes';
|
||||
import { CompletionModel } from './completionModel';
|
||||
import { CompletionItem, getSuggestionComparator, provideSuggestionItems, getSnippetSuggestSupport, SnippetSortOrder, CompletionOptions } from './suggest';
|
||||
import { SnippetController2 } from 'vs/editor/contrib/snippet/snippetController2';
|
||||
@@ -379,9 +379,10 @@ export class SuggestModel implements IDisposable {
|
||||
this._requestToken = new CancellationTokenSource();
|
||||
|
||||
// kind filter and snippet sort rules
|
||||
const { contribInfo } = this._editor.getConfiguration();
|
||||
let itemKindFilter = new Set<CompletionItemKind>();
|
||||
let snippetSortOrder = SnippetSortOrder.Inline;
|
||||
switch (this._editor.getConfiguration().contribInfo.suggest.snippets) {
|
||||
switch (contribInfo.suggest.snippets) {
|
||||
case 'top':
|
||||
snippetSortOrder = SnippetSortOrder.Top;
|
||||
break;
|
||||
@@ -397,6 +398,14 @@ export class SuggestModel implements IDisposable {
|
||||
break;
|
||||
}
|
||||
|
||||
// kind filter
|
||||
for (const key in contribInfo.suggest.filteredTypes) {
|
||||
const kind = completionKindFromString(key, true);
|
||||
if (typeof kind !== 'undefined' && contribInfo.suggest.filteredTypes[key] === false) {
|
||||
itemKindFilter.add(kind);
|
||||
}
|
||||
}
|
||||
|
||||
let wordDistance = WordDistance.create(this._editorWorker, this._editor);
|
||||
|
||||
let items = provideSuggestionItems(
|
||||
|
||||
@@ -164,7 +164,8 @@ suite('CompletionModel', function () {
|
||||
localityBonus: false,
|
||||
shareSuggestSelections: false,
|
||||
showIcons: true,
|
||||
maxVisibileSuggestions: 12
|
||||
maxVisibileSuggestions: 12,
|
||||
filteredTypes: Object.create(null)
|
||||
});
|
||||
|
||||
assert.equal(model.items.length, 2);
|
||||
@@ -191,7 +192,8 @@ suite('CompletionModel', function () {
|
||||
localityBonus: false,
|
||||
shareSuggestSelections: false,
|
||||
showIcons: true,
|
||||
maxVisibileSuggestions: 12
|
||||
maxVisibileSuggestions: 12,
|
||||
filteredTypes: Object.create(null)
|
||||
});
|
||||
|
||||
assert.equal(model.items.length, 2);
|
||||
@@ -217,7 +219,8 @@ suite('CompletionModel', function () {
|
||||
localityBonus: false,
|
||||
shareSuggestSelections: false,
|
||||
showIcons: true,
|
||||
maxVisibileSuggestions: 12
|
||||
maxVisibileSuggestions: 12,
|
||||
filteredTypes: Object.create(null)
|
||||
});
|
||||
|
||||
assert.equal(model.items.length, 2);
|
||||
|
||||
Vendored
+5
@@ -2555,6 +2555,10 @@ declare namespace monaco.editor {
|
||||
* Max suggestions to show in suggestions. Defaults to 12.
|
||||
*/
|
||||
maxVisibileSuggestions?: boolean;
|
||||
/**
|
||||
* Names of suggestion types to filter.
|
||||
*/
|
||||
filteredTypes?: Record<string, boolean>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3200,6 +3204,7 @@ declare namespace monaco.editor {
|
||||
readonly shareSuggestSelections: boolean;
|
||||
readonly showIcons: boolean;
|
||||
readonly maxVisibileSuggestions: number;
|
||||
readonly filteredTypes: Record<string, boolean>;
|
||||
}
|
||||
|
||||
export interface InternalParameterHintOptions {
|
||||
|
||||
Reference in New Issue
Block a user