mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-01 22:12:26 +01:00
Use set instead instead of regexp for kind modifiers
This commit is contained in:
@@ -76,26 +76,30 @@ class MyCompletionItem extends vscode.CompletionItem {
|
||||
}
|
||||
}
|
||||
|
||||
if (tsEntry.kindModifiers && tsEntry.kindModifiers.match(/\boptional\b/)) {
|
||||
if (!this.insertText) {
|
||||
this.insertText = this.label;
|
||||
if (tsEntry.kindModifiers) {
|
||||
const kindModifiers = new Set(tsEntry.kindModifiers.split(/\s+/g));
|
||||
|
||||
if (kindModifiers.has(PConst.KindModifiers.optional)) {
|
||||
if (!this.insertText) {
|
||||
this.insertText = this.label;
|
||||
}
|
||||
|
||||
if (!this.filterText) {
|
||||
this.filterText = this.label;
|
||||
}
|
||||
this.label += '?';
|
||||
}
|
||||
|
||||
if (!this.filterText) {
|
||||
this.filterText = this.label;
|
||||
}
|
||||
this.label += '?';
|
||||
}
|
||||
|
||||
if (tsEntry.kind === PConst.Kind.script && tsEntry.kindModifiers) {
|
||||
for (const extModifier of PConst.KindModifiers.fileExtensionKindModifiers) {
|
||||
if (tsEntry.kindModifiers.match(extModifier.pattern)) {
|
||||
if (tsEntry.name.toLowerCase().endsWith(extModifier.value)) {
|
||||
this.detail = tsEntry.name;
|
||||
} else {
|
||||
this.detail = tsEntry.name + extModifier.value;
|
||||
if (tsEntry.kind === PConst.Kind.script) {
|
||||
for (const extModifier of PConst.KindModifiers.fileExtensionKindModifiers) {
|
||||
if (kindModifiers.has(extModifier)) {
|
||||
if (tsEntry.name.toLowerCase().endsWith(extModifier)) {
|
||||
this.detail = tsEntry.name;
|
||||
} else {
|
||||
this.detail = tsEntry.name + extModifier;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,25 +41,22 @@ export class DiagnosticCategory {
|
||||
public static readonly suggestion = 'suggestion';
|
||||
}
|
||||
|
||||
interface KindModifier {
|
||||
readonly pattern: RegExp;
|
||||
readonly value: string;
|
||||
}
|
||||
|
||||
export class KindModifiers {
|
||||
public static readonly dtsModifier: KindModifier = { pattern: /(^|\s)\.d\.ts($|\s)/i, value: '.d.ts' };
|
||||
public static readonly tsModifier: KindModifier = { pattern: /(^|\s)\.ts($|\s)/i, value: '.ts' };
|
||||
public static readonly tsxModifier: KindModifier = { pattern: /(^|\s)\.tsx($|\s)/i, value: '.tsx' };
|
||||
public static readonly jsModifier: KindModifier = { pattern: /(^|\s)\.js($|\s)/i, value: '.js' };
|
||||
public static readonly jsxModifier: KindModifier = { pattern: /(^|\s)\.jsx($|\s)/i, value: '.jsx' };
|
||||
public static readonly jsonModifier: KindModifier = { pattern: /(^|\s)\.json($|\s)/i, value: '.json' };
|
||||
public static readonly optional = 'optional';
|
||||
|
||||
public static readonly dtsFile = '.d.ts';
|
||||
public static readonly tsFile = '.ts';
|
||||
public static readonly tsxFile = '.tsx';
|
||||
public static readonly jsFile = '.js';
|
||||
public static readonly jsxFile = '.jsx';
|
||||
public static readonly jsonFile = '.json';
|
||||
|
||||
public static readonly fileExtensionKindModifiers = [
|
||||
KindModifiers.dtsModifier,
|
||||
KindModifiers.tsModifier,
|
||||
KindModifiers.tsxModifier,
|
||||
KindModifiers.jsModifier,
|
||||
KindModifiers.jsxModifier,
|
||||
KindModifiers.jsonModifier,
|
||||
KindModifiers.dtsFile,
|
||||
KindModifiers.tsFile,
|
||||
KindModifiers.tsxFile,
|
||||
KindModifiers.jsFile,
|
||||
KindModifiers.jsxFile,
|
||||
KindModifiers.jsonFile,
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user