mirror of
https://github.com/facebook/sapling.git
synced 2024-10-06 06:47:41 +03:00
wire typeahead fetch to go to the isl server
Summary: Hook up our typeahead fetch function to send a message to the server. This is where we'll be able to actually do our fetches. Reviewed By: quark-zju Differential Revision: D45627740 fbshipit-source-id: d5426b84fb420f06e72e6f6f583577f63b1242d5
This commit is contained in:
parent
44eba5acdf
commit
185b0abd65
@ -577,6 +577,15 @@ export default class ServerToClientAPI {
|
||||
});
|
||||
break;
|
||||
}
|
||||
case 'typeahead': {
|
||||
// TODO: actually do the query
|
||||
this.postMessage({
|
||||
type: 'typeaheadResult',
|
||||
id: data.id,
|
||||
result: [],
|
||||
});
|
||||
break;
|
||||
}
|
||||
case 'fetchDiffSummaries': {
|
||||
repo.codeReviewProvider?.triggerDiffSummariesFetch(repo.getAllDiffIds());
|
||||
break;
|
||||
|
@ -86,6 +86,7 @@ export function CommitInfoField({
|
||||
autoFocus={autofocus ?? false}
|
||||
editedMessage={editedFieldContent}
|
||||
setEditedCommitMessage={setEditedField}
|
||||
typeaheadKind={field.typeaheadKind}
|
||||
/>
|
||||
) : (
|
||||
<CommitInfoTextArea
|
||||
|
@ -5,11 +5,15 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import type {TypeaheadKind} from './types';
|
||||
|
||||
import serverApi from '../ClientToServerAPI';
|
||||
import {Subtle} from '../Subtle';
|
||||
import {getInnerTextareaForVSCodeTextArea} from './utils';
|
||||
import {VSCodeButton, VSCodeTextField} from '@vscode/webview-ui-toolkit/react';
|
||||
import {useRef, useEffect, useState} from 'react';
|
||||
import {Icon} from 'shared/Icon';
|
||||
import {randomId} from 'shared/utils';
|
||||
|
||||
/** Extract comma-separated tokens into an array, plus any remaining non-tokenized text */
|
||||
function extractTokens(raw: string): [Array<string>, string] {
|
||||
@ -28,11 +32,13 @@ export function CommitInfoTextField({
|
||||
autoFocus,
|
||||
editedMessage,
|
||||
setEditedCommitMessage,
|
||||
typeaheadKind,
|
||||
}: {
|
||||
name: string;
|
||||
autoFocus: boolean;
|
||||
editedMessage: string;
|
||||
setEditedCommitMessage: (fieldValue: string) => unknown;
|
||||
typeaheadKind: TypeaheadKind;
|
||||
}) {
|
||||
const ref = useRef(null);
|
||||
useEffect(() => {
|
||||
@ -50,7 +56,7 @@ export function CommitInfoTextField({
|
||||
const newValue = (event?.target as HTMLInputElement)?.value;
|
||||
setEditedCommitMessage(tokensToString(tokens, newValue));
|
||||
setTypeaheadSuggestions({type: 'loading'});
|
||||
fetchNewSuggestions(newValue).then(values =>
|
||||
fetchNewSuggestions(typeaheadKind, newValue).then(values =>
|
||||
setTypeaheadSuggestions({type: 'success', values}),
|
||||
);
|
||||
};
|
||||
@ -84,7 +90,7 @@ export function CommitInfoTextField({
|
||||
) : (
|
||||
typeaheadSuggestions?.values.map(suggestion => (
|
||||
<span key={suggestion.value} className="suggestion">
|
||||
<span>{suggestion.display}</span>
|
||||
<span>{suggestion.label}</span>
|
||||
<Subtle>{suggestion.value}</Subtle>
|
||||
</span>
|
||||
))
|
||||
@ -104,7 +110,7 @@ type TypeaheadSuggestions =
|
||||
| undefined;
|
||||
type TypeaheadSuggestion = {
|
||||
/** The display text of the suggestion */
|
||||
display: string;
|
||||
label: string;
|
||||
/**
|
||||
* The literal value of the suggestion,
|
||||
* shown de-emphasized next to the display name
|
||||
@ -114,6 +120,15 @@ type TypeaheadSuggestion = {
|
||||
};
|
||||
|
||||
// eslint-disable-next-line require-await
|
||||
async function fetchNewSuggestions(_text: string): Promise<Array<TypeaheadSuggestion>> {
|
||||
return [];
|
||||
async function fetchNewSuggestions(
|
||||
kind: TypeaheadKind,
|
||||
text: string,
|
||||
): Promise<Array<TypeaheadSuggestion>> {
|
||||
const id = randomId();
|
||||
serverApi.postMessage({type: 'typeahead', kind, id, query: text});
|
||||
const values = await serverApi.nextMessageMatching(
|
||||
'typeaheadResult',
|
||||
message => message.id === id,
|
||||
);
|
||||
return values.result;
|
||||
}
|
||||
|
@ -8,6 +8,8 @@
|
||||
/** Values for each field key, */
|
||||
export type CommitMessageFields = Record<string, string | Array<string>>;
|
||||
|
||||
export type TypeaheadKind = 'meta-user' | 'meta-task' | 'meta-tag' | 'meta-diff';
|
||||
|
||||
/**
|
||||
* Which fields of the message should display as editors instead of rendered values.
|
||||
* This can be controlled outside of the commit info view, but it gets updated in an effect as well when commits are changed.
|
||||
@ -50,6 +52,6 @@ export type FieldConfig = {
|
||||
}
|
||||
| {
|
||||
type: 'field';
|
||||
typeaheadType: 'user' | 'task' | 'tag' | 'diff';
|
||||
typeaheadKind: TypeaheadKind;
|
||||
}
|
||||
);
|
||||
|
@ -5,6 +5,7 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import type {TypeaheadKind} from './CommitInfoView/types';
|
||||
import type {InternalTypes} from './InternalTypes';
|
||||
import type {TrackEventName} from 'isl-server/src/analytics/eventNames';
|
||||
import type {TrackDataWithEventName} from 'isl-server/src/analytics/types';
|
||||
@ -380,6 +381,7 @@ export type ClientToServerMessage =
|
||||
| {type: 'abortRunningOperation'; operationId: string}
|
||||
| {type: 'deleteFile'; filePath: RepoRelativePath}
|
||||
| {type: 'fetchCommitMessageTemplate'}
|
||||
| {type: 'typeahead'; kind: TypeaheadKind; query: string; id: string}
|
||||
| {type: 'requestRepoInfo'}
|
||||
| {type: 'requestApplicationInfo'}
|
||||
| {type: 'fetchDiffSummaries'}
|
||||
@ -426,6 +428,7 @@ export type ServerToClientMessage =
|
||||
| FileABugProgressMessage
|
||||
| {type: 'gotConfig'; name: ConfigName; value: string | undefined}
|
||||
| {type: 'fetchedCommitMessageTemplate'; template: string}
|
||||
| {type: 'typeaheadResult'; id: string; result: Array<{label: string; value: string}>}
|
||||
| {type: 'applicationInfo'; platformName: string; version: string}
|
||||
| {type: 'repoInfo'; info: RepoInfo; cwd?: string}
|
||||
| {type: 'repoError'; error: RepositoryError | undefined}
|
||||
|
Loading…
Reference in New Issue
Block a user