Skip to content

Commit 8aa08cb

Browse files
author
Akos Kitta
committed
fixed fuzzy. added proper boost.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
1 parent fdc5814 commit 8aa08cb

File tree

7 files changed

+436
-37
lines changed

7 files changed

+436
-37
lines changed

arduino-ide-extension/src/browser/boards/boards-data-menu-updater.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,34 +42,36 @@ export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
4242
const { fqbn } = selectedBoard;
4343
if (fqbn) {
4444
const { configOptions, programmers, selectedProgrammer } = await this.boardsDataStore.getData(fqbn);
45-
const boardsConfigMenuPath = [...ArduinoMenus.TOOLS, 'z01_boardsConfig']; // `z_` is for ordering.
46-
for (const { label, option, values } of configOptions.sort(ConfigOption.LABEL_COMPARATOR)) {
47-
const menuPath = [...boardsConfigMenuPath, `${option}`];
48-
const commands = new Map<string, Disposable & { label: string }>()
49-
for (const value of values) {
50-
const id = `${fqbn}-${option}--${value.value}`;
51-
const command = { id };
52-
const selectedValue = value.value;
53-
const handler = {
54-
execute: () => this.boardsDataStore.selectConfigOption({ fqbn, option, selectedValue }),
55-
isToggled: () => value.selected
56-
};
57-
commands.set(id, Object.assign(this.commandRegistry.registerCommand(command, handler), { label: value.label }));
45+
if (configOptions.length) {
46+
const boardsConfigMenuPath = [...ArduinoMenus.TOOLS, 'z01_boardsConfig']; // `z_` is for ordering.
47+
for (const { label, option, values } of configOptions.sort(ConfigOption.LABEL_COMPARATOR)) {
48+
const menuPath = [...boardsConfigMenuPath, `${option}`];
49+
const commands = new Map<string, Disposable & { label: string }>()
50+
for (const value of values) {
51+
const id = `${fqbn}-${option}--${value.value}`;
52+
const command = { id };
53+
const selectedValue = value.value;
54+
const handler = {
55+
execute: () => this.boardsDataStore.selectConfigOption({ fqbn, option, selectedValue }),
56+
isToggled: () => value.selected
57+
};
58+
commands.set(id, Object.assign(this.commandRegistry.registerCommand(command, handler), { label: value.label }));
59+
}
60+
this.menuRegistry.registerSubmenu(menuPath, label);
61+
this.toDisposeOnBoardChange.pushAll([
62+
...commands.values(),
63+
Disposable.create(() => this.unregisterSubmenu(menuPath)), // We cannot dispose submenu entries: https://github.com/eclipse-theia/theia/issues/7299
64+
...Array.from(commands.keys()).map((commandId, i) => {
65+
const { label } = commands.get(commandId)!;
66+
this.menuRegistry.registerMenuAction(menuPath, { commandId, order: `${i}`, label });
67+
return Disposable.create(() => this.menuRegistry.unregisterMenuAction(commandId));
68+
})
69+
]);
5870
}
59-
this.menuRegistry.registerSubmenu(menuPath, label);
60-
this.toDisposeOnBoardChange.pushAll([
61-
...commands.values(),
62-
Disposable.create(() => this.unregisterSubmenu(menuPath)), // We cannot dispose submenu entries: https://github.com/eclipse-theia/theia/issues/7299
63-
...Array.from(commands.keys()).map((commandId, i) => {
64-
const { label } = commands.get(commandId)!;
65-
this.menuRegistry.registerMenuAction(menuPath, { commandId, order: `${i}`, label });
66-
return Disposable.create(() => this.menuRegistry.unregisterMenuAction(commandId));
67-
})
68-
]);
6971
}
7072
if (programmers.length) {
7173
const programmersMenuPath = [...ArduinoMenus.TOOLS, 'z02_programmers'];
72-
const label = selectedProgrammer ? `Programmer: ${selectedProgrammer.name}` : 'Programmer'
74+
const label = selectedProgrammer ? `Programmer: "${selectedProgrammer.name}"` : 'Programmer'
7375
this.menuRegistry.registerSubmenu(programmersMenuPath, label);
7476
for (const programmer of programmers) {
7577
const { id, name } = programmer;

arduino-ide-extension/src/browser/boards/boards-service-client-impl.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import { RecursiveRequired } from '../../common/types';
88
import { BoardsServiceClient, AttachedBoardsChangeEvent, BoardInstalledEvent, Board, Port, BoardUninstalledEvent, BoardsService } from '../../common/protocol';
99
import { BoardsConfig } from './boards-config';
1010
import { naturalCompare } from '../../common/utils';
11+
import { compareAnything } from '../theia/monaco/comparers';
12+
13+
interface BoardMatch {
14+
readonly board: Board & Readonly<{ packageName: string }>;
15+
readonly matches: monaco.filters.IMatch[] | undefined;
16+
}
1117

1218
@injectable()
1319
export class BoardsServiceClientImpl implements BoardsServiceClient, FrontendApplicationContribution {
@@ -168,13 +174,28 @@ export class BoardsServiceClientImpl implements BoardsServiceClient, FrontendApp
168174
const coresFilter = !!cores && cores.length
169175
? ((toFilter: { packageName: string }) => cores.some(core => core === toFilter.packageName))
170176
: () => true;
171-
const fuzzyFilter = !!query
172-
? ((toFilter: Board) => !!monaco.filters.matchesFuzzy(query, toFilter.name, true))
173-
: () => true
174-
return boards
175-
.filter(coresFilter)
176-
.filter(fuzzyFilter)
177-
.sort(Board.compare)
177+
if (!query) {
178+
return boards.filter(coresFilter).sort(Board.compare);
179+
}
180+
const toMatch = ((toFilter: Board & { packageName: string }) => (({ board: toFilter, matches: monaco.filters.matchesFuzzy(query, toFilter.name, true) })));
181+
const compareEntries = (left: BoardMatch, right: BoardMatch, lookFor: string) => {
182+
const leftMatches = left.matches || [];
183+
const rightMatches = right.matches || [];
184+
if (leftMatches.length && !rightMatches.length) {
185+
return -1;
186+
}
187+
if (!leftMatches.length && rightMatches.length) {
188+
return 1;
189+
}
190+
if (leftMatches.length === 0 && rightMatches.length === 0) {
191+
return 0;
192+
}
193+
const leftLabel = left.board.name.replace(/\r?\n/g, ' ');
194+
const rightLabel = right.board.name.replace(/\r?\n/g, ' ');
195+
return compareAnything(leftLabel, rightLabel, lookFor);
196+
}
197+
const normalizedQuery = query.toLowerCase();
198+
return boards.filter(coresFilter).map(toMatch).sort((left, right) => compareEntries(left, right, normalizedQuery)).map(({ board }) => board);
178199
}
179200

180201
get boardsConfig(): BoardsConfig.Config {

arduino-ide-extension/src/browser/contributions/edit-contributions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ ${value}
219219
}
220220

221221
protected async run(commandId: string): Promise<any> {
222-
const editor = await this.current();
222+
const editor = await this.current(); // TODO: this should be the active monaco editor and not Theia editor. e.g: Output
223223
if (editor) {
224224
const action = editor.getControl().getAction(commandId);
225225
if (action) {

0 commit comments

Comments
 (0)