Skip to content

Commit

Permalink
Add query selector config (#178)
Browse files Browse the repository at this point in the history
Context:
https://sourcegraph.slack.com/archives/C04MSD3DP5L/p1721935489008949

A customer wants to return context items from their provider if the
user's query matches some keywords. They wish to bypass the whole
mentions process and return context items for queries on submission
time.

This makes sense and is useful. 

This PR adds `meta.items.querySelectors` which will be used at query
evaluation time to match with query and then call `provider.items` for
the matching providers to collect context items.
  • Loading branch information
thenamankumar authored Jul 26, 2024
1 parent f588cc3 commit 7f2e5dc
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openctx/cli",
"version": "0.0.11",
"version": "0.0.12",
"description": "OpenCtx CLI",
"license": "Apache-2.0",
"homepage": "https://openctx.org/docs/clients/cli",
Expand Down
2 changes: 1 addition & 1 deletion client/vscode-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openctx/vscode-lib",
"version": "0.0.13",
"version": "0.0.14",
"description": "OpenCtx library for VS Code extensions",
"license": "Apache-2.0",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion lib/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openctx/client",
"version": "0.0.19",
"version": "0.0.20",
"description": "OpenCtx client library",
"license": "Apache-2.0",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion lib/protocol/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openctx/protocol",
"version": "0.0.15",
"version": "0.0.16",
"description": "OpenCtx client/provider protocol",
"license": "Apache-2.0",
"repository": {
Expand Down
30 changes: 30 additions & 0 deletions lib/protocol/src/openctx-protocol.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
{
"$ref": "#/definitions/Mention"
},
{
"$ref": "#/definitions/MessageSelector"
},
{
"$ref": "#/definitions/MentionSelector"
},
Expand Down Expand Up @@ -104,6 +107,18 @@
}
}
},
"MessageSelector": {
"description": "List of regex patterns matching a message for which the provider can return context items.",
"type": "object",
"additionalProperties": false,
"required": ["pattern"],
"properties": {
"pattern": {
"description": "The regex pattern matching a message for which the provider can return context items",
"type": "string"
}
}
},
"MetaParams": {
"type": "object",
"additionalProperties": false,
Expand Down Expand Up @@ -147,6 +162,21 @@
"description": "The name of the provider.",
"type": "string"
},
"items": {
"description": "Configuration for providing context items.",
"type": "object",
"additionalProperties": false,
"properties": {
"messageSelectors": {
"description": "The list of regex patterns for matching with a message for which the provider can return context items",
"type": "array",
"items": {
"$ref": "#/definitions/MessageSelector"
},
"tsType": "MessageSelector[]"
}
}
},
"mentions": {
"description": "Configuration for the mentions feature.",
"type": "object",
Expand Down
19 changes: 19 additions & 0 deletions lib/protocol/src/openctx-protocol.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type Protocol =
| MetaParams
| MetaResult
| Mention
| MessageSelector
| MentionSelector
| AnnotationSelector
| MentionsParams
Expand Down Expand Up @@ -48,6 +49,15 @@ export interface MetaResult {
* The name of the provider.
*/
name: string
/**
* Configuration for providing context items.
*/
items?: {
/**
* The list of regex patterns for matching with a message for which the provider can return context items
*/
messageSelectors?: MessageSelector[]
}
/**
* Configuration for the mentions feature.
*/
Expand Down Expand Up @@ -91,6 +101,15 @@ export interface Mention {
[k: string]: unknown | undefined
}
}
/**
* List of regex patterns matching a message for which the provider can return context items.
*/
export interface MessageSelector {
/**
* The regex pattern matching a message for which the provider can return context items
*/
pattern: string
}
/**
* List of regex patterns matching the mention text for which the provider can return mentions.
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openctx/provider",
"version": "0.0.14",
"version": "0.0.15",
"description": "OpenCtx provider library",
"license": "Apache-2.0",
"repository": {
Expand Down
1 change: 1 addition & 0 deletions provider/hello-world/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('helloWorld', () => {
expect(helloWorld.meta({}, {})).toStrictEqual<MetaResult>({
name: '✨ Hello World!',
annotations: {},
items: { messageSelectors: [{ pattern: '.*' }] },
}))

test('annotations', () =>
Expand Down
8 changes: 7 additions & 1 deletion provider/hello-world/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ import type {
*/
const helloWorld: Provider = {
meta(params: MetaParams, settings: ProviderSettings): MetaResult {
return { name: '✨ Hello World!', annotations: {} }
return {
name: '✨ Hello World!',
annotations: {},
items: {
messageSelectors: [{ pattern: '.*' }],
},
}
},

items(params: ItemsParams, settings: ProviderSettings): ItemsResult {
Expand Down
2 changes: 1 addition & 1 deletion provider/hello-world/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openctx/provider-hello-world",
"version": "0.0.14",
"version": "0.0.15",
"description": "Hello World (OpenCtx provider)",
"license": "Apache-2.0",
"homepage": "https://openctx.org/docs/providers/hello-world",
Expand Down

0 comments on commit 7f2e5dc

Please sign in to comment.