insomnia/packages/insomnia-app/app/codemirror.d.ts
Timothy Lim 58ce5ec39e
Allow Autocomplete to be properly registered as a Shortcut (#2726)
* Allow autocomplete to be registered

* On shortcut update refresh pane to enable shortcuts to register correctly

* Improve types and add explanation about keyname order

* bind code-editor to hotkeyregistry via redux so that it updates keymaps on change

* remove force refresh via key and convert to named export

* send hotkeyregistry in environment autocomplete options

* use autocomplete delay from settings

* Use Pick<T>

Co-authored-by: Timothy Lim <tim.lim@intercom.io>
Co-authored-by: gatzjames <jamesgatzos@gmail.com>
Co-authored-by: Opender Singh <opender.singh@konghq.com>
2021-09-15 15:01:35 +02:00

100 lines
2.7 KiB
TypeScript

import 'codemirror';
import { GraphQLInfoOptions } from 'codemirror-graphql/info';
import { ModifiedGraphQLJumpOptions } from 'codemirror-graphql/jump';
import { GraphQLSchema } from 'graphql';
import { HandleGetRenderContext, HandleRender } from './common/render';
import { Settings } from './models/settings';
import { NunjucksParsedTag } from './templating/utils';
type LinkClickCallback = (url: string) => void;
interface InsomniaExtensions {
closeHintDropdown: () => void;
enableNunjucksTags: (
handleRender: HandleRender,
handleGetRenderContext?: HandleGetRenderContext,
isVariableUncovered?: boolean,
) => void;
isHintDropdownActive: () => boolean;
makeLinksClickable: (handleClick: LinkClickCallback) => void;
}
declare module 'codemirror' {
type CodeMirrorLinkClickCallback = LinkClickCallback;
interface Editor extends InsomniaExtensions {}
interface EditorFromTextEditor extends InsomniaExtensions {}
interface TextMarker {
// This flag is being used internally by codemirror and the fold extension
__isFold: boolean;
}
interface Variable {
name: string;
value: any;
}
interface Snippet {
name: string;
displayValue: string;
value: string | (() => Promise<unknown>);
}
interface EnvironmentAutocompleteOptions extends Pick<Settings, 'hotKeyRegistry' | 'autocompleteDelay'> {
getConstants?: () => string[] | PromiseLike<string[]>;
getVariables?: () => Variable[] | PromiseLike<Variable[]>;
getSnippets?: () => Snippet[] | PromiseLike<Snippet[]>;
getTags?: () => NunjucksParsedTag[] | PromiseLike<NunjucksParsedTag[]>;
}
interface EditorConfiguration {
info?: GraphQLInfoOptions;
jump?: ModifiedGraphQLJumpOptions;
environmentAutocomplete?: EnvironmentAutocompleteOptions;
}
interface Hint {
/**
* Custom Insomnia Key. Used for checking the type of the hint
*/
type: 'constant' | 'variable' | 'snippet' | 'tag';
/**
* Custom Insomnia Key. The segment that matched and produced this hint
*/
segment: string;
/**
* Custom Insomnia Key. This value gets displayed in the autocomplete menu.
*/
displayValue: string;
/**
* Custom Insomnia Key. The display value of the hint
*/
comment?: string;
/**
* Custom Insomnia Key. Used for sorting the hints
*/
score: number;
}
interface ShowHintOptions {
variables?: Variable[];
constants?: string[];
snippets?: Snippet[];
tags?: NunjucksParsedTag[];
showAllOnNoMatch?: boolean;
}
interface LintOptions {
schema?: GraphQLSchema;
}
interface EditorEventMap {
fold: (instance: Editor, from: Position) => void;
unfold: (instance: Editor, from: Position) => void;
}
const keyNames: Record<number, string>;
}