Skip to content

Commit

Permalink
add setting editor.suggest.filteredTypes, #45039
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Mar 7, 2019
1 parent 1cb20c7 commit cd4c799
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 10 deletions.
137 changes: 137 additions & 0 deletions src/vs/editor/common/config/commonEditorConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 10 additions & 2 deletions src/vs/editor/common/config/editorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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>;
}

/**
Expand Down Expand Up @@ -927,6 +932,7 @@ export interface InternalSuggestOptions {
readonly shareSuggestSelections: boolean;
readonly showIcons: boolean;
readonly maxVisibileSuggestions: number;
readonly filteredTypes: Record<string, boolean>;
}

export interface InternalParameterHintOptions {
Expand Down Expand Up @@ -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)
};
}

Expand Down Expand Up @@ -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,
Expand Down
15 changes: 12 additions & 3 deletions src/vs/editor/common/modes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
};
})();

Expand Down
13 changes: 11 additions & 2 deletions src/vs/editor/contrib/suggest/suggestModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand All @@ -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(
Expand Down
9 changes: 6 additions & 3 deletions src/vs/editor/contrib/suggest/test/completionModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
}

/**
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit cd4c799

Please sign in to comment.