Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: issue when adding words to config #3081

Merged
merged 1 commit into from Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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