Skip to content

Commit 21a561c

Browse files
authored
Prevent new search regressing issue microsoft#239936 (microsoft#241733)
1 parent f66e839 commit 21a561c

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

src/vs/workbench/contrib/preferences/browser/preferencesSearch.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { ISettingsEditorModel, ISetting, ISettingsGroup, ISearchResult, IGroupFilter, SettingMatchType, ISettingMatch } from '../../../services/preferences/common/preferences.js';
6+
import { ISettingsEditorModel, ISetting, ISettingsGroup, ISearchResult, IGroupFilter, SettingMatchType, ISettingMatch, SettingKeyMatchTypes } from '../../../services/preferences/common/preferences.js';
77
import { IRange } from '../../../../editor/common/core/range.js';
88
import { distinct } from '../../../../base/common/arrays.js';
99
import * as strings from '../../../../base/common/strings.js';
@@ -131,9 +131,11 @@ export class LocalSearchProvider implements ISearchProvider {
131131
exactMatch: true
132132
});
133133
} else if (useNewKeyMatchAlgorithm) {
134-
// Filter by the top match type.
135-
const topMatchType = Math.max(...filterMatches.map(m => m.matchType));
136-
const filteredMatches = filterMatches.filter(m => m.matchType === topMatchType);
134+
// Check the top key match type.
135+
const topKeyMatchType = Math.max(...filterMatches.map(m => (m.matchType & SettingKeyMatchTypes)));
136+
// Always allow description matches as part of https://github.com/microsoft/vscode/issues/239936.
137+
const alwaysAllowedMatchTypes = SettingMatchType.DescriptionOrValueMatch | SettingMatchType.LanguageTagSettingMatch;
138+
const filteredMatches = filterMatches.filter(m => (m.matchType & topKeyMatchType) || (m.matchType & alwaysAllowedMatchTypes));
137139
return Promise.resolve({
138140
filterMatches: filteredMatches,
139141
exactMatch: false

src/vs/workbench/contrib/preferences/browser/settingsTreeModels.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -971,10 +971,9 @@ export class SearchResultModel extends SettingsTreeModel {
971971
// Sort by match type if the match types are not the same.
972972
// The priority of the match type is given by the SettingMatchType enum.
973973
return b.matchType - a.matchType;
974-
} else if (a.matchType === SettingMatchType.NonContiguousWordsInSettingsLabel || a.matchType === SettingMatchType.ContiguousWordsInSettingsLabel) {
975-
// The match types are the same.
976-
// Sort by the number of words matched in the key.
977-
// If those are the same, sort by the order in the table of contents.
974+
} else if ((a.matchType & SettingMatchType.NonContiguousWordsInSettingsLabel) || (a.matchType & SettingMatchType.ContiguousWordsInSettingsLabel)) {
975+
// The match types of a and b are the same and can be sorted by their number of matched words.
976+
// If those numbers are the same, sort by the order in the table of contents.
978977
return (b.keyMatchScore - a.keyMatchScore) || compareTwoNullableNumbers(a.setting.internalOrder, b.setting.internalOrder);
979978
} else if (a.matchType === SettingMatchType.RemoteMatch) {
980979
// The match types are the same and are RemoteMatch.

src/vs/workbench/services/preferences/common/preferences.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ export enum SettingMatchType {
144144
ContiguousQueryInSettingId = 1 << 6,
145145
AllWordsInSettingsLabel = 1 << 7,
146146
}
147+
export const SettingKeyMatchTypes = (SettingMatchType.AllWordsInSettingsLabel
148+
| SettingMatchType.ContiguousWordsInSettingsLabel
149+
| SettingMatchType.NonContiguousWordsInSettingsLabel
150+
| SettingMatchType.NonContiguousQueryInSettingId
151+
| SettingMatchType.ContiguousQueryInSettingId);
147152

148153
export interface ISettingMatch {
149154
setting: ISetting;

0 commit comments

Comments
 (0)