Skip to content

Commit

Permalink
feat: show schema suggestion at same level as query
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinslin committed Jul 8, 2020
1 parent 0d1f5b5 commit 830c50d
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions packages/plugin-core/src/components/lookup/LookupProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DNodeUtils, Note, Schema, SchemaUtils } from "@dendronhq/common-all";
import { DNodeUtils, Note, Schema, SchemaUtils, DNode } from "@dendronhq/common-all";
import { createLogger } from "@dendronhq/common-server";
import { DendronEngine } from "@dendronhq/engine-server";
import _ from "lodash";
Expand All @@ -12,12 +12,30 @@ const L = createLogger("LookupProvider");
class QueryStringUtils {
/**
* Get all schema matches for current query
*
* # eg. Query with Root
*
* schema:
* - bar
* - alpha
* - beta
* - foo
* - one
* - two
* qs: foo
*
* return: [one, two]
*
* # eg. Query not at root
* qs: foo.one
*
*
* @param _qs
* @param engineResp
*/
static getAllSchemaAtLevel(_qs: string, engineResp: Note[]): Schema[] {
const maybeSchema = engineResp[0]?.schema;
return maybeSchema?.parent?.children as Schema[] || [];
return maybeSchema?.children as Schema[] || [];
}

static isDomainQuery(qs: string): boolean {
Expand Down Expand Up @@ -63,11 +81,18 @@ class PickerUtils {
) {
return picker.value;
}

static getSelection<T extends QuickPickItem = QuickPickItem>(
picker: QuickPick<T>
): T {
return picker.selectedItems[0];
}

static filterStubs(items: DNode[]): DNode[] {
return _.filter(items, ent => {
return !ent.stub
});
}
}


Expand Down Expand Up @@ -136,6 +161,7 @@ export class LookupProvider {
return ent.fname;
});
}
updatedItems = PickerUtils.filterStubs(updatedItems);

// check if perfect match, remove @noActiveItem result if that's the case
if (perfectMatch) {
Expand Down

0 comments on commit 830c50d

Please sign in to comment.