mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-24 01:28:35 +02:00
Fix autocomplete for environment editor names
This commit is contained in:
@@ -281,7 +281,7 @@ function SidebarButton({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'delete',
|
key: 'delete-environment',
|
||||||
variant: 'danger',
|
variant: 'danger',
|
||||||
label: 'Delete',
|
label: 'Delete',
|
||||||
leftSlot: <Icon icon="trash" size="sm" />,
|
leftSlot: <Icon icon="trash" size="sm" />,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useEffect } from 'react';
|
|||||||
import { useClipboardText } from '../hooks/useClipboardText';
|
import { useClipboardText } from '../hooks/useClipboardText';
|
||||||
import { useCommandPalette } from '../hooks/useCommandPalette';
|
import { useCommandPalette } from '../hooks/useCommandPalette';
|
||||||
import { cookieJarsQueryKey } from '../hooks/useCookieJars';
|
import { cookieJarsQueryKey } from '../hooks/useCookieJars';
|
||||||
|
import { environmentsQueryKey } from '../hooks/useEnvironments';
|
||||||
import { foldersQueryKey } from '../hooks/useFolders';
|
import { foldersQueryKey } from '../hooks/useFolders';
|
||||||
import { useGlobalCommands } from '../hooks/useGlobalCommands';
|
import { useGlobalCommands } from '../hooks/useGlobalCommands';
|
||||||
import { grpcConnectionsQueryKey } from '../hooks/useGrpcConnections';
|
import { grpcConnectionsQueryKey } from '../hooks/useGrpcConnections';
|
||||||
@@ -62,6 +63,8 @@ export function GlobalHooks() {
|
|||||||
? httpResponsesQueryKey(model)
|
? httpResponsesQueryKey(model)
|
||||||
: model.model === 'folder'
|
: model.model === 'folder'
|
||||||
? foldersQueryKey(model)
|
? foldersQueryKey(model)
|
||||||
|
: model.model === 'environment'
|
||||||
|
? environmentsQueryKey(model)
|
||||||
: model.model === 'grpc_connection'
|
: model.model === 'grpc_connection'
|
||||||
? grpcConnectionsQueryKey(model)
|
? grpcConnectionsQueryKey(model)
|
||||||
: model.model === 'grpc_event'
|
: model.model === 'grpc_event'
|
||||||
@@ -96,10 +99,8 @@ export function GlobalHooks() {
|
|||||||
queryClient.setQueryData<Model[]>(queryKey, (values = []) => {
|
queryClient.setQueryData<Model[]>(queryKey, (values = []) => {
|
||||||
const index = values.findIndex((v) => modelsEq(v, model)) ?? -1;
|
const index = values.findIndex((v) => modelsEq(v, model)) ?? -1;
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
// console.log('UPDATED', payload);
|
|
||||||
return [...values.slice(0, index), model, ...values.slice(index + 1)];
|
return [...values.slice(0, index), model, ...values.slice(index + 1)];
|
||||||
} else {
|
} else {
|
||||||
// console.log('CREATED', payload);
|
|
||||||
return pushToFront ? [model, ...(values ?? [])] : [...(values ?? []), model];
|
return pushToFront ? [model, ...(values ?? [])] : [...(values ?? []), model];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -117,6 +118,8 @@ export function GlobalHooks() {
|
|||||||
queryClient.setQueryData(httpResponsesQueryKey(model), removeById(model));
|
queryClient.setQueryData(httpResponsesQueryKey(model), removeById(model));
|
||||||
} else if (model.model === 'folder') {
|
} else if (model.model === 'folder') {
|
||||||
queryClient.setQueryData(foldersQueryKey(model), removeById(model));
|
queryClient.setQueryData(foldersQueryKey(model), removeById(model));
|
||||||
|
} else if (model.model === 'environment') {
|
||||||
|
queryClient.setQueryData(environmentsQueryKey(model), removeById(model));
|
||||||
} else if (model.model === 'grpc_request') {
|
} else if (model.model === 'grpc_request') {
|
||||||
queryClient.setQueryData(grpcRequestsQueryKey(model), removeById(model));
|
queryClient.setQueryData(grpcRequestsQueryKey(model), removeById(model));
|
||||||
} else if (model.model === 'grpc_connection') {
|
} else if (model.model === 'grpc_connection') {
|
||||||
|
|||||||
@@ -266,7 +266,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&.cm-completionInfo-right {
|
&.cm-completionInfo-right {
|
||||||
@apply ml-1 -mt-0.5;
|
@apply ml-1 -mt-0.5 font-sans;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.cm-completionInfo-right-narrow {
|
&.cm-completionInfo-right-narrow {
|
||||||
@@ -278,7 +278,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&.cm-tooltip-autocomplete {
|
&.cm-tooltip-autocomplete {
|
||||||
@apply font-mono text-editor;
|
@apply font-mono;
|
||||||
|
|
||||||
& > ul {
|
& > ul {
|
||||||
@apply p-1 max-h-[40vh];
|
@apply p-1 max-h-[40vh];
|
||||||
|
|||||||
@@ -20,7 +20,11 @@ export interface GenericCompletionConfig {
|
|||||||
/**
|
/**
|
||||||
* Complete options, always matching until the start of the line
|
* Complete options, always matching until the start of the line
|
||||||
*/
|
*/
|
||||||
export function genericCompletion({ options, minMatch = 1 }: GenericCompletionConfig) {
|
export function genericCompletion(config?: GenericCompletionConfig) {
|
||||||
|
if (config == null) return [];
|
||||||
|
|
||||||
|
const { minMatch = 1, options } = config;
|
||||||
|
|
||||||
return function completions(context: CompletionContext) {
|
return function completions(context: CompletionContext) {
|
||||||
const toMatch = context.matchBefore(/.*/);
|
const toMatch = context.matchBefore(/.*/);
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import type { LanguageSupport } from '@codemirror/language';
|
import type { LanguageSupport } from '@codemirror/language';
|
||||||
import { LRLanguage } from '@codemirror/language';
|
import { LRLanguage } from '@codemirror/language';
|
||||||
import { parseMixed } from '@lezer/common';
|
import { parseMixed } from '@lezer/common';
|
||||||
|
import type { Environment, Workspace } from '../../../../lib/models';
|
||||||
import type { GenericCompletionConfig } from '../genericCompletion';
|
import type { GenericCompletionConfig } from '../genericCompletion';
|
||||||
import { genericCompletion } from '../genericCompletion';
|
import { genericCompletion } from '../genericCompletion';
|
||||||
import { placeholders } from './placeholder';
|
|
||||||
import { textLanguageName } from '../text/extension';
|
import { textLanguageName } from '../text/extension';
|
||||||
import { twigCompletion } from './completion';
|
import { twigCompletion } from './completion';
|
||||||
|
import { placeholders } from './placeholder';
|
||||||
import { parser as twigParser } from './twig';
|
import { parser as twigParser } from './twig';
|
||||||
import type { Environment, Workspace } from '../../../../lib/models';
|
|
||||||
|
|
||||||
export function twig(
|
export function twig(
|
||||||
base: LanguageSupport,
|
base: LanguageSupport,
|
||||||
@@ -15,25 +15,19 @@ export function twig(
|
|||||||
workspace: Workspace | null,
|
workspace: Workspace | null,
|
||||||
autocomplete?: GenericCompletionConfig,
|
autocomplete?: GenericCompletionConfig,
|
||||||
) {
|
) {
|
||||||
const variables =
|
|
||||||
[...(workspace?.variables ?? []), ...(environment?.variables ?? [])].filter((v) => v.enabled) ??
|
|
||||||
[];
|
|
||||||
const completions = twigCompletion({ options: variables });
|
|
||||||
|
|
||||||
const language = mixLanguage(base);
|
const language = mixLanguage(base);
|
||||||
const completion = language.data.of({ autocomplete: completions });
|
const allVariables = [...(workspace?.variables ?? []), ...(environment?.variables ?? [])];
|
||||||
const completionBase = base.language.data.of({ autocomplete: completions });
|
const variables = allVariables.filter((v) => v.enabled) ?? [];
|
||||||
const additionalCompletion = autocomplete
|
const completions = twigCompletion({ options: variables });
|
||||||
? [base.language.data.of({ autocomplete: genericCompletion(autocomplete) })]
|
|
||||||
: [];
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
language,
|
language,
|
||||||
completion,
|
|
||||||
completionBase,
|
|
||||||
base.support,
|
base.support,
|
||||||
placeholders(variables),
|
placeholders(variables),
|
||||||
...additionalCompletion,
|
language.data.of({ autocomplete: completions }),
|
||||||
|
base.language.data.of({ autocomplete: completions }),
|
||||||
|
language.data.of({ autocomplete: genericCompletion(autocomplete) }),
|
||||||
|
base.language.data.of({ autocomplete: genericCompletion(autocomplete) }),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user