Skip to content

Commit

Permalink
Use properties for commitCharacters
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbvz committed Jul 13, 2018
1 parent 09e26ac commit eaa535f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as Previewer from '../utils/previewer';
import * as typeConverters from '../utils/typeConverters';
import TypingsStatus from '../utils/typingsStatus';
import FileConfigurationManager from './fileConfigurationManager';
import { memoize } from '../utils/memoize';

const localize = nls.loadMessageBundle();

Expand All @@ -34,9 +35,9 @@ class MyCompletionItem extends vscode.CompletionItem {
line: string,
public readonly tsEntry: Proto.CompletionEntry,
useCodeSnippetsOnMethodSuggest: boolean,
commitCharactersSettings: CommitCharactersSettings
public readonly commitCharactersSettings: CommitCharactersSettings
) {
super(tsEntry.name);
super(tsEntry.name, MyCompletionItem.convertKind(tsEntry.kind));

if (tsEntry.isRecommended) {
// Make sure isRecommended property always comes first
Expand All @@ -51,9 +52,7 @@ class MyCompletionItem extends vscode.CompletionItem {
this.sortText = tsEntry.sortText;
}

this.kind = MyCompletionItem.convertKind(tsEntry.kind);
this.position = position;
this.commitCharacters = MyCompletionItem.getCommitCharacters(commitCharactersSettings, tsEntry.kind);
this.useCodeSnippet = useCodeSnippetsOnMethodSuggest && (this.kind === vscode.CompletionItemKind.Function || this.kind === vscode.CompletionItemKind.Method);
if (tsEntry.replacementSpan) {
this.range = typeConverters.Range.fromTextSpan(tsEntry.replacementSpan);
Expand Down Expand Up @@ -136,7 +135,6 @@ class MyCompletionItem extends vscode.CompletionItem {
case PConst.Kind.interface:
return vscode.CompletionItemKind.Interface;
case PConst.Kind.warning:
case PConst.Kind.file:
case PConst.Kind.script:
return vscode.CompletionItemKind.File;
case PConst.Kind.directory:
Expand All @@ -147,20 +145,18 @@ class MyCompletionItem extends vscode.CompletionItem {
return vscode.CompletionItemKind.Property;
}

private static getCommitCharacters(
settings: CommitCharactersSettings,
kind: string
): string[] | undefined {
@memoize
public get commitCharacters(): string[] | undefined {
const commitCharacters: string[] = [];
switch (kind) {
switch (this.tsEntry.kind) {
case PConst.Kind.memberGetAccessor:
case PConst.Kind.memberSetAccessor:
case PConst.Kind.constructSignature:
case PConst.Kind.callSignature:
case PConst.Kind.indexSignature:
case PConst.Kind.enum:
case PConst.Kind.interface:
if (settings.enableDotCompletions) {
if (this.commitCharactersSettings.enableDotCompletions) {
commitCharacters.push('.');
}
break;
Expand All @@ -175,10 +171,10 @@ class MyCompletionItem extends vscode.CompletionItem {
case PConst.Kind.class:
case PConst.Kind.function:
case PConst.Kind.memberFunction:
if (settings.enableDotCompletions) {
if (this.commitCharactersSettings.enableDotCompletions) {
commitCharacters.push('.', ',');
}
if (settings.enableCallCompletions) {
if (this.commitCharactersSettings.enableCallCompletions) {
commitCharacters.push('(');
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export class Kind {
public static readonly directory = 'directory';
public static readonly enum = 'enum';
public static readonly externalModuleName = 'external module name';
public static readonly file = 'file';
public static readonly function = 'function';
public static readonly indexSignature = 'index';
public static readonly interface = 'interface';
Expand Down

0 comments on commit eaa535f

Please sign in to comment.