Skip to content

Commit

Permalink
Rename keyMatchSize to keyMatchScore (microsoft#238625)
Browse files Browse the repository at this point in the history
  • Loading branch information
rzhao271 authored Jan 23, 2025
1 parent b018522 commit 6fbae9a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
17 changes: 10 additions & 7 deletions src/vs/workbench/contrib/preferences/browser/preferencesSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class LocalSearchProvider implements ISearchProvider {

let orderedScore = LocalSearchProvider.START_SCORE; // Sort is not stable
const settingMatcher = (setting: ISetting) => {
const { matches, matchType, keyMatchSize } = new SettingMatches(this._filter, setting, true, true, (filter, setting) => preferencesModel.findValueMatches(filter, setting), this.configurationService);
const { matches, matchType, keyMatchScore } = new SettingMatches(this._filter, setting, true, true, (filter, setting) => preferencesModel.findValueMatches(filter, setting), this.configurationService);
const score = strings.equalsIgnoreCase(this._filter, setting.key) ?
LocalSearchProvider.EXACT_MATCH_SCORE :
orderedScore--;
Expand All @@ -108,7 +108,7 @@ export class LocalSearchProvider implements ISearchProvider {
{
matches,
matchType,
keyMatchSize,
keyMatchScore,
score
} :
null;
Expand Down Expand Up @@ -139,8 +139,11 @@ export class LocalSearchProvider implements ISearchProvider {
export class SettingMatches {
readonly matches: IRange[];
matchType: SettingMatchType = SettingMatchType.None;
/** A more precise match score for key matches. */
keyMatchSize: number = 0;
/**
* A match score for key matches to allow comparing key matches against each other.
* Otherwise, all key matches are treated the same, and sorting is done by ToC order.
*/
keyMatchScore: number = 0;

constructor(
searchString: string,
Expand Down Expand Up @@ -186,7 +189,7 @@ export class SettingMatches {
}
if (keyMatchingWords.size) {
this.matchType |= SettingMatchType.KeyMatch;
this.keyMatchSize = keyMatchingWords.size;
this.keyMatchScore = keyMatchingWords.size;
}

// Also check if the user tried searching by id.
Expand Down Expand Up @@ -407,7 +410,7 @@ class AiRelatedInformationSearchProvider implements IRemoteSearchProvider {
setting: settingsRecord[pick],
matches: [settingsRecord[pick].range],
matchType: SettingMatchType.RemoteMatch,
keyMatchSize: 0,
keyMatchScore: 0,
score: info.weight
});
}
Expand Down Expand Up @@ -503,7 +506,7 @@ class TfIdfSearchProvider implements IRemoteSearchProvider {
setting: this._settingsRecord[pick],
matches: [this._settingsRecord[pick].range],
matchType: SettingMatchType.RemoteMatch,
keyMatchSize: 0,
keyMatchScore: 0,
score: info.score
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,7 @@ export class SettingsEditor2 extends EditorPane {
for (const g of this.defaultSettingsEditorModel.settingsGroups.slice(1)) {
for (const sect of g.sections) {
for (const setting of sect.settings) {
fullResult.filterMatches.push({ setting, matches: [], matchType: SettingMatchType.None, keyMatchSize: 0, score: 0 });
fullResult.filterMatches.push({ setting, matches: [], matchType: SettingMatchType.None, keyMatchScore: 0, score: 0 });
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ export class SearchResultModel extends SettingsTreeModel {
} else if (a.matchType === SettingMatchType.KeyMatch) {
// The match types are the same and are KeyMatch.
// Sort by the number of words matched in the key.
return b.keyMatchSize - a.keyMatchSize;
return b.keyMatchScore - a.keyMatchScore;
} else if (a.matchType === SettingMatchType.RemoteMatch) {
// The match types are the same and are RemoteMatch.
// Sort by score.
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/services/preferences/common/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export interface ISettingMatch {
setting: ISetting;
matches: IRange[] | null;
matchType: SettingMatchType;
keyMatchSize: number;
keyMatchScore: number;
score: number;
}

Expand Down Expand Up @@ -186,7 +186,7 @@ export interface IPreferencesEditorModel<T> {
}

export type IGroupFilter = (group: ISettingsGroup) => boolean | null;
export type ISettingMatcher = (setting: ISetting, group: ISettingsGroup) => { matches: IRange[]; matchType: SettingMatchType; keyMatchSize: number; score: number } | null;
export type ISettingMatcher = (setting: ISetting, group: ISettingsGroup) => { matches: IRange[]; matchType: SettingMatchType; keyMatchScore: number; score: number } | null;

export interface ISettingsEditorModel extends IPreferencesEditorModel<ISetting> {
readonly onDidChangeGroups: Event<void>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ abstract class AbstractSettingsModel extends EditorModel {
setting,
matches: settingMatchResult && settingMatchResult.matches,
matchType: settingMatchResult?.matchType ?? SettingMatchType.None,
keyMatchSize: settingMatchResult?.keyMatchSize ?? 0,
keyMatchScore: settingMatchResult?.keyMatchScore ?? 0,
score: settingMatchResult?.score ?? 0
});
}
Expand Down Expand Up @@ -900,7 +900,7 @@ export class DefaultSettingsEditorModel extends AbstractSettingsModel implements
setting: filteredMatch.setting,
score: filteredMatch.score,
matchType: filteredMatch.matchType,
keyMatchSize: filteredMatch.keyMatchSize,
keyMatchScore: filteredMatch.keyMatchScore,
matches: filteredMatch.matches && filteredMatch.matches.map(match => {
return new Range(
match.startLineNumber - filteredMatch.setting.range.startLineNumber,
Expand Down

0 comments on commit 6fbae9a

Please sign in to comment.