Skip to content

Commit

Permalink
fix: issue when adding words to config (#3081)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed Mar 4, 2024
1 parent d0b9eba commit ad70737
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/_server/src/config/configTargetsHelper.mts
Expand Up @@ -31,7 +31,7 @@ export async function calculateConfigTargets(
const targets: ConfigTarget[] = [];
const possibleSources = extractCSpellFileConfigurations(settings).filter((cfg) => !cfg.readonly);
const sources = configFilesFound
? possibleSources.filter((cfg) => cfg.source.fileSource && isFound(cfg.source.filename))
? possibleSources.filter((cfg) => isFound(cfg.source.filename))
: await filterExistingCSpellFileConfigurations(possibleSources);
const dictionaries = extractTargetDictionaries(settings);

Expand Down
19 changes: 12 additions & 7 deletions packages/client/src/promptUser.ts
@@ -1,5 +1,5 @@
import type { QuickPickOptions, Uri } from 'vscode';
import { window } from 'vscode';
import type { QuickPickOptions } from 'vscode';
import { Uri, window } from 'vscode';

import { extractMatchingDiagTexts, getCSpellDiags } from './diags';
import { normalizeWords } from './settings/CSpellSettings';
Expand All @@ -13,6 +13,7 @@ export function onCommandUseDiagsSelectionOrPrompt(
fnAction: (text: string, uri: Uri | undefined) => Promise<void>,
): (text?: string, uri?: Uri | string) => Promise<void> {
return async function (text?: string, uri?: Uri | string) {
// console.log('onCommandUseDiagsSelectionOrPrompt %o', { prompt, text, uri });
const selected = await determineTextSelection(prompt, text, uri);
if (!selected) return;

Expand All @@ -22,10 +23,14 @@ export function onCommandUseDiagsSelectionOrPrompt(
};
}

async function determineTextSelection(prompt: string, text?: string, uri?: Uri | string): Promise<{ text: string; uri?: Uri } | undefined> {
uri = toUri(uri);
if (text) {
return { text, uri: uri || window.activeTextEditor?.document.uri };
async function determineTextSelection(
prompt: string,
textOrUri?: string | Uri,
uri?: Uri | string,
): Promise<{ text: string; uri?: Uri } | undefined> {
uri = uri ? toUri(uri) : textOrUri instanceof Uri ? textOrUri : undefined;
if (typeof textOrUri === 'string' && textOrUri) {
return { text: textOrUri, uri: uri || window.activeTextEditor?.document.uri };
}

const editor = findEditor(uri);
Expand All @@ -50,7 +55,7 @@ async function determineTextSelection(prompt: string, text?: string, uri?: Uri |
return { text: word, uri: document?.uri };
}

text = selection.contains(range) ? document.getText(selection) : document.getText(range);
const text = selection.contains(range) ? document.getText(selection) : document.getText(range);

const words = normalizeWords(text);
const picked =
Expand Down

0 comments on commit ad70737

Please sign in to comment.